Skip to content

Instantly share code, notes, and snippets.

@G-UK
Last active August 27, 2023 15:09
Show Gist options
  • Save G-UK/196638656e822a2b67f7843db875646d to your computer and use it in GitHub Desktop.
Save G-UK/196638656e822a2b67f7843db875646d to your computer and use it in GitHub Desktop.
Building the Raspberry Pi 3 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 3B 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.

On your Debian build machine

Create a build directory.

mkdir ~/Pi3-Kernel && cd ~/Pi3-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 3 configuration.

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

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

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

Build the Kernel with optimisations for the Pi3 Arm Cortex A53 CPU.

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j4 \
    CXXFLAGS="-march=armv8-a+crypto+crc -mtune=cortex-a53" \
    CFLAGS="-march=armv8-a+crypto+crc -mtune=cortex-a53" \
    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/Pi3-Kernel/
sudo cp -r boot /mnt/n/Pi3-Kernel/
sudo rm ~/Pi3-Kernel/linux*
sudo rm -r ~/Pi3-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' > ~/cmdline.txt
echo $'kernel=kernel8.img\ngpu_mem=16\narm_64bit=1' > ~/config.txt

Kernel Installation

Remove the old Kernel and Install the new.

sudo cp /mnt/NAS/Pi3-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/Pi3-Kernel/boot/* /boot/
sudo cp ~/cmdline.txt /boot/
sudo cp ~/config.txt /boot/
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment