Walid
Walid

Reputation: 119

Real time with raspberry pi CM4

I want to apply real time on my raspberry pi CM4. My current kernel version is 6.1.19, Is this version available for applying PREEMPT_RT, or I should build a new kernel to apply PREEMPT_RT? and what is the steps to do any of mentioned options?

Thank you.

Upvotes: 0

Views: 571

Answers (1)

John
John

Reputation: 1

First, install RaspiOS on the CM4. Then do this on your PC (this method has you build, cross-compile, the RT-kernel on your PC, then deploy to the CM4):

Install necessary packages

$ sudo dnf install gcc-aarch64-linux-gnu gcc-c++-aarch64-linux-gnu

Create build-directories

(rt-kernel/ is the target directory for the new build to be deployed to the CM4)

$ mkdir -p  ~/repos/rpi-cm4
$ cd ~/repos/rpi-cm4
$ mkdir -p rt-kernel/boot/firmware

##clone repo (check for latest branch); this creates a new sub-directory "linux"

$ git clone --depth 1 --branch rpi-6.6.y https://github.com/raspberrypi/linux

download patch (version must match repo branch numeric)

$ wget -c https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/6.6/patch-6.6.23-rt28.patch.xz

--- If the wget command throws an error about establishing SSL connection, just use a browser to download the patch and manually copy it to ~/repos/rpi-cm4/.

Apply the RT patch (decompress patch, cd to rpi repo, apply patch)

$ xz -d patch-6.6.23-rt28.patch.xz
$ cd linux
$ patch -p1  < ~/repos/rpi-cm4/patch-6.6.23-rt28.patch.xz

Set up build environment parameters

$ export ARCH=arm64 
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ export INSTALL_MOD_PATH=~/repos/rpi-cm4/rt-kernel
$ export INSTALL_DTBS_PATH=~/repos/rpi-cm4/rt-kernel

Prepare the build config-profile for the CM4

$ KERNEL=kernel8
$ make bcm2711_defconfig

Run the configuration dialog

$ make menuconfig

In menuconfig:
A) Uncheck “Virtualization” in the main menu
B) Select “General setup —>”
C) Toggle/Enable Configure standard kernel features (expert users)
C) Select “Fully Preemptible Kernel (Real-Time”
D) Go up a level to “General setup —>”
E) Select “Timers subsystem –>”
F) Uncheck “Old Idle dynticks config”.
G) Select “Timer tick handling (Idle dynticks system (tickles idle)) —>”
H) Check “Periodic timer ticks (constant rate, no dynticks)”
I) Save and Exit

## Compile the new kernel (-jX; change X to num parallel jobs desired)
$ make -j4 Image.gz modules dtbs

## Install modules and dtbs to INSTALL_MOD_PATH and DTBS_MOD_PATH
$ make modules_install
$ make dtbs_install

## Copy the new kernel to the target directory under boot/firmware
## as kernel8.img. Create sym-link to it under boot/.
$ cp arch/arm64/boot/Image ../rt-kernel/boot/firmware/kernel8.img
$ cd ../rt-kernel/boot
$ ln -s firmware/kernel8.img

## Make compressed archive of the target directory and transfer to CM4
$ cd ..
$ tar czf ../rt-kernel.tgz *
$ cd ..
$ rsync rt-kernel.tgz <user>@<ip>:

### The following steps performed on the CM4 as normal non-root user ###
### sudo privileges required.

## Assuming rt-kernel.tgz resides top-level of user's home directory ##
## go to top-level of home-dir
$ cd

# Create tmp directory and move rt-kernel.tgz into tmp/
$ mdkir tmp
$ mv rt-kernel.tgz tmp/
$ cd tmp
$ tar xzf rt-kernel.tgz

# Using sudo, copy new kernel files to appropriate destinations
$ sudo cp -rd boot/* /boot/
$ sudo cp -rd broadcom/bcm* /boot/
$ sudo cp -rd lib/* /lib/
$ sudo cp -rd overlays/* /boot/overlays/

Reboot the CM4.

Upvotes: 0

Related Questions