ClangBuiltLinux / boot-utils

Collection of files for booting Linux kernels
26 stars 7 forks source link

Initial LoongArch support #109

Closed nathanchance closed 1 year ago

nathanchance commented 1 year ago

This pull request adds support for booting LoongArch kernels.

The first patch updates the version of Buildroot that we use and updates the configurations accordingly.

The second third patches add the Buildroot scaffolding needed to support building a LoongArch rootfs. LoongArch support for Buildroot is available as a patch on the Buildroot mailing list, so that is applied to the source before building.

The fourth patch adds support for LoongArch to boot-qemu.py. The EFI firmware is downloaded from Loongson's GitHub when first booting a LoongArch kernel.

The last patch allows this pull request to be tested locally. It will be removed before this pull request is merged.

Source/toolchain information

LLVM:

a5c877ce482b D138135
ff76d4149a5a D153872
1f675e67a20e D153865
11b71ade51e0 [PowerPC][TLS] Add additional TLS X-Form loads/store instructions

Linux:

eff1147df203 LoongArch: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
df9a4a707b3b LoongArch: vDSO: Use CLANG_FLAGS instead of filtering out '--target='
53cdf865f90b Add linux-next specific files for 20230627

Testing

$ make -skj"$(nproc)" ARCH=loongarch LLVM=1 mrproper defconfig

$ scripts/config -d CRASH_DUMP -d MODULES -d RELOCATABLE

$ make -skj"$(nproc)" ARCH=loongarch LLVM=1 olddefconfig all

$ boot-qemu.py -k .

QEMU location: /usr/sbin

QEMU version: QEMU emulator version 8.0.2
$ timeout --foreground 3m stdbuf -eL -oL /usr/sbin/qemu-system-loongarch64 -display none -nodefaults -M virt -cpu la464 -bios $BOOT_UTILS/images/loongarch/edk2-loongarch64-code.fd -no-reboot -append console=ttyS0,115200 -kernel $KBUILD/arch/loongarch/boot/vmlinuz.efi -initrd $BOOT_UTILS/images/loongarch/rootfs.cpio -m 4G -smp 2 -serial mon:stdio
...
[    1.546543] Run /init as init process
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Saving 256 bits of non-creditable seed for next boot
Starting network: OK
Linux version 6.4.0-next-20230627+ (nathan@dev-arch.thelio-3990X) (ClangBuiltLinux clang version 17.0.0 (https://github.com/llvm/llvm-project a5c877ce482b1a5fbacb5ad7ec77675a67eae395), ClangBuiltLinux LLD 17.0.0) #1 SMP PREEMPT Tue Jun 27 10:04:49 MST 2023
Stopping network: OK
Seeding 256 bits without crediting
Saving 256 bits of non-creditable seed for next boot
Stopping klogd: OK
Stopping syslogd: OK
umount: devtmpfs busy - remounted read-only
umount: can't unmount /: Invalid argument
The system is going down NOW!
Sent SIGTERM to all processes
Sent SIGKILL to all processes
Requesting system reboot
[    4.856427] ACPI: PM: Preparing to enter system sleep state S5
[    4.857035] reboot: Restarting system

Additionally, I have verified that the new Buildroot revision successfully builds with all the existing configurations that we have and that there are no boot regressions.

nathanchance commented 1 year ago

Thanks for the PR and your continued testing!

Thank you for all the work you have done driving this on both the Linux and LLVM side :)

FYI, next-20230628 now works with LLVM main branch (I tested llvm/llvm-project@193d3ac) + only https://reviews.llvm.org/D138135 applied (everything else is already upstream).

Yes, confirmed, good to see everything is moving along nicely!