Building a 64-bit aarch64 kernel and userspace for the Raspberry Pi 4
source link: https://esotericnonsense.com/blog/rpi-chroot.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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 <> (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) [email protected]
November 16, 2019
Recommend
-
36
One of the cool thing of working for a software company is that very often you get new hardware prototypes to test. But this is not the case, I bought the Rpi4 because it’s extremely cheap! The Rpi4 c...
-
6
Index of pub/NetBSD-daily/HEAD/latest/evbarm-aarch64/binary/kernel/Index of pub/NetBSD-daily/HEAD/latest/evbarm-aarch64/binary/kernel/ NameLast modifiedSize
-
10
Tutorial - emulate an iOS kernel in QEMU up to launchd and userspace Jul 22, 2018 I got launchd and recoveryd to start on an emulated iPhone running iOS 12 beta 4’s kerne...
-
10
Install Ubuntu Server 20.04.1 LTS 64-bit on Raspberry Pi I was trying to get Ubuntu Server 20.04.1 LTS Focal Fossa installed on a Raspberry Pi 3 B+. While this seems like it should have been a straig...
-
7
How to compile Rust and LLVM for ESP32 on a Raspberry Pi (aarch64) Tue, Sep 21, 2021 ESP32 is a series of microcontrollers that has the particularity to have both integrated Bluetooth and Wi-Fi. It mak...
-
8
It's official: Raspberry Pi OS goes 64-bit February 3, 2022 64-bits. More is always better, right? W...
-
11
Raspberry Pi OS 64-bit 版本正式推出 在 Twitter 上看到前同事貼了 Raspberry Pi 官方放出 Raspberry Pi OS 64-bit 版本的公告:「
-
6
Biesheuvel: Mitigating kernel risks on 32-bit ARM [Posted February 23, 2022 by corbet] Ard Biesheuvel
-
11
StarCTF 2022 AArch64 kernel Pwn babyarm 发表于...
-
5
Linux Kernel 6.2 - Userspace Processes To Enable Mitigation
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK