Skip to content

Initial LoongArch support#109

Merged
nathanchance merged 5 commits into
ClangBuiltLinux:mainfrom
nathanchance:loongarch
Jul 7, 2023
Merged

Initial LoongArch support#109
nathanchance merged 5 commits into
ClangBuiltLinux:mainfrom
nathanchance:loongarch

Conversation

@nathanchance

Copy link
Copy Markdown
Member

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.

In order to making applying patches for LoongArch a little easier,
update buildroot to the latest LTS release.

As part of this upgrade, we:

* Move to ulibc instead of glibc for the RISC-V toolchain, which results
  in a smaller toolchain download.
* Move to a prebuilt toolchain for s390, which results in a faster
  overall build because the toolchain only has to be downloaded, rather
  than built.
* Drop BR2_powerpc_power8, as it is now the default choice after [1] and
  [2].

[1]: buildroot/buildroot@c0b0288
[2]: buildroot/buildroot@fdb2369

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
LoongArch support is only available as an in-review patch on the mailing
list. Add scaffolding to make it easy to apply patches on top of the
Buildroot tarball.

To make it easy to add and remove patches while ensuring they get
applied properly, keep the downloaded tarball instead of removing it
after extraction, so that the source can be cleanly recreated each run.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
LoongArch support for Buildroot is still in review. Apply the latest
patch from the mailing list and base the configuration off of that.
LoongArch was only supported in GCC 12.x and binutils 2.39, so those are
explicitly selected for the toolchain.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>

@xen0n xen0n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and your continued testing!

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).

Comment thread boot-qemu.py
@xen0n xen0n mentioned this pull request Jun 28, 2023
LoongArch requires EFI firmware to boot, which is available as a
precompiled blob from Loongson's GitHub, so it is downloaded when
running 'boot-qemu.py -a loongarch' for the first time. There is no
update mechanism like for the rootfs images for a simple implementation.
If there comes a time where the firmware has to be updated for the
machine to boot properly, such a mechanism can be implemented then.

Other than that, the rest of the support is pretty straightforward. The
defaults for cores and memory are a little higher than other machines,
as that is what other folks are testing.

Closes: ClangBuiltLinux#108
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
This is included so that the rootfs image generated by
'buildroot/rebuild.py' can be tested before it is included in a GitHub
release.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
@nathanchance

Copy link
Copy Markdown
Member Author

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!

@nickdesaulniers nickdesaulniers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; thanks! ➿ ➰

@nathanchance nathanchance merged commit c5048c4 into ClangBuiltLinux:main Jul 7, 2023
@nathanchance nathanchance deleted the loongarch branch July 7, 2023 18:29
nathanchance added a commit to nathanchance/boot-utils that referenced this pull request Jul 10, 2023
Ensure 'images/loongarch' exists before trying to download the firmware.
I missed this because 'images/loongarch' was erroneously a part of the
history when LoongArch support was merged in ClangBuiltLinux#109.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants