forked from raspberrypi/linux
-
Notifications
You must be signed in to change notification settings - Fork 13
Building PREEMPT_RT kernel for Raspberry Pi
Kevin Doren edited this page Aug 10, 2024
·
8 revisions
These instructions are for building a 64-bit kernel on a 64-bit system. You can build on Raspberry Pi 64-bit if you have a USD SSD. I currently build on a Debian 12 VM (4 vCPU, builds take around 10 mins) running on an M3 Mac under VMware Fusion (which is free for personal use, and very good).
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 for a kernel version 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: Leave as-is, or change 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 -j4 bindeb-pkg