The generic kernel employed the the default ComfilePi operating system is not a real-time kernel. That is fine for many, if not most, use cases. For those use cases that may require real-time operation, we provide the following procedure. Please note that COMFILE Technology does not maintain the Raspberry Pi kernel or the Linux real-time patches, so those wishing to employ this capability should assume responsibility for it.
The Raspberry Pi Foundation maintains the kernel for Raspberry Pi-based products at https://github.com/raspberrypi/linux. The real-time kernel patches are maintained by a different group at https://cdn.kernel.org/pub/linux/kernel/projects/rt/. Compile errors and/or patch errors can arise if the 3 digit version number of the Raspberry Pi kernel and the real time patch do not match. The Raspberry Pi Foundation and the real-time patch maintainers do no coordinate their releases, so one must search the kernel's Makefile version history for a “Linux x.y.z” commit that matches the real-time kernel patch version, then use the “Merge remote-tracking…” commit that follows it. At the time of writing this, the latest such commit for the 5.10.y branch was here:
Given the versioning limitations explained above, the following shell script cross-compiles kernel version 5.10.35. It will download all necessary software and source code, cross-compile the real-time kernel, and package the resulting assests for deployment to a ComfilePi panel PC. It was tested on an Ubuntu 20.04 x64 workstation, and in an Ubuntu 20.04 instance of Windows Subsystem for Linux.
#!/bin/bash KERNEL_VERSION=5.10 RT_PATCH_VERSION=$KERNEL_VERSION.35-rt39 COMMIT_HASH=53a5ac4935c500d32bfc465551cc5107e091c09c DEFCONFIG=bcm2709_defconfig ARCH=arm TARGET=arm-linux-gnueabihf KERNEL_BRANCH=rpi-$KERNEL_VERSION.y COMPILER=$TARGET- # All work will be done in $PWD/rtkernel. The final result will be packaged as $PWD/rtkernel/result PROJECT_DIR=`pwd`/rtkernel rm -rf $PROJECT_DIR mkdir $PROJECT_DIR cd $PROJECT_DIR # install necessary packages sudo apt update sudo apt install -y wget git bc bison flex libssl-dev make libc6-dev libncurses5-dev crossbuild-essential-armhf # download the kernel and RT patch git clone --depth=1 --branch $KERNEL_BRANCH https://github.com/raspberrypi/linux wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/$KERNEL_VERSION/older/patch-$RT_PATCH_VERSION.patch.gz gunzip patch-$RT_PATCH_VERSION.patch.gz cd linux # Need this to get precisely the correct kernel version git fetch origin $COMMIT_HASH git checkout $COMMIT_HASH # Patch the kernel patch -p1 < ../patch-$RT_PATCH_VERSION.patch # Prepare configuration make ARCH=$ARCH CROSS_COMPILE=$COMPILER mrproper make ARCH=$ARCH CROSS_COMPILE=$COMPILER $DEFCONFIG # Configure the kernel # At this step, select "Virtualization" and deselect "Kernel-based Virtual Machine (KVM) support" # Then, select "General setup" --> "Preemption Model" --> "Fully Preemptible Kernel (Real-Time)" make ARCH=$ARCH CROSS_COMPILE=$COMPILER menuconfig # Compile make -j16 ARCH=$ARCH CROSS_COMPILE=$COMPILER zImage modules dtbs # copy assets to the $PROJECT_DIR/result directory RESULT_DIR=$PROJECT_DIR/result mkdir $RESULT_DIR EXT4_DIR=$RESULT_DIR/ext4 FAT32_DIR=$RESULT_DIR/fat32 mkdir $FAT32_DIR mkdir $EXT4_DIR make ARCH=$ARCH CROSS_COMPILE=$COMPILER INSTALL_MOD_PATH=$EXT4_DIR modules_install cp arch/$ARCH/boot/zImage $FAT32_DIR/ cp arch/$ARCH/boot/dts/*.dtb $FAT32_DIR/ mkdir $FAT32_DIR/overlays cp arch/$ARCH/boot/dts/overlays/*.dtb* $FAT32_DIR/overlays/ cp arch/$ARCH/boot/dts/overlays/README $FAT32_DIR/overlays/
After running the build script above, the rtkernel/result directory will contain 2 directories: fat32 and ext4. The fat32 directory contains assets that must be deployed to the ComfilePi's FAT32 partition (i.e. the /boot directory) and the ext4 directory contains assets that must be deployed to the ComfilePi's operating system root partition (i.e. the / directory).
# Package up the result into a single file tar czf rtkernel.tgz rtkernel/result/* # transfer the file to the ComfilePi scp rtkernel.tgz pi@192.168.0.5:
# Unpack the files tar xzf rtkernel.tgz cd rtkernel/result # Copy files to the /boot directory sudo cp fat32/zImage /boot/kernel7.img sudo cp fat32/*.dtb /boot/ sudo cp fat32/overlays/*.dtb* /boot/overlays/ sudo cp fat32/overlays/README /boot/overlays/ # Copy files to the / directory sudo cp -rd ext4/lib/* /lib
After rebooting, verify that the new kernel is loaded and running
$uname -a Linux raspberrypi 5.10.35-rt39-v7+ #1 SMP PREEMPT_RT Thu Jun 24 11:13:50 KST 2021 armv7l GNU/Linux
If you encounter freezing or lockups while running the real-time kernel, you may need to incorporate the patch described at https://www.osadl.org/Single-View.111+M5c03315dc57.0.html