Building a 64 -bit aarch 64 kernel and userspace for the Raspberry Pi 4
I’ve recently been tinkering around with using a Raspberry Pi as a desktop computer. The Pi 4 is fairly powerful; very sufficient for web browsing, audio, video, and terminal use for programming.
I use Arch Linux on most of my machines, so it was only natural to use Arch on the RPi. There’s a community port athttps://archlinuxarm.org. One problem – only the 32 -bit port is available.
Easy, I thought; we’ll just recompile the kernel and userspace for 64 – bit.
Turns out there’s a bit more to it!
There are a few ways to skin this cat, such as cross compiling, but the easiest method I found was as follows:
- Download the ARMv7 Raspberry Pi 4 image
ArchLinuxARM-rpi-4-latest.tar. gz
fromhttps://archlinuxarm.org/about/downloads
This will form the initial 32 – bit environment that will run on the Pi.
- Download the aarch (multi-platform image) ArchLinuxARM-aarch 64 – latest.tar.gzfromhttps://archlinuxarm.org/about/downloads
This will be the 64 – bit environment we chroot into and build the kernel within.
- Install, on an x (_) machine, the
qemu-arm-static
package from the AURhttps://aur.archlinux.org/packages/qemu-arm-static
This will be used later in order to enable the use of an aarch 64 chroot on x 86 _ 64.
- Extract the aarch 64 image, and use
systemd-nspawn -D / path / to / aarch 64 - root
in order to gain root
I suggest changing MAKEFLAGS in/ etc / makepkg.conf
at this point in order to reflect the number of cores on your build system.
- Build, inside this container, the
linux-raspberrypi4-aarch 64
package from the AUR, posted by yours trulyhttps://aur.archlinux.org/packages/linux-raspberrypi4-aarch
Installation will take some time here as it’s a full kernel build. For reference, on my 12 C / (t Threadripper 1920 x the build took(a standard build or cross compile takes about 3 minutes, for reference).
Copy out the finished packages - both the kernel and headers.
- Extract the armv7h image, and use
systemd-nspawn -D / path / to / aarch 64 - root
in order to gain root
Copy your built aarch 64 kernel into the chroot.
Follow the instructions athttps://wiki.archlinux.org/index.php/Migrating_between_architectures
in order to migrate from armv7h to aarch 64.
Roughly:
pacman -S pacman-contrib # for pactree sed -i /etc/pacman.conf "s / armv7h / aarch 64 / '' -Syy pacman pacman -Sw $ (pacman -Qqn) pactree -l pacman | pacman -S - pacman -Qqn | pacman -S -
With a bit of luck, this all worked. You should now be able to install your built aarch 64 kernel into the chroot. Once all of that is done, copy over the completed filesystem to an SD card in the standard way, and you should be there! Seehttps://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4 (for reference.)
- Happy tinkering!
-
esotericnonsense (Daniel Edgecumbe)[email protected]
November 16, 2019
GIPHY App Key not set. Please check settings