diff --git a/boot-qemu.py b/boot-qemu.py index 21c131f..8b48b0f 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -21,6 +21,7 @@ 'arm32_v7', 'arm64', 'arm64be', + 'loongarch', 'm68k', 'mips', 'mipsel', @@ -476,6 +477,35 @@ def __init__(self): self._initrd_arch = 'arm64be' +class LoongArchQEMURunner(QEMURunner): + + def __init__(self): + super().__init__() + + self.cmdline.append('console=ttyS0,115200') + self._default_kernel_path = Path('arch/loongarch/boot/vmlinuz.efi') + self._initrd_arch = 'loongarch' + + bios = Path(utils.BOOT_UTILS, 'images', self._initrd_arch, + 'edk2-loongarch64-code.fd') + if not bios.exists(): + firmware_url = f"https://github.com/loongson/Firmware/raw/main/LoongArchVirtMachine/{bios.name}" + utils.green( + f"Downloading LoongArch firmware from {firmware_url}...") + curl_cmd = ['curl', '-LSs', '-o', bios, firmware_url] + subprocess.run(curl_cmd, check=True) + + self._qemu_arch = 'loongarch64' + self._qemu_args += [ + '-M', 'virt', + '-cpu', 'la464', + '-bios', bios, + '-no-reboot', + ] # yapf: disable + self._ram = '2G' + self.smp = 2 + + class M68KQEMURunner(QEMURunner): def __init__(self): @@ -699,6 +729,7 @@ def guess_arch(kernel_arg): 'ELF 64-bit MSB executable, ARM aarch64': 'arm64be', 'ELF 64-bit LSB pie executable, ARM aarch64': 'arm64', 'ELF 64-bit MSB pie executable, ARM aarch64': 'arm64be', + 'ELF 64-bit LSB executable, LoongArch': 'loongarch', 'ELF 32-bit MSB executable, Motorola m68k, 68020': 'm68k', 'ELF 32-bit MSB executable, MIPS, MIPS32': 'mips', 'ELF 32-bit LSB executable, MIPS, MIPS32': 'mipsel', @@ -802,6 +833,7 @@ def parse_arguments(): 'arm32_v7': ARMV7QEMURunner, 'arm64': ARM64QEMURunner, 'arm64be': ARM64BEQEMURunner, + 'loongarch': LoongArchQEMURunner, 'm68k': M68KQEMURunner, 'mips': MIPSQEMURunner, 'mipsel': MIPSELQEMURunner, diff --git a/buildroot/buildroot-2022.02.tar.gz.sha256 b/buildroot/buildroot-2022.02.tar.gz.sha256 deleted file mode 100644 index c82e887..0000000 --- a/buildroot/buildroot-2022.02.tar.gz.sha256 +++ /dev/null @@ -1 +0,0 @@ -9aaaa1317ca1082ccdabe3f2566bba06975080a80256adf87f860bc4c3f45a9b buildroot-2022.02.tar.gz diff --git a/buildroot/buildroot-2023.02.2.tar.gz.sha256 b/buildroot/buildroot-2023.02.2.tar.gz.sha256 new file mode 100644 index 0000000..38f4451 --- /dev/null +++ b/buildroot/buildroot-2023.02.2.tar.gz.sha256 @@ -0,0 +1 @@ +44cced15a58505c93a87b215a632eba25f65560da64782fea50111f62b5ae86c buildroot-2023.02.2.tar.gz diff --git a/buildroot/loongarch.config b/buildroot/loongarch.config new file mode 100644 index 0000000..546d0d7 --- /dev/null +++ b/buildroot/loongarch.config @@ -0,0 +1,8 @@ +BR2_loongarch64=y +BR2_BINUTILS_VERSION_2_39_X=y +BR2_GCC_VERSION_12_X=y +BR2_TARGET_GENERIC_ROOT_PASSWD="root" +BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" +BR2_ROOTFS_OVERLAY="../overlay-reboot" +BR2_TARGET_ROOTFS_CPIO=y +# BR2_TARGET_ROOTFS_TAR is not set diff --git a/buildroot/ppc64le.config b/buildroot/ppc64le.config index 120c1ab..485a9f0 100644 --- a/buildroot/ppc64le.config +++ b/buildroot/ppc64le.config @@ -1,5 +1,4 @@ BR2_powerpc64le=y -BR2_powerpc_power8=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_POWERPC64LE_POWER8_GLIBC_STABLE=y BR2_TARGET_GENERIC_ROOT_PASSWD="root" diff --git a/buildroot/rebuild.py b/buildroot/rebuild.py index 6524d98..7e33cc7 100755 --- a/buildroot/rebuild.py +++ b/buildroot/rebuild.py @@ -7,11 +7,12 @@ import shutil import subprocess -BUILDROOT_VERSION = '2022.02' +BUILDROOT_VERSION = '2023.02.2' SUPPORTED_ARCHES = [ 'arm64', 'arm64be', 'arm', + 'loongarch', 'm68k', 'mips', 'mipsel', @@ -72,16 +73,17 @@ def build_image(architecture, edit_config): def download_and_extract_buildroot(): + if SRC_FOLDER.exists(): + shutil.rmtree(SRC_FOLDER) SRC_FOLDER.mkdir(parents=True) tarball = Path(ROOT_FOLDER, f"buildroot-{BUILDROOT_VERSION}.tar.gz") - tarball.unlink(missing_ok=True) - - curl_cmd = [ - 'curl', '-LSs', '-o', tarball, - f"https://buildroot.org/downloads/{tarball.name}" - ] - subprocess.run(curl_cmd, check=True) + if not tarball.exists(): + curl_cmd = [ + 'curl', '-LSs', '-o', tarball, + f"https://buildroot.org/downloads/{tarball.name}" + ] + subprocess.run(curl_cmd, check=True) sha256_cmd = ['sha256sum', '--quiet', '-c', f"{tarball.name}.sha256"] subprocess.run(sha256_cmd, check=True, cwd=ROOT_FOLDER) @@ -91,27 +93,18 @@ def download_and_extract_buildroot(): ] subprocess.run(tar_cmd, check=True) - tarball.unlink(missing_ok=True) - - -def download_buildroot_if_necessary(): - if SRC_FOLDER.exists(): - # Make support/scripts/setlocalversion do nothing because we are in a - # git repository so it will return information about this repo, not - # Buildroot - setlocalversion = Path(SRC_FOLDER, 'support/scripts/setlocalversion') - setlocalversion.write_text('', encoding='utf-8') - - installed_version = subprocess.run(['make', 'print-version'], - capture_output=True, - check=True, - cwd=SRC_FOLDER, - text=True).stdout.strip() - if installed_version != BUILDROOT_VERSION: - shutil.rmtree(SRC_FOLDER) - download_and_extract_buildroot() - else: - download_and_extract_buildroot() + if (patches := list(ROOT_FOLDER.glob('*.patch'))): + for patch in patches: + patch_cmd = [ + 'patch', '--directory', SRC_FOLDER, '--input', patch, + '--strip', '1' + ] + try: + subprocess.run(patch_cmd, check=True) + except subprocess.CalledProcessError as err: + raise RuntimeError( + f"{patch} did not apply to Buildroot {BUILDROOT_VERSION}, does it need to be updated?" + ) from err def release_images(): @@ -161,7 +154,7 @@ def parse_arguments(): architectures = SUPPORTED_ARCHES if 'all' in args.architectures else args.architectures - download_buildroot_if_necessary() + download_and_extract_buildroot() for arch in architectures: build_image(arch, args.edit_config) diff --git a/buildroot/riscv.config b/buildroot/riscv.config index 7d8894c..4a2026d 100644 --- a/buildroot/riscv.config +++ b/buildroot/riscv.config @@ -1,6 +1,6 @@ BR2_riscv=y BR2_TOOLCHAIN_EXTERNAL=y -BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_RISCV64_LP64D_GLIBC_STABLE=y +BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_RISCV64_LP64D_UCLIBC_STABLE=y BR2_TARGET_GENERIC_ROOT_PASSWD="root" BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_ROOTFS_OVERLAY="../overlay-poweroff" diff --git a/buildroot/s390.config b/buildroot/s390.config index 0aff61b..cd4c6e5 100644 --- a/buildroot/s390.config +++ b/buildroot/s390.config @@ -1,7 +1,6 @@ BR2_s390x=y -BR2_KERNEL_HEADERS_4_4=y -BR2_BINUTILS_VERSION_2_35_X=y -BR2_GCC_VERSION_10_X=y +BR2_TOOLCHAIN_EXTERNAL=y +BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_S390X_Z13_GLIBC_STABLE=y BR2_TARGET_GENERIC_ROOT_PASSWD="root" BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" BR2_ROOTFS_OVERLAY="../overlay-poweroff" diff --git a/buildroot/v3_20221212_duanzhiwei_buildroot_add_basic_support_for_loongarch_architecture_toolchain_only.patch b/buildroot/v3_20221212_duanzhiwei_buildroot_add_basic_support_for_loongarch_architecture_toolchain_only.patch new file mode 100644 index 0000000..1df9b11 --- /dev/null +++ b/buildroot/v3_20221212_duanzhiwei_buildroot_add_basic_support_for_loongarch_architecture_toolchain_only.patch @@ -0,0 +1,193 @@ +From git@z Thu Jan 1 00:00:00 1970 +Subject: [PATCH v3] buildroot: Add basic support for LoongArch architecture + (toolchain only) +From: Zhiwei Duan +Date: Mon, 12 Dec 2022 16:34:57 +0800 +Message-Id: <20221212083457.8308-1-duanzhiwei@loongson.cn> +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 7bit + +With this patch, the buildroot can compile the rootfs of the loongarch architecture. +Both external toolchain and buildroot toolchain can compile rootfs. +buildroot toolchain: binutils>=2.38 GCC>=12 Linux>=5.19 glibc>=2.36. + +Signed-off-by: Zhiwei Duan +Link: https://lore.kernel.org/r/20221212083457.8308-1-duanzhiwei@loongson.cn +--- + arch/Config.in | 16 +++++++++++ + arch/Config.in.loongarch | 52 ++++++++++++++++++++++++++++++++++++ + package/glibc/Config.in | 1 + + support/gnuconfig/config.sub | 11 ++++++-- + toolchain/Config.in | 2 +- + 5 files changed, 79 insertions(+), 3 deletions(-) + create mode 100644 arch/Config.in.loongarch + +diff --git a/arch/Config.in b/arch/Config.in +index 1c0c400a98..88f805bb1e 100644 +--- a/arch/Config.in ++++ b/arch/Config.in +@@ -251,6 +251,17 @@ config BR2_xtensa + http://en.wikipedia.org/wiki/Xtensa + http://www.tensilica.com/ + ++config BR2_loongarch64 ++ bool "LOONGARCH64 (little endian)" ++ select BR2_ARCH_IS_64 ++ select BR2_USE_MMU ++ help ++ LOONGARCH is a RISC microprocessor from LOONGARCH Technologies. Little ++ endian. ++ https://www.loongson.cn/ ++ #http://en.wikipedia.org/wiki/MIPS_Technologies ++ ++ + endchoice + + # For some architectures or specific cores, our internal toolchain +@@ -414,6 +425,11 @@ if BR2_xtensa + source "arch/Config.in.xtensa" + endif + ++if BR2_loongarch64 ++source "arch/Config.in.loongarch" ++endif ++ ++ + # Set up target binary format + choice + prompt "Target Binary Format" +diff --git a/arch/Config.in.loongarch b/arch/Config.in.loongarch +new file mode 100644 +index 0000000000..bf86490cff +--- /dev/null ++++ b/arch/Config.in.loongarch +@@ -0,0 +1,52 @@ ++# loongarch config ++config BR2_LOONGARCH_CPU_LOONGARCH64 ++ bool ++ select BR2_LOONGARCH_NAN_LEGACY ++ ++choice ++ prompt "Target Architecture Variant" ++ default BR2_loongarch_64 if BR2_loongarch64 ++ depends on BR2_loongarch64 ++ help ++ Specific CPU variant to use ++ ++config BR2_loongarch_64 ++ bool "Generic LOONGARCH64" ++ depends on BR2_ARCH_IS_64 ++ select BR2_LOONGARCH_CPU_LOONGARCH64 ++endchoice ++ ++config BR2_LOONGARCH_NAN_LEGACY ++ bool ++ ++#config BR2_GCC_TARGET_NAN ++# default "legacy" if BR2_LOONGARCH_NAN_LEGACY ++ ++config BR2_ARCH ++ default "loongarch64" if BR2_loongarch64 ++ ++config BR2_NORMALIZED_ARCH ++ default "loongarch" ++ ++config BR2_ENDIAN ++ default "LITTLE" if BR2_loongarch64 ++ ++config BR2_GCC_TARGET_ARCH ++ default "loongarch64" if BR2_loongarch_64 ++ ++config BR2_READELF_ARCH_NAME ++ default "LoongArch" ++ ++config BR2_LOONGARCH_SOFT_FLOAT ++ bool "Use soft-float" ++ #default y ++ select BR2_SOFT_FLOAT ++ help ++ If your target CPU does not have a Floating Point Unit (FPU) ++ or a kernel FPU emulator, but you still wish to support ++ floating point functions, then everything will need to be ++ compiled with soft floating point support (-msoft-float). ++ ++ ++# vim: ft=kconfig ++# -*- mode:kconfig; -*- +diff --git a/package/glibc/Config.in b/package/glibc/Config.in +index 71c50504ac..d8325610f5 100644 +--- a/package/glibc/Config.in ++++ b/package/glibc/Config.in +@@ -21,6 +21,7 @@ config BR2_PACKAGE_GLIBC_ARCH_SUPPORTS + default y if BR2_microblaze + default y if BR2_nios2 + default y if BR2_arc && BR2_ARC_ATOMIC_EXT ++ default y if BR2_loongarch64 + depends on !BR2_powerpc_SPE + depends on BR2_RISCV_ISA_RVA || !BR2_riscv + depends on BR2_USE_MMU +diff --git a/support/gnuconfig/config.sub b/support/gnuconfig/config.sub +index 9bc49a7e92..c751ddf15a 100755 +--- a/support/gnuconfig/config.sub ++++ b/support/gnuconfig/config.sub +@@ -164,7 +164,7 @@ case $1 in + basic_os=$field2 + ;; + # Manufacturers +- dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ ++ dec* | mips* | loongarch* | sequent* | encore* | pc533* | sgi* | sony* \ + | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ + | unicom* | ibm* | next | hp | isi* | apollo | altos* \ + | convergent* | ncr* | news | 32* | 3600* | 3100* \ +@@ -632,6 +632,11 @@ case $1 in + basic_machine=ymp-cray + basic_os=unicos + ;; ++ loongarch) ++ basic_machine=loongarch-loongson ++ basic_os= ++ ;; ++ + *) + basic_machine=$1 + basic_os= +@@ -1211,6 +1216,7 @@ case $cpu-$vendor in + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipsr5900 | mipsr5900el \ + | mipstx39 | mipstx39el \ ++ | loongarch | loongarch64 \ + | mmix \ + | mn10200 | mn10300 \ + | moxie \ +@@ -1253,7 +1259,8 @@ case $cpu-$vendor in + | x86 | x86_64 | xc16x | xgate | xps100 \ + | xstormy16 | xtensa* \ + | ymp \ +- | z8k | z80) ++ | z8k | z80 \ ++ | loongarch | loongarch64) + ;; + + *) +diff --git a/toolchain/Config.in b/toolchain/Config.in +index 4947ab3aae..a4939af6fb 100644 +--- a/toolchain/Config.in ++++ b/toolchain/Config.in +@@ -24,7 +24,7 @@ config BR2_TOOLCHAIN_USES_UCLIBC + # architectures + select BR2_TOOLCHAIN_HAS_UCONTEXT if BR2_ARM_CPU_HAS_ARM || BR2_i386 \ + || BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el \ +- || BR2_sparc || BR2_x86_64 ++ || BR2_sparc || BR2_x86_64 || BR2_loongarch64 + select BR2_TOOLCHAIN_SUPPORTS_PIE if !BR2_m68k && !BR2_microblaze && !BR2_STATIC_LIBS + + config BR2_TOOLCHAIN_USES_MUSL +-- +2.20.1 + +_______________________________________________ +buildroot mailing list +buildroot@buildroot.org +https://lists.buildroot.org/mailman/listinfo/buildroot + diff --git a/images/loongarch/.release b/images/loongarch/.release new file mode 100644 index 0000000..b589b1a --- /dev/null +++ b/images/loongarch/.release @@ -0,0 +1 @@ +20230609-194440 \ No newline at end of file diff --git a/images/loongarch/rootfs.cpio.zst b/images/loongarch/rootfs.cpio.zst new file mode 100644 index 0000000..9dc4320 Binary files /dev/null and b/images/loongarch/rootfs.cpio.zst differ