#!/bin/bash # Raspberry Pi OS # Build a PREEMPT_RT kernel for RPI 5 # # Pre requisites # - burn Raspberry Pi OS Lite 64bit # - after first boot #sudo apt update && sudo apt dist-upgrade -y # - install Xfce Desktop and default to boot into #sudo apt install xfce4 #sudo systemctl set-default graphical.target # enable access to samba shares #sudo apt install smbclient #sudo apt install gvfs-backends #sudo sync #sudo reboot # going to kernel stuff #uname -a # install neccessary packages to build a kernel sudo apt install git bc bison flex libssl-dev make libncurses5-dev -y mkdir ~/build && cd ~/build KERNEL_VERSION=6.6 KERNEL=kernel_2712 KERNEL_BRANCH=rpi-$KERNEL_VERSION.y RT_PATCH_VERSION=$KERNEL_VERSION.63-rt46 # get the kernel sources for Raspberry Pi OS git clone --depth=1 --branch $KERNEL_BRANCH https://github.com/raspberrypi/linux wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/$KERNEL_VERSION/older/patch-$RT_PATCH_VERSION.patch.gz gunzip patch-$RT_PATCH_VERSION.patch.gz cd linux/ # Patch the kernel patch -p1 < ../patch-$RT_PATCH_VERSION.patch # create default config make bcm2712_defconfig # set values to configure the kernel as _RT # make menuconfig ./scripts/config --set-val CONFIG_LOCALVERSION "\"-v8-16k-DeJe63\"" ./scripts/config --set-val CONFIG_PREEMPT_RT y ./scripts/config --set-val CONFIG_RCU_BOOST y ./scripts/config --set-val CONFIG_RCU_BOOST_DELAY 500 ./scripts/config --set-val CONFIG_RCU_NOCB_CPU y ./scripts/config --set-val CONFIG_NO_HZ_FULL y ./scripts/config --set-val CONTEXT_TRACKING_USER_FORCE n ./scripts/config --set-val RCU_NOCB_CPU_DEFAULT_ALL n ./scripts/config --set-val RCU_NOCB_CPU_CB_BOOST y # build the kernel, this takes some time make -j6 Image.gz modules dtbs # make it live sudo make -j6 modules_install sudo cp /boot/firmware/$KERNEL.img /boot/firmware/$KERNEL-backup.img sudo cp arch/arm64/boot/Image.gz /boot/firmware/$KERNEL.img sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/ sudo cp arch/arm64/boot/dts/overlays/*.dtb /boot/firmware/overlays/ sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/ # add "isolcpus=2,3 max.processor.cstate=1" to cmdline.txt # flush and reboot #sudo sync #sudo reboot # check if right kernel is installed #uname -a # install linuxcnc #sudo apt install ./linuxcnc-uspace_2.9.3_arm64.deb