User Tools

Site Tools

한국어

comfilepi:compile_a_real-time_kernel:index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
comfilepi:compile_a_real-time_kernel:index [2023/05/12 10:08]
COMFILE Technology [Troubleshooting]
comfilepi:compile_a_real-time_kernel:index [2023/11/22 08:57] (current)
COMFILE Technology [Deploy to the ComfilePi]
Line 1: Line 1:
 ====== Compile and Deploy a Real-Time Kernel to the ComfilePi ====== ====== Compile and Deploy a Real-Time Kernel to the ComfilePi ======
  
-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 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.
  
 +In addition to compiling and deploying a realtime kernel, [[comfilepi:​improving_real-time_performance:​index|other OS configurations]] may be necessary to improve the realtime performance.
 +
 +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.
 ===== Kernel Versioning ===== ===== Kernel Versioning =====
  
-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 [[https://​github.com/​raspberrypi/​linux/​commits/​rpi-5.10.y/Makefile|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:+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 [[https://​github.com/​raspberrypi/​linux/​commits/​rpi-6.1.y|kernel'​s ​commit ​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:
  
 {{ :​comfilepi:​compile_a_real-time_kernel:​commit.png }} {{ :​comfilepi:​compile_a_real-time_kernel:​commit.png }}
Line 11: Line 14:
 ===== Build Script ===== ===== Build Script =====
  
-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 [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​about|Windows Subsystem for Linux]].+Given the versioning limitations explained above, the following shell script cross-compiles kernel version ​6.1.26.  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 a Debian ​instance of [[https://​docs.microsoft.com/​en-us/​windows/​wsl/​about|Windows Subsystem for Linux]].
  
 <code bash> <code bash>
 #!/bin/bash #!/bin/bash
  
-KERNEL_VERSION=5.10 +# You may need to install the following packages 
-RT_PATCH_VERSION=$KERNEL_VERSION.35-rt39 +# apt update ​-y 
-COMMIT_HASH=53a5ac4935c500d32bfc465551cc5107e091c09c +# apt install ​-y wget git bc bison flex libssl-dev make libc6-dev libncurses5-dev crossbuild-essential-$ARCH
-DEFCONFIG=bcm2709_defconfig +
-ARCH=arm +
-TARGET=arm-linux-gnueabihf+
  
 +KERNEL_VERSION=6.1
 +RT_PATCH_VERSION=$KERNEL_VERSION.26-rt8
 +COMMIT_HASH=dbcb82357ef21be47841ba39d117b626d715af31
 +DEFCONFIG=bcm2711_defconfig
 +ARCH=arm64
 +TARGET=aarch64-linux-gnu
 +KERNEL_NAME=kernel8
 + 
 KERNEL_BRANCH=rpi-$KERNEL_VERSION.y KERNEL_BRANCH=rpi-$KERNEL_VERSION.y
 COMPILER=$TARGET- COMPILER=$TARGET-
 + 
 # All work will be done in $PWD/​rtkernel. ​ The final result will be packaged as $PWD/​rtkernel/​result # All work will be done in $PWD/​rtkernel. ​ The final result will be packaged as $PWD/​rtkernel/​result
-PROJECT_DIR=`pwd`/​rtkernel +WORK_DIR=`pwd`/​rtkernel 
-rm -rf $PROJECT_DIR +rm -rf $WORK_DIR 
-mkdir $PROJECT_DIR +mkdir $WORK_DIR 
-cd $PROJECT_DIR +cd $WORK_DIR 
- +   
-# install necessary packages +# download the kernel
-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 git clone --depth=1 --branch $KERNEL_BRANCH https://​github.com/​raspberrypi/​linux
 +  
 +# download the RT patch
 wget http://​cdn.kernel.org/​pub/​linux/​kernel/​projects/​rt/​$KERNEL_VERSION/​older/​patch-$RT_PATCH_VERSION.patch.gz 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 gunzip patch-$RT_PATCH_VERSION.patch.gz
 +  
 +# Need this to get precisely the correct kernel version
 cd linux cd linux
- 
-# Need this to get precisely the correct kernel version 
 git fetch origin $COMMIT_HASH git fetch origin $COMMIT_HASH
-git checkout ​$COMMIT_HASH +git reset --hard ​$COMMIT_HASH 
 + 
 # Patch the kernel # Patch the kernel
 patch -p1 < ../​patch-$RT_PATCH_VERSION.patch patch -p1 < ../​patch-$RT_PATCH_VERSION.patch
- +  
-# Prepare configuration + # Prepare configuration
-make ARCH=$ARCH CROSS_COMPILE=$COMPILER mrproper+
 make ARCH=$ARCH CROSS_COMPILE=$COMPILER $DEFCONFIG make ARCH=$ARCH CROSS_COMPILE=$COMPILER $DEFCONFIG
 + 
 + # Configure to use the "Fully Preemptible Kernel (Real-Time)"​ kernel
 +./​scripts/​config --set-val CONFIG_PREEMPT_RT y
 +./​scripts/​config --set-val CONFIG_RCU_BOOST y
 +./​scripts/​config --set-val CONFIG_RCU_BOOST_DELAY 500
 +./​scripts/​config --set-val CONFIG_RCU_NOCB_CPU y
 +./​scripts/​config --set-val CONFIG_NO_HZ_FULL y
 +./​scripts/​config --set-val CONTEXT_TRACKING_USER_FORCE n
 +./​scripts/​config --set-val RCU_NOCB_CPU_DEFAULT_ALL n
 +./​scripts/​config --set-val RCU_NOCB_CPU_CB_BOOST y
 + 
 +# Compile
 +make -j32 ARCH=$ARCH CROSS_COMPILE=$COMPILER Image.gz modules dtbs
  
-Configure ​the kernel +copy assets to the root file system 
-# At this step, select "​Virtualization"​ and deselect "​Kernel-based Virtual Machine (KVM) support"​ +make ARCH=$ARCH CROSS_COMPILE=$COMPILER ​INSTALL_MOD_PATH=modules_to_install modules_install
-# 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+
  
 + # Out of linux, out of work_dir
 +cd ../../
 + 
 # copy assets to the $PROJECT_DIR/​result directory # copy assets to the $PROJECT_DIR/​result directory
-RESULT_DIR=$PROJECT_DIR/result +RESULT_DIR=$WORK_DIR/result 
-mkdir $RESULT_DIR +mkdir -p $RESULT_DIR/​boot/​overlays 
-EXT4_DIR=$RESULT_DIR/​ext4 +cp ${WORK_DIR}/​linux/​arch/$ARCH/​boot/​Image.gz ​${RESULT_DIR}/​boot/​$KERNEL_NAME.img 
-FAT32_DIR=$RESULT_DIR/fat32 +cp -r ${WORK_DIR}/linux/modules_to_install/​lib/​* ​${RESULT_DIR}/​lib
-mkdir $FAT32_DIR +cp ${WORK_DIR}/​linux/​arch/​$ARCH/​boot/​dts/broadcom/*.dtb ${RESULT_DIR}/boot
-mkdir $EXT4_DIR +cp ${WORK_DIR}/​linux/​arch/​$ARCH/​boot/​dts/​overlays/​*.dtb* ${RESULT_DIR}/​boot/​overlays/​ 
-make ARCH=$ARCH CROSS_COMPILE=$COMPILER INSTALL_MOD_PATH=$EXT4_DIR modules_install +cp ${WORK_DIR}/​linux/​arch/​$ARCH/​boot/​dts/​overlays/​README ${RESULT_DIR}/​boot/overlays/
-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/+
 </​code>​ </​code>​
  
 ===== Deploy to the ComfilePi ===== ===== Deploy to the ComfilePi =====
  
-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).+After running the build script above, the //​rtkernel/​result//​ directory will contain 2 directories:​ //boot// and //lib//.  The //boot// directory contains assets that must be deployed to the ComfilePi'​s FAT32 partition (i.e. the ///boot// directory) and the //lib// directory contains assets that must be deployed to the ComfilePi'​s operating system root partition (i.e. the ///lib// directory).
  
 +On the build PC:
 <code bash> <code bash>
 # Package up the result into a single file # Package up the result into a single file
-tar czf rtkernel.tgz rtkernel/​result/​*+tar czf rtkernel.tgz ​-C rtkernel/​result/ ​.
  
 # transfer the file to the ComfilePi # transfer the file to the ComfilePi
Line 90: Line 100:
 </​code>​ </​code>​
  
 +[[http://​downloads.comfiletech.com/​ComfilePi/​realtime/​rtkernel_6.1.26-rt8.tgz|Download rtkernel_6.1.26-rt8.tgz]] (MD5: cadb563fc3cc61e9a2a5fc571a08004a)
 +
 +On the ComfilePi:
 <code bash> <code bash>
-Unpack ​the files +Install ​the kernel assets 
-tar xzf rtkernel.tgz +sudo tar xzf rtkernel.tgz ​--directory / --keep-directory-symlink --no-same-owner
- +
-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+
 </​code>​ </​code>​
  
Line 109: Line 111:
 <​code>​ <​code>​
 $uname -a $uname -a
-Linux raspberrypi ​5.10.35-rt39-v7+ #1 SMP PREEMPT_RT ​Thu Jun 24 11:13:50 KST 2021 armv7l ​GNU/Linux+Linux raspberrypi ​6.1.21-rt8-v8+ #1 SMP PREEMPT_RT ​Fri May 12 10:19:19 KST 2023 aarch64 ​GNU/Linux
 </​code>​ </​code>​
  
comfilepi/compile_a_real-time_kernel/index.1683853682.txt.gz · Last modified: 2023/05/12 10:08 by COMFILE Technology