[LINUX] Procedure for installing Xenomai on RaspberryPi 3 model B + Part 1

Overview

For some reason, it became necessary to investigate the processing power of the real-time kernel, so I introduced Xenomai, which is a real-time kernel, to Raspberry Pi 3. At that time, I worked according to the official forum of Xenomai, but it didn't work at all and I struggled, so I summarized the introduction method. There are extremely few articles in Japanese about the introduction of Xenomai, and it is quite difficult unless you look at overseas posts (when you can not read English) Do you think it should be a guide for people who want to do the same thing from now on? (By the way, this is Qiita's first post)

Notes

It's an introduction method as of 2020! It may not work depending on the environment in which it is used.

table of contents

--What is Xenomai?

What is Xenomai?

--This refers to patches and their libraries that allow the Kernel to have real-time processing power when realizing a real-time operating system. --Since it is made based on Linux, it can only be applied to Linux OS. --With the introduction of Xenomai, you will be able to use various APIs that realize real-time performance. --Details are written below

Xenomai's Gitlab (wiki)

https://gitlab.denx.de/Xenomai/xenomai/-/wikis/home

Work environment

You can do it without a PC with a Linux environment, but in that case you will have to self-compile the Kernel with RPi, so be prepared for a considerable amount of time.

There are mainly two stages of work, and the first stage is to build a kernel so that Xenomai can be used. The second step is to build the Xenomai main body so that you can use the Xenomai library etc. This time, I will explain the first stage.

Work contents (kernel preparation)

I tried both self-compilation and cross-compilation this time, but I will describe the method I tried with cross-compilation (I may write a self-compilation method if I feel like it)

Preparation 1

This time Linux kernel 4.19.xxx (xxx is a sublevel of stable at that time) Start a terminal in a Linux environment and compile under your home directory Create a directory to store the downloaded ones

linux_user@TN-201709F100R:~$ mkdir /kernel_cnst/
linux_user@TN-201709F100R:~$ cd ./kernel_cnst/

Pull a normal Linux kernel for Raspberry Pi from Github. (You can also download directly from the git URL, but it is better to use git, so install the git command as apt-get or yum)

linux_user@TN-201709F100R:~$ git clone https://github.com/raspberrypi/linux -b rpi-4.19.y

When executed, the linux kernel source will be downloaded from the git repository. When finished, a directory called "linux" will be created.

linux_user@TN-201709F100R:~$ cd ./linux/
linux_user@TN-201709F100R:~$ head -4 Makefile

Then, check the version of the dropped source. In the environment I ran

# SPDX-License-Identifier: GPL-2.0
VERSION = 4
PATCHLEVEL = 19
SUBLEVEL = 127

And this is the Stable version at the time of work. (If you do not specify anything with the -b option, the Stable version at that time will be downloaded.)

Preparation 2

Next, pull the Xenomai source and patches from the following with wget.

Xenomai body: http://xenomai.org/downloads/xenomai/stable/ Xenomai iPipe patch: https://xenomai.org/downloads/ipipe/v4.x/arm/

If you drop them, be sure to place them under the working directory. (In my environment, kernel_cnst as above)

Preparation 3 (not required when self-compiling)

For self-compilation, I don't need it because I only need a linux standard compiler, If you want to cross-compile, you will need it, so do the following:

linux_user@TN-201709F100R:~$ cd ~/kernel_cnst/
linux_user@TN-201709F100R:~$ git clone https://github.com/raspberrypi/tools

Work content (kernel compilation)

Let's start the game ...

I'm sorry. Let's actually build and install the Xenomai kernel from here. Regardless of this kernel build, be sure to log when working on commands on linux! (I don't know why I failed later)

All the files you just dropped should be under the kernel_cnst directory.

In order to use the features of Xenomai, you have to extend the features of the kernel. The current directory structure looks like this

~/kernel_cnst/
  →/Xenomai3.x/ *xenomai source
  →/linux/ *kernel source
  →/ipipe_patch_xxx.patch *ipipe_patch
  →/tools/  *cross compile tool set

First, patch the kernel itself to give the kernel the functionality of iPipe. You can create a directory for ipipe itself and put it in it.

linux_user@TN-201709F100R:~$ cd ~/kernel_cnst/
linux_user@TN-201709F100R:~$ cd ./linux/
linux_user@TN-201709F100R:~$ ../Xenomai3.x/scripts/prepare-kernel.sh --linux=./ --arch=arm --ipipe=../ipipe_patch_xxx.patch --verbose

The first challenge. If "Build system ready" is displayed here, the patch has been applied without any problem. If you say "unable patch ~~~~", it fails. The problem is that I don't have the linux kernel version and the ipipe patch version (the wiki says it's okay if the Sublevels are different, but it wasn't) So, in this case, you need to modify the patch contents according to the version of linux. (I will write another article about patch correction)

Once the patch is hit, the rest is to build the Linux kernel.

linux_user@TN-201709F100R:~$ cd ~/kernel_cnst/linux/
linux_user@TN-201709F100R:~$ export CROSS_COMPILE=../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
linux_user@TN-201709F100R:~$ export KERNEL=kernel7

Note that it is not "kernel7" for PRi4 when setting environment variables for KERNEL.

linux_user@TN-201709F100R:~$ make bcm2709_defconfig
linux_user@TN-201709F100R:~$ make menuconfig

If when you run menuconfig and it says there is no such thing, do the following

linux_user@TN-201709F100R:~$ sudo apt-get install build-essential libncurses5-dev

When menuconfig opens, set the parameters as follows ([] cancels the setting, [x] check the setting)

CPU Power Management → CPU Frequency scaling → CPU Frequency scaling [ ]
Kernel Features → Contiguous Memory Allocator [ ]
Kernel Features → Allow for memory compaction [ ]
Kernel Hacking → KGDB: kernel debugger [ ]
Kernel Features → Time Frequency → 1000Hz

This completes the config settings for make, and finally build

linux_user@TN-201709F100R:~$ mkdir ~/xenomai_kernel_build/
linux_user@TN-201709F100R:~$ export INSTALL_MOD_PATH={Directory created above}
linux_user@TN-201709F100R:~$ export INSTALL_DTBS_PATH={Can be the same as the directory specified above}
linux_user@TN-201709F100R:~$ make –j□ zImage modules dtbs (Enter the number of cores you want to use in □)
linux_user@TN-201709F100R:~$ $ make –j□ modules_install 
linux_user@TN-201709F100R:~$ make –j□ dtbs_install(This will create a dtb file for configuration, but the one should be the same as the one generated by make zImage)

I don't think any current machine uses a CPU with 4 cores or less, so I think 4 is fine. If you can build successfully, execute the following

linux_user@TN-201709F100R:~$ mkdir $INSTALL_MOD_PATH/boot/
linux_user@TN-201709F100R:~$ ./scripts/mkknlimg ./arch/arm/boot/zImage $INSTALL_MOD_PATH/boot/kernel7.img

Now you have the Image files and the files needed to install the Kernel. It will be generated in $ INSTALL_MOD_PATH, so compress it and bring it to RPi via USB etc.

tar -zcvf kernel_pack.tgz $INSTALL_MOD_PATH

Below work with Paspberry Pi

Unzip the compressed file you brought to a suitable place. The RPi kernel can be recombined by building the source and replacing the generated Image file with the one already under / boot /. Be sure to back up all the files you want to replace before doing any further work </ font> If you do not do this, the worst RPi will never start again. (It doesn't actually start)

Backup work

linux_user@TN-201709F100R:~$ sudo mkdir /boot/boot_org/
linux_user@TN-201709F100R:~$ sudo cp  -rd /boot/* /boot/boot_org
linux_user@TN-201709F100R:~$ sudo cp –rd /lib/ /lib_backup/

Finally install the new kernel on RPi

linux_user@TN-201709F100R:~$ sudo cp {Unzipped$INSTALL_MOD_PATH}/kernel7.img /boot/
linux_user@TN-201709F100R:~$ sudo cp ./arch/arm/boot/dts/*.dtb /boot/
linux_user@TN-201709F100R:~$ sudo cp ./arch/arm/boot/dts/overlays/* /boot/overlays
linux_user@TN-201709F100R:~$ cd {Unzipped$INSTALL_MOD_PATH}
linux_user@TN-201709F100R:~$ cp –rd ./* /lib/

Then edit the boot config

linux_user@TN-201709F100R:~$ sudo vi /boot/config.txt

Added the following two lines

Kernel=kernel7.img
device_tree= bcm2710-rpi-3-b-plus.dtb

The newly added kernel will not be reflected until it is restarted, so execute the following before restarting to check the current kernel version (to check if the kernel is really replaced).

linux_user@TN-201709F100R:~$ uname -a
linux_user@TN-201709F100R:~$ Linux 4.19.xxx

After confirmation, restart RPi

linux_user@TN-201709F100R:~$ sudo reboot

After this, if it starts normally, start the terminal and check the kernel version

linux_user@TN-201709F100R:~$ uname -a
linux_user@TN-201709F100R:~$ Linux 4.19.yyy(The version of the kernel that was included in this work)

If it is, OK. This completes the Kernel construction for Xenomai for the time being. The articles I referred to in this work are as follows

References

https://lemariva.com/blog/2018/07/raspberry-pi-xenomai-patching-tutorial-for-kernel-4-14-y

Next is the build of Xenomai itself, but since it will be long, continue to Part 2.

Recommended Posts

Procedure for installing Xenomai on RaspberryPi 3 model B + Part 1
Step 2 to install Xenomai on RaspberryPi 3 model B +
[Go] Procedure for installing Go on WSL2
Procedure for manually installing Java (jdk1.8) on Linux (CentOS7)
Power on/off the USB port on the RaspberryPi 4 Model B
raspberry pi 1 model b, node-red part 17
Could not install python3.8.1 grovepi module on RaspberryPi Model 3B (solved)
Notes for installing Sublime Text on Ubuntu
[Note] Procedures for installing Ubuntu on Windows 10
Error reading SHT31-D value on RaspberryPi 3B +
The easiest procedure and explanation for installing Oracle Linux 8.3 (DB construction first part)
Retry to turn on/off the power of the USB port on RaspberryPi 4 Model B
Installing TensorFlow on Windows Easy for Python beginners