For the realtime kernel
Ideally you don't want to be building the kernel sources on a SD card
so personally I tend to keep /boot on the sd card but move everything else across to a USB Hard Disk
I won't bother to go into details on how to do that here unless someone asks.
raspian recently merged 6.1.27 into they're 6.1 branch
github.com/raspberrypi/linux/tree/83cf6b...b7fef70b1a7c9539b0b9
using this in combination with this patch
mirrors.edge.kernel.org/pub/linux/kernel...-6.1.26-rt8.patch.xz
this seems to work ok for a realtime rpi kernel, at least for the Pi4
Install some dependenciessudo apt install git bc bison flex libssl-dev make gcc raspberrypi-kernel-headers libc6-dev
sudo apt install patch xz-utils libncurses-dev
Download Linux Sourcescd /usr/src/
wget https://github.com/raspberrypi/linux/archive/refs/heads/rpi-6.1.y.tar.gz
tar -xvf rpi-6.1.y.tar.gz
mv linux-rpi-6.1.y linux-6.1.27-linuxcnc-rt
Patch Sourceswget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.1/patch-6.1.26-rt8.patch.xz
cd linux-6.1.27-linuxcnc-rt
xzcat ../patch-6.1.26-rt8.patch.xz | patch -p1
Set the default config for the rpi# 64bit Rpi4 / Rpi3
KERNEL=kernel8
make bcm2711_defconfig
# 32Bit Rpi3
KERNEL=kernel7
make bcm2709_defconfig
# 32Bit Rpi4
KERNEL=kernel7l
make bcm2711_defconfig
- Run make menuconfig
- under General -> Preemption Model, switch this to real-time
- Edit .config and add something to the end of `CONFIG_LOCALVERSION` to make it unique
- such as "-linuxcnc-rt"
Next to build the sources
In this example I'm using a subdirectory of
/boot/rt/
this way we're free to switch back to the original kernel if needed
# For 64bit
make -j4 Image.gz modules dtbs
make modules_install
mkdir -p /boot/rt/overlays/
cp arch/arm64/boot/dts/broadcom/*.dtb /boot/rt/
cp arch/arm64/boot/dts/overlays/*.dtb* /boot/rt/overlays/
cp arch/arm64/boot/dts/overlays/README /boot/rt/overlays/
cp arch/arm64/boot/Image.gz /boot/rt/$KERNEL.img
# For 32bit
make -j4 zImage modules dtbs
make modules_install
mkdir -p /boot/rt/overlays/
cp arch/arm/boot/dts/*.dtb /boot/rt/
cp arch/arm/boot/dts/overlays/*.dtb* /boot/rt/overlays/
cp arch/arm/boot/dts/overlays/README /boot/rt/overlays/
cp arch/arm/boot/zImage /boot/rt/$KERNEL.img
To boot to the new kernel
Edit the
/boot/config.txt file.
Add
os_prefix=/rt/ to the top, this will select the files under
/boot/rt where the new kernel will be located
If anything goes wrong then just put the sd card in a usb adapter and comment out that line to switch back to the old kernel
If using a Pi3 I'd suggest sticking to 32bit
Also there seems to be some issues with it's USB Controller and Realtime
forums.raspberrypi.com/viewtopic.php?t=159170
One workaround for this is to add
dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 to the end of cmdline.txt
Which I think makes it more stable but I'm not entirely sure if it's fully stable
as I was still seeing some messages related to mmc1 under dmesg with network traffic
The Pi4 by comparison seems a lot more stable
I've not got an orangePi 5 to test but they're official kernels seems to be older at around version 5.4.65
with some branches going up to 5.18.
I think Armbian may have patches for a later kernel for the rock chipset.
This probably also applies to a lot of the other rpi alternatives since a lot of those also use the same rock chipset
Pi4's are starting to make they're way back onto Amazon now but they are a bit expensive still