linux-raspberrypi4-aarch64

Building a 64-bit aarch64 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 at https://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 from https://archlinuxarm.org/about/downloads

This will form the initial 32-bit environment that will run on the Pi.

Download the aarch64 multi-platform image ArchLinuxARM-aarch64-latest.tar.gz from https://archlinuxarm.org/about/downloads

This will be the 64-bit environment we chroot into and build the kernel within.

Install, on an x86_64 machine, the qemu-arm-static package from the AUR https://aur.archlinux.org/packages/qemu-arm-static

This will be used later in order to enable the use of an aarch64 chroot on x86_64.

Extract the aarch64 image, and use systemd-nspawn -D /path/to/aarch64-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-aarch64 package from the AUR, posted by yours truly https://aur.archlinux.org/packages/linux-raspberrypi4-aarch64

Installation will take some time here as it’s a full kernel build. For reference, on my 12c/24t Threadripper 1920x the build took 70 minutes (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/aarch64-root in order to gain root

Copy your built aarch64 kernel into the chroot.

Follow the instructions at https://wiki.archlinux.org/index.php/Migrating_between_architectures in order to migrate from armv7h to aarch64.

Roughly:

pacman -S pacman-contrib # for pactree sed -i /etc/pacman.conf "s/armv7h/aarch64/" pacman -Syy 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 aarch64 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! See https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4 for reference.

Happy tinkering! esotericnonsense (Daniel Edgecumbe) blog@esotericnonsense.com

November 16, 2019