linux-raspberrypi4-aarch64

2019-11-16 07:15:00

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:

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

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

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

I suggest changing MAKEFLAGS in /etc/makepkg.conf at this point in order to reflect the number of cores on your build system.

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.

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)

November 16, 2019