Raspberry PI 5B

Raspberry PI 5B

1. Update and Clean System

Update system packages

sudo apt update && sudo apt upgrade

Remove unnecessary packages

sudo apt remove libc++-14-dev llvm-14 cmake

2. Install Required Dependencies

Install necessary dependencies

sudo apt install clangd-19 g++ libc++-19-dev libonnxruntime-dev libprotobuf-dev protobuf-compiler bc bison flex \
    libssl-dev make git gcc g++ axel curl xz-utils libncurses5-dev libncursesw5-dev rt-tests libnuma-dev

3. Clone and Configure Kernel Source

Clone the Raspberry Pi Linux kernel source

git clone https://github.com/raspberrypi/linux
cd linux

Checkout a specific kernel version

git checkout fed8a0934de84a8eb9980ebd5c19b440611572bb

Download and apply RT kernel patch

wget https://raw.githubusercontent.com/FluxSand/Utilities/refs/heads/master/1.RT-Kernel-Patch/0001-Add-RT-feature.patch
git apply 0001-Add-RT-feature.patch

Download pre-configured kernel build configuration

wget https://raw.githubusercontent.com/FluxSand/Utilities/refs/heads/master/1.RT-Kernel-Patch/.config

4. Compile and Install Kernel

Set kernel variable

KERNEL=kernel_2712

Compile the kernel, modules, and device tree

make -j6 Image.gz modules dtbs

Install kernel modules

sudo make -j6 modules_install

5. Backup and Deploy New Kernel

Backup current kernel

sudo cp /boot/firmware/$KERNEL.img /boot/firmware/$KERNEL-backup.img

Copy newly compiled kernel and device tree to the boot directory

sudo cp arch/arm64/boot/Image.gz /boot/firmware/$KERNEL.img
sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/overlays/
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/

6. Install CMake

cd && wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0.tar.gz && tar -xvf cmake-3.28.0.tar.gz && cd cmake-3.28.0 && ./bootstrap && make -j4 && make install && cd ..

7. RT test in old kernel

uname -a
sudo cyclictest -S -p 95 -d 0 -i 1000 -D 1m -m
# View the results

output:

Linux XRobot 6.6.73-rt47-v8-16k #2 SMP PREEMPT Fri Jan 24 06:02:36 GMT 2025 aarch64 GNU/Linux
policy: fifo: loadavg: 0.72 0.27 0.09 1/224 1083

T: 0 ( 1080) P:95 I:1000 C:  13744 Min:      2 Act:    3 Avg:   11 Max:      41
T: 1 ( 1081) P:95 I:1000 C:  13743 Min:      4 Act:    7 Avg:   14 Max:      49
T: 2 ( 1082) P:95 I:1000 C:  13739 Min:      2 Act:    5 Avg:   13 Max:      41
T: 3 ( 1083) P:95 I:1000 C:  13734 Min:      2 Act:    7 Avg:   14 Max:      34

8. Reboot System

Reboot the system to apply changes

sudo reboot

9. RT test in new kernel

uname -a
sudo cyclictest -S -p 95 -d 0 -i 1000 -D 1m -m
# View the results

output:

Linux XRobot 6.6.73-rt47-v8-16k-RTLC+ #2 SMP PREEMPT_RT Fri Jan 24 06:02:36 GMT 2025 aarch64 GNU/Linux

policy: fifo: loadavg: 0.51 0.16 0.06 1/278 1128

T: 0 ( 1122) P:95 I:1000 C:  15641 Min:      1 Act:    3 Avg:    2 Max:      14
T: 1 ( 1123) P:95 I:1000 C:  15634 Min:      1 Act:    2 Avg:    2 Max:       8
T: 2 ( 1124) P:95 I:1000 C:  15631 Min:      1 Act:    2 Avg:    2 Max:      13
T: 3 ( 1125) P:95 I:1000 C:  15626 Min:      1 Act:    2 Avg:    2 Max:      10

10. Install onnxruntime

cd && git clone --recursive https://github.com/Microsoft/onnxruntime\
cd onnxruntime/

# This command will take a long time(more than 1 hours) and a lot of memory, please enable zram and swap, be patient.
./build.sh --config RelWithDebInfo --build_shared_lib --compile_no_warning_as_error --skip_submodule_sync --cmake_extra_defines CMAKE_OSX_ARCHITECTURES="aarch64"

cd /build/Linux/Release
sudo make install
sudo ldconfig