Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrwj/878f79a2aabffd4c9c14524658b4de58 to your computer and use it in GitHub Desktop.
Save andrwj/878f79a2aabffd4c9c14524658b4de58 to your computer and use it in GitHub Desktop.
Building the Raspberry Pi 4 Arm64 Linux Kernel

The Raspberry Pi foundation have now released a beta version of an official 64-bit Kernel which can be installed using the rpi-update script. The rpi-update script can be found at https://github.com/Hexxeh/rpi-update/blob/master/rpi-update or through the Raspbian repositories

Introduction

The objective of these instructions is to build a stock 64bit Linux Kernel for use on the Raspberry Pi 4B on a Debian x64 machine (Windows Subsystem for Linux in my case), and deploy on the Raspberry Pi.

Notes:

  • Transfer to Pi is using my NAS in this example, replace with shared drive/memory stick etc. as required.
    • (N: drive on Windows and /mnt/NAS on Linux in this example).
  • For a specific Kernel version replace the 4.19 with the wanted version in the git clone command.
    • Greater than 3GB RAM only currently available on Kernel 4.19
      • Workaround: Add "total_mem=3072" to config.txt when using other kernel versions with the 4GB Pi4
    • FKMS 3D driver fixes only currently available on Kernel 4.19.
      • 3D Acceleration does not work, falls back to software.

On your Debian build machine

Create a build directory.

mkdir ~/Pi4-Kernel && cd ~/Pi4-Kernel

Clone the official Raspberry Pi repository and pre-built binaries (Ensuring to remove the pre-built 32bit Kernel)

git clone --depth=1 -b rpi-4.19.y https://github.com/raspberrypi/linux.git
svn export https://github.com/raspberrypi/firmware/trunk/boot
rm boot/kernel*
rm boot/*.dtb
rm boot/overlays/*.dtbo

Load the stock Raspbeery Pi 4 configuration.

cd linux
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig

Update Config using nconfig if required (Skip for stock Pi4 config)

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- nconfig

Build the Kernel with optimisations for the Pi4 Arm Cortex A72 CPU.

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 \
    CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72" \
    CFLAGS="-march=armv8-a+crc -mtune=cortex-a72" \
    bindeb-pkg
cp arch/arm64/boot/Image ../boot/kernel8.img
cp arch/arm64/boot/dts/overlays/*.dtbo ../boot/overlays/
cp arch/arm64/boot/dts/broadcom/*.dtb ../boot/
cd ..

Now to copy our new Kernel off the build machine and tidy up your build folder.

sudo mount -t drvfs N: /mnt/n
sudo cp *.deb /mnt/n/Pi4-Kernel/
sudo cp -r boot /mnt/n/Pi4-Kernel/
sudo rm ~/Pi4-Kernel/linux*.deb
sudo rm -r ~/Pi4-Kernel/boot

On Your Pi

Startup Configuration

If required create a cmdline.txt & config.txt file to boot using. We'll keep a copy of them in your home directory for now.

echo 'dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait net.ifnames=0' > ~/boot/cmdline.txt
echo $'kernel=kernel8.img\ngpu_mem=512\narm_64bit=1\ndtoverlay=vc4-fkms-v3d' > ~/boot/config.txt

Kernel Installation

Remove the old Kernel and Install the new.

sudo cp /mnt/NAS/Pi4-Kernel/*.deb /home/pi/
cd ~/
mkdir temp && cd temp
sudo apt purge linux-headers-* linux-image-*
cd .. && rm -r temp
sudo rm -r /boot/*
sudo dpkg -i linux-headers-*.deb linux-image-*.deb linux-libc-*.deb
sudo cp -r /mnt/NAS/Pi4-Kernel/boot/* /boot/
sudo cp ~/boot/cmdline.txt /boot/
sudo cp ~/boot/config.txt /boot/
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment