forked from raspberrypi/linux
-
Notifications
You must be signed in to change notification settings - Fork 12
Building PREEMPT_RT kernel for Raspberry Pi
Kevin Doren edited this page Aug 6, 2024
·
8 revisions
You can clone this repo for pre-patched sources if that meets your needs (you want different config options for same version).
Otherwise, you can work with upstream sources:
- Find and checkout a raspberrypi/linux commit which has a matching rt patch set
- Typically, the commit will be titled "Merge remote-tracking branch 'stable/linux-6.6.y' into rpi-6.6.y" by "popcornmix"
- get the matching patch set from https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.6/older
- Pi3 operation requires the same raspberry-pi rt patches that were used on the "official" rpi-4.19.y-rt kernel.
- Rebased patch set is here: https://raw.githubusercontent.com/kdoren/linux/rpi-5.10.35-rt/0001-usb-dwc_otg-fix-system-lockup.patch
Example: raspberrypi/linux has a merge commit for linux 6.6.35, and there exists rt patch set for 6.6.35.
To build:
Get kernel sources and apply any patches:
git clone https://github.com/raspberrypi/linux.git
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.6/older/patch-6.6.35-rt34.patch.xz
# wget https://raw.githubusercontent.com/kdoren/linux/rpi-5.10.35-rt/0001-usb-dwc_otg-fix-system-lockup.patch # Pi3 only
cd linux
# checkout the merge commit for raspberrypi linux 6.6.35
git checkout -b rpi-6.6.35-rt 5263478665260ec207b8ee4751401c1d4a6a514a
xzcat ../patch-6.6.35-rt34.patch.xz | patch -p1
# cat ../0001-usb-dwc_otg-fix-system-lockup.patch | patch -p1 # Pi3 Only
Install any build prerequisites: Kernel-Build-Prerequisites
Then configure and build.
export ARCH=arm64
export KERNEL=kernel8 # Pi4
# export KERNEL=kernel_2712 # Pi5
make bcm2711_defconfig # Pi4
# make bcm2712_defconfig # Pi5
make menuconfig
# set General -> Local version to "-rpi-v8" or "rpi-2712"
# set General -> Preemption Model to "Fully Preeemptible Kernel (Real-Time)"
# I disable "Virtualization"
# I set Kernel Features -> Timer frequency to 1000 HZ
# I set CPU Power Management -> CPU Frequency Scaling -> Default CPUFreq governor to "performance"
# Save as ".config"
make -j4 Image modules dtbs # if building 32-bit kernal, use "zImage" instead of "Image"
make LOCALVERSION= -j4 bindeb-pkg # the "LOCALVERION=" is needed to avoid the "+" at the end of the package name
Now we need to inject file "README" into the deb package, overwriting original deb package file:
cd ..
DEBFILE=linux-image-6.6.35-rt34-rpi-v8_6.6.35-1_arm64.deb
TMPDIR=/tmp/extract_${DEBFILE%%_*}
mkdir $TMPDIR
dpkg-deb -R $DEBFILE $TMPDIR/
cp linux/arch/arm64/boot/dts/overlays/README $TMPDIR/usr/lib/${DEBFILE%%_*}/overlays/
dpkg-deb -b $TMPDIR $DEBFILE # overwrites original deb package file
rm -rf $TMPDIR