The objective of these instructions is to build a stock arm 64bit Linux Kernel for use on the Raspberry Pi 4B on a Debian x64 machine and deploy it on the Raspberry Pi.
I. Build Raspberry Pi kernel
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-5.15.y https://github.com/raspberrypi/linux.git
svn export https://github.com/raspberrypi/firmware/trunk/boot --force
rm boot/kernel*
rm boot/*.dtb
rm boot/overlays/*.dtbo
Load the stock Raspberry 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" \
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 ..
Install library to our folder
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=../library_install/ modules_install
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
2. Deploy new kernel to Raspberry Pi 4
Insert SDcard installed raspbian and mount to Ubuntu
sudo mkdir -p /media/pi4/
sudo mount /dev/sdb1 /media/pi4/
Remove the old Kernel and Install the new.
sudo rm -r media/pi4/boot/*
sudo cp -r ./boot/* media/pi4/boot/
Copy library to SDcard
sudo cp -r ../library_install/* media/pi4/rootfs/
sudo sync
Now you can unmount sdcard and plug in to Pi4 to test with new kernel
Leave a comment