Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target: add support for Loongson LoongArch64 (kernel 6.6) #14357

Closed
wants to merge 9 commits into from

Conversation

hackpascal
Copy link
Contributor

@hackpascal hackpascal commented Jan 7, 2024

Add target for Loongson LoongArch64-based boards.

LoongArch is a new RISC ISA developed by Loongson. It's a bit like MIPS or RISC-V.
LoongArch includes both 32-bit and 64-bit versions (LoongArch32/LoongArch64).

Loongson 3A5000 and 3A6000 are the two existing CPUs of LoongArch64 and is used for PC products.
It's BIOS supports ACPI and UEFI-only boot. These CPUs supports SMP and SMT.

At present only LoongArch64 is supported by linux kernel.

Toolchain requirement:
binutils >= 2.40
gcc >= 13.1
glibc >= 2.36
musl >= 1.2.5

Installation:
Write openwrt-loongarch64-generic-ext4-combined-efi.img directly to a hard disk.

Note:
mac80211 type drivers are now available.
Both integrated graphics (7A2000) and discrete graphics (amdgpu only) works.
Serial port ttyS0 is also enabled for kernel console.
Tested on Loongson-3A6000-HV-7A2000-XA61200.

For details, please check the following links:
https://lwn.net/Articles/861951/
https://loongson.github.io/LoongArch-Documentation/README-EN.html

The picture of XA61200 motherboard is as follows:
https://github.com/loongson/Firmware/blob/main/Image/XA61200.jpg
image

@github-actions github-actions bot added build/scripts/tools pull request/issues for build, scripts and tools related changes kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages toolchain pull request/issue with toolchain related changes labels Jan 7, 2024
@ynezz ynezz changed the title [RFC][RFT] target: add support for Loongson LoongArch64 [RFC][RFT] target: add support for Loongson LoongArch64 (kernel 6.6) Jan 7, 2024
@cherinyy
Copy link

cherinyy commented Jan 7, 2024

Please refrain from sending meaningless comments and focus on development communication.

@castillofrancodamian
Copy link

6.6 is LTS.

@cherinyy
Copy link

cherinyy commented Jan 7, 2024

6.6 is LTS.

yes, it is. but right now 6.6 is still stable because 6.7 is still mainline.

the longterm maintenance version of the 6.6 kernel has still not been released.

@hackpascal hackpascal force-pushed the loongarch64 branch 2 times, most recently from e0ab2c5 to 87ea501 Compare January 8, 2024 14:17
@hackpascal
Copy link
Contributor Author

https://github.com/openwrt/openwrt/actions/runs/7448683628/job/20263661083?pr=14357

====== Make errors from logs/target/linux/compile.txt ======
HDRINST usr/include/asm/ioctls.h
HDRINST usr/include/asm/stat.h
HDRINST usr/include/asm/bitsperlong.h
INSTALL /__w/openwrt/openwrt/openwrt/build_dir/target-loongarch64_generic_glibc/linux-loongarch64/linux-6.6.9/user_headers/include
make[4]: Leaving directory '/__w/openwrt/openwrt/openwrt/build_dir/target-loongarch64_generic_glibc/linux-loongarch64/linux-6.6.9'
make[6]: hexdump: No such file or directory
make[6]: hexdump: No such file or directory
make[6]: hexdump: No such file or directory
make[6]: hexdump: No such file or directory
truncate: Invalid number: 'arch/loongarch/boot/vmlinux.bin'
make[6]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: arch/loongarch/boot/vmlinux.bin] Error 1

This is weird. Can hexdump be missing on the build system?

@ynezz
Copy link
Member

ynezz commented Jan 9, 2024

Can hexdump be missing on the build system?

Indeed, its not present, because its not current build host dependency defined and assured in include/prereq-build.mk. You can check it yourself in the CI tools container:

$ docker run --rm -it ghcr.io/openwrt/tools:latest which hexdump

Containers used on CI are basically reusing buildbot's buildworker container used on https://buildbot.openwrt.org

Anyways, that new hexdump dependency seems to be introduced in 6.4 via commit bca2f3a9406b ("efi/zboot: Add BSS padding before compression") "just" for some padding purposes, so either we debloat it upstream by some other means or just bite the bullet and introduce hexdump as a new host build dependency OR as a new compiled host tool under tools.

@hackpascal
Copy link
Contributor Author

a new compiled host tool under tools

I‘ll give this a try.

@hackpascal hackpascal force-pushed the loongarch64 branch 5 times, most recently from 84b2062 to 4a2dee5 Compare January 10, 2024 01:10
@hackpascal
Copy link
Contributor Author

At least all checks passed after introducing util-linux and disabling mac80211 drivers.

@KFERMercer
Copy link

KFERMercer commented Jan 10, 2024

build failed: libffi requires at least v3.4.3, now is v3.4.2.

@hackpascal
Copy link
Contributor Author

build failed: libffi requires at least v3.4.3, now is v3.4.2.

@KFERMercer libffi is not a base package included in the openwrt repo.
It should be updated in the packages repo by another PR.

@KFERMercer
Copy link

@KFERMercer libffi is not a base package included in the openwrt repo. It should be updated in the packages repo by another PR.

sorry, just mention for other people

@hackpascal hackpascal changed the title [RFC][RFT] target: add support for Loongson LoongArch64 (kernel 6.6) target: add support for Loongson LoongArch64 (kernel 6.6) Jan 13, 2024
@cherinyy
Copy link

Kernel 6.6.14 is now available and it is the longterm version.

@hackpascal
Copy link
Contributor Author

Kernel 6.6.14 is now available and it is the longterm version.

OK. I'll update later

@dangowrt
Copy link
Member

dangowrt commented Feb 3, 2024

@hackpascal Skipping Linux 6.1 and preparing the next release based on Linux 6.6 is worth the debate -- the number of backport patches on top of 6.1 is already nearly unbearable by now and using Linux 6.6 as a base will allow us to drop most of those obviously and rather make a release happen sooner than later. Maybe you should open another PR only covering the part introducing support for Linux 6.6?

On a personal note, switching to Linux 6.6 has a sad side to me because it drops the support for ox820 SoC (2x ARM11MPCore, 2x SATA, 1x gigE, PCIe1 x1, USB 2.0 x2, parallel NAND to boot, SPARC LEON uC remoteproc 🚀 , even a weird 2D graphics unit) which I had worked on a lot in my free time many years ago. And switching to Linux 6.6 implies dropping the oxnas target in OpenWrt 😢

@hackpascal
Copy link
Contributor Author

Maybe you should open another PR only covering the part introducing support for Linux 6.6?

It's reasonable. I'll do this after Chinese New Year.

tools/Makefile Outdated
@@ -128,6 +129,7 @@ $(curdir)/quilt/compile := $(curdir)/autoconf/compile $(curdir)/findutils/compil
$(curdir)/sdcc/compile := $(curdir)/bison/compile
$(curdir)/squashfs3-lzma/compile := $(curdir)/lzma-old/compile
$(curdir)/squashfs4/compile := $(curdir)/xz/compile $(curdir)/zlib/compile
$(curdir)/util-linux/compile := $(curdir)/meson/compile $(curdir)/bison/compile
Copy link
Contributor

Choose a reason for hiding this comment

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

As you are using the autotools build system the dependency on meson should be unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I was trying meson first but it can't precisely select the minimum set of programs to build. That's why now autotools build system is used.
I'll remove this line.

@oliv3r
Copy link
Contributor

oliv3r commented Feb 23, 2024

@hackpascal what's the status in having a seperate branch for just the 6.6 bump related changes?

@hauke
Copy link
Member

hauke commented Apr 14, 2024

Please rebase this PR. The musl libc, elfutils and GCC changes are already merged upstream and not needed here any more.

@hackpascal
Copy link
Contributor Author

Please rebase this PR. The musl libc, elfutils and GCC changes are already merged upstream and not needed here any more.

@hauke Ah. finally.
Thanks for reminding

@hackpascal
Copy link
Contributor Author

Unfortunately musl 1.2.5 doesn't work with kernel 6.6:

[ 5.139619] EXT4-fs (sda2): mounted filesystem ff313567-e9f1-5a5d-9895-3ba130b4a864 ro with ordered data mode. Quota mode: disabled.
[ 5.186109] VFS: Mounted root (ext4 filesystem) readonly on device 8:2.
[ 5.210313] Freeing unused kernel image (initmem) memory: 384K
[ 5.233508] This architecture does not have kernel memory protection.
[ 5.257339] Run /sbin/init as init process
[ 5.281161] Run /etc/init as init process
[ 5.302158] Run /bin/init as init process
[ 5.322797] Run /bin/sh as init process
[ 5.343195] Kernel panic - not syncing: No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
[ 5.389491] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.6.27 #0
[ 5.411199] Hardware name: Loongson Loongson-3A6000-HV-7A2000-XA61200/Loongson-3A6000-HV-7A2000-XA61200, BIOS Loongson-UDK2018-V4.0.05636-stable202311 12/

Kernel can't recognize /sbin/init as an executable program.
This issue will take time to be analyzed.

So.. I still have to disable musl for loongarch64 for now.
At lease glibc does work well.

@yichya
Copy link

yichya commented Apr 16, 2024

Kernel can't recognize /sbin/init as an executable program. This issue will take time to be analyzed.

So.. I still have to disable musl for loongarch64 for now. At lease glibc does work well.

This is caused by incorrect musl symlink filename (it is created as ld-musl-loongarch64.so.1 while it should be ld-musl-loongarch-lp64d.so.1).

Create a symlink there (I did a quick hack by creating it in package/base-files) and the problem will be solved, however a more proper fix is still needed to be figured out.

image

EDIT: ldd /sbin/init and uname -a

image

@yichya
Copy link

yichya commented Apr 17, 2024

There are some more things worth mentioning:

  • Squashfs images does not work because 16KiB page size is not supported by f2fs in Linux 6.6.

  • (maybe a little offtopic) To build firmware directly on loongarch64 systems:

    • fakeroot needs to be updated (1.34 is enough but that macOS patch does not apply. I just deleted it)
    • libressl needs to be patched (no upstream support currently. Copy bn_arch.h from arm seems just enough to work)
    • golang/host in packages does not bootstrap (currently external Go toolchain is only used for first bootstrap. This needs to be changed)

@hackpascal
Copy link
Contributor Author

  • Squashfs images does not work because 16KiB page size is not supported by f2fs in Linux 6.6.

That's why I disabled squashfs for now lol

@hackpascal
Copy link
Contributor Author

musl now fixed 😃

@hackpascal
Copy link
Contributor Author

Squashfs images does not work because 16KiB page size is not supported by f2fs in Linux 6.6.

It's better to do this in another PR

GCC has changed musl dynamic linker name from
ld-musl-loongarch-lp64d.so.1 to ld-musl-loongarch64.so.1 recently [1].

Meanwhile musl 1.2.5 only supports the new name. So it's better to follow
the new name.

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8bccee51f0deac64b79cd9ad75df599422f4c8ff

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
GCC has changed musl dynamic linker name from
ld-musl-loongarch-lp64d.so.1 to ld-musl-loongarch64.so.1 recently [1].

This means there are two dynamic linker names will be used across different
ersions of GCC. But musl 1.2.5 only supports the new name while the GCC
we're currently using uses the old name.

To maintain compatibility with all versions of GCC, the musl is then patched
to generate two symbolic links to libc.so with both old and new names.

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8bccee51f0deac64b79cd9ad75df599422f4c8ff

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
Add target for Loongson LoongArch64-based boards.

LoongArch is a new RISC ISA developed by Loongson. It's a bit like
MIPS or RISC-V. LoongArch includes both 32-bit and 64-bit versions
(LoongArch32/LoongArch64).

Loongson 3A5000 and 3A6000 are the two existing CPUs of LoongArch64
and is used for PC products. It's BIOS supports ACPI and UEFI-only
boot. These CPUs supports SMP and SMT.

At present only LoongArch64 is supported by linux kernel.

Toolchain requirement:
binutils >= 2.40
gcc >= 13.1

For details, please check the following links:
https://lwn.net/Articles/861951/
https://loongson.github.io/LoongArch-Documentation/README-EN.html

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
libtsan and liblsan are not supported by glibc on loongarch64

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
Add TARGET_loongarch64 as dependency for kmod-mdio-devres,
kmod-mdio-gpio and kmod-switch-rtl8366-smi

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
* Allow kmod-acpi-video to be built for loongarch64:
The x86-specific CONFIG_ACPI_WMI will be split from default
kmod-acpi-video as a board-specific addition.

* Allow kmod-drm-amdgpu to be built for loongarch64:
Also add loongarch64-specific configs and modules.

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
Add a new package for loongarch64 which only supports EFI.

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
Add "linux64-loongarch64-openwrt" into openssl configurations to enable
building on loongarch64 machines.

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
Modify package depends to allow building for loongarch64.
Also fix for building with musl.

Signed-off-by: Weijie Gao <hackpascal@gmail.com>
@981213
Copy link
Member

981213 commented May 4, 2024

Merged. Thanks!

@981213 981213 closed this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/scripts/tools pull request/issues for build, scripts and tools related changes core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes toolchain pull request/issue with toolchain related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet