RPi-RT

From DaqWiki
Revision as of 16:40, 5 January 2024 by Lmartin (talk | contribs) (Created page with "== Introduction == These are notes from cross-compiling a real-time (i.e. "fully preemptive") kernel for raspberry pi 3B+ and 4B. Adapted from https://www.instructables.com/64bit-RT-Kernel-Compilation-for-Raspberry-Pi-4B-/ and https://www.instructables.com/64bit-RT-Kernel-Compilation-for-Raspberry-Pi-4B-/ == Prerequisites == Install the toolchain for cross-compilation: <pre> sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev sudo apt install cr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

These are notes from cross-compiling a real-time (i.e. "fully preemptive") kernel for raspberry pi 3B+ and 4B. Adapted from https://www.instructables.com/64bit-RT-Kernel-Compilation-for-Raspberry-Pi-4B-/ and https://www.instructables.com/64bit-RT-Kernel-Compilation-for-Raspberry-Pi-4B-/

Prerequisites

Install the toolchain for cross-compilation:

sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
sudo apt install crossbuild-essential-arm64

Sources

Go to https://github.com/raspberrypi/linux/branches and select a branch. If you choose the default branch, you do not need to explicitly select it in the following command:

git clone --depth=1 --branch <branch> https://github.com/raspberrypi/linux

Find the matching real-time patch file in https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/ and download it. E.g.:

wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.1/patch-6.1.70-rt21.patch.gz

Apply the patch to the kernel sources:

cd linux
gzip -cd ../patch-6.1.70-rt21.patch.gz | patch -p1 --verbose
mkdir ../kernel-out

Configuring and building the kernel

Default configuration

rPi 3B+

make O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcmrpi3_defconfig

rPi 4B

make O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig

Turn on Real-Time support

make O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

Navigate to General->Preemption Model and select the Real-Time option.

Building the kernel

Compilation of the kernel will take several minutes, depending on PC power and number of parallel threads.

make -j16 O=../kernel-out/  ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs

The -j16 option is for the number of parallel processes and should probably be chosen no larger than the number of CPU cores.