How to compile 64-bit RT-kernel for Raspberry Pi 5 for Debian bookworm onwards incl. trixie (i.e., /boot/firmware/)
sudo apt install git bc bison flex libssl-dev make
sudo apt install libncurses5-dev
sudo apt install raspberrypi-kernel-headers
mkdir ~/kernelClone the git, in this case kernel 7.0, from from https://github.com/raspberrypi/linux/tree/rpi-7.0.y
cd ~
git clone --depth 1 --branch rpi-7.0.y https://github.com/raspberrypi/linuxNEW: starting with linux kernel 6.12, the RT-patch is rolled into the mainline codebase for ARM64 architexture (and some others), so no need to apply RT-patches anymore!
git stash
git pull --rebase
#git stash clearP.S.: If resetting and updating your local (git-) environment with the last two steps does not work for any reason, you can always run sudo rm -rd ~/linux to start from scratch @ https://github.com/by/RT-Kernel?tab=readme-ov-file#clone-the-git-in-this-case-kernel-70-from-from-httpsgithubcomraspberrypilinuxtreerpi-70
#git pullmake bcm2712_defconfigmake menuconfig## I've made the following changes specifically for my NTP server to also enable kernel PPS:
sudo ~/linux/scripts/diffconfig ~/linux/arch/arm64/configs/bcm2712_defconfig ~/linux/defconfig
-CPU_FREQ_DEFAULT_GOV_ONDEMAND y
-CPU_FREQ_GOV_CONSERVATIVE y
-CPU_FREQ_GOV_POWERSAVE y
-CPU_FREQ_GOV_SCHEDUTIL y
-CPU_FREQ_GOV_USERSPACE y
-IR_GPIO_TX m
-LEDS_TRIGGER_CPU y
-NO_HZ y
-PREEMPT y
LOCALVERSION "-v8-16k" -> "-v8-16k-NTP"
PPS_CLIENT_GPIO m -> y
+CPU_FREQ_DEFAULT_GOV_PERFORMANCE y
+EFI_DISABLE_RUNTIME n
+HZ_1000 y
+NTP_PPS y
+PREEMPT_RT ySee also https://github.com/by/RT-Kernel/blob/main/bcm2712_defconfig_RT_NTP
make prepare
make CFLAGS='-O3 -march=native' -j6 Image.gz modules dtbs # recommendation is 1.5 times the number of cores (=4), which equals 6 -- if you have enough main memory!
sudo make -j6 modules_install # recommendation is 1.5 times the number of cores (=4), which equals 6sudo mkdir /boot/firmware/NTP
sudo mkdir /boot/firmware/NTP/overlayssudo cp -v /boot/firmware/cmdline.txt /boot/firmware/NTP/cmdline.txtThe newly built kernel is now also moved into /boot/firmware/NTP and expects its own cmdline.txt there, too; upside is that you can create an RT-kernel-specific cmdline.txt right here.
sudo mkinitramfs -o /boot/firmware/NTP/initramfs_2712-NTP $(uname -r)and ignore the warning about not being able to check availability of zstd compression support (CONFIG_RD_ZSTD) due to missing kernel configuration /boot/config-$(uname -r); here, only a copy of the file in this very directory is missing, but ``ìnitramfs```correct assumes it to be available (see the respective warning message).
os_prefix=NTP/
kernel=kernel_2712-NTP.imgand add to enable initramfs for your custom kernel
#auto_initramfs=1 as it apparently does not properly follow the changed directory os_prefix
initramfs initramfs_2712-NTP followkernelsudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/NTP/; sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/NTP/overlays/; sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/NTP/overlays/; sudo cp arch/arm64/boot/Image.gz /boot/firmware/NTP/kernel_2712-NTP.imgsudo reboot nowsudo SKIP_KERNEL=1 PRUNE_MODULES=1 rpi-update rpi-7.0.y