Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

xenomai是linux实时改造的重要方案之一,下面给出其具体的安装以及Ubuntu内核编译过程。
原理图如下
Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

1. 下载ubuntu内核以及xenomai3.1软件包

#开局先换源
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.9.38.tar.gz
wget https://xenomai.org/downloads/xenomai/stable/xenomai-3.1.tar.bz2

2. 压缩包解压,并复制到/usr/src

 sudo tar xf linux-4.9.38.tar.gz
 sudo tar xf xenomai-3.1.tar.bz2
 sudo cp -r linux-4.9.38  /usr/src
 sudo cp -r xenomai-3.1  /usr/src

3. 给ubuntu内核打上xenomai补丁,建立一个x86_64位内核

 cd linux-4.9.38
 
 sudo wget https://xenomai.org/downloads/ipipe/v4.x/x86/older/ipipe-core-4.9.38-x86-3.patch
 
 ../xenomai-3.1/scripts/prepare-kernel.sh --arch=x86_64 --ipipe=ipipe-core-4.9.38-x86-3.patch
 #File arch/x86/Kconfig is read-only;trying to patch anyway
 #checking file arch/x86/Kconfig
 #...
 #如出现上述报错,记得加sudo

4. 配置内核

sudo apt install gcc libc6-dev libncurses5-dev libssl-dev build-essential bison flex
#/bin/sh: 1: gcc: not found
#scripts/Makefile.host:107: recipe for target'scripts/basic/fixed' failed
#make[1]: *** [scripts/basic/fixed] Error 127
#Makefile:588: recipe for target 'menuconfig' failed
#make: *** [scripts_basic] Error 2
#如出现上述报错,在安装下面的关键库
#sudo apt install lib32stdc++6
#sudo apt install lib32z1
yes "" | make oldconfig
make menuconfig
#如还提示安装ncurses报错,加sudo
#进入menuconfig界面,会看影响xenomai实时性的警告信息:
#*** WARNING! Page migration (CONFIG_MIGRATION) may increase ***
#*** latency. ***
#*** WARNING! At least one of APM, CPU frequency scaling, ACPI ‘processor‘ ***
#*** or CPU idle features is enabled. Any of these options may ***
#*** cause troubles with Xenomai. You should disable them. ***

#具体配置如下所示:   

    * General setup

      --> Local version - append to kernel release: -xenomai-3.1

      --> Timers subsystem

          --> High Resolution Timer Support (Enable)

    * Xenomai/cobalt

      --> Sizes and static limits

        --> Number of registry slots (512 --> 4096)

        --> Size of system heap (Kb) (512 --> 4096)

        --> Size of private heap (Kb) (64 --> 256)

        --> Size of shared heap (Kb) (64 --> 256)

        --> Maximum number of POSIX timers per process (128 --> 512)

      --> Drivers

        --> RTnet

            --> RTnet, TCP/IP socket interface (Enable)

                --> Drivers

                    --> New intel(R) PRO/1000 PCIe (Enable)

                    --> Realtek 8169 (Enable)

                    --> Loopback (Enable)

            --> Add-Ons

                --> Real-Time Capturing Support (Enable)

    * Power management and ACPI options

      --> CPU Frequency scaling

          --> CPU Frequency scaling (Disable)

      --> ACPI (Advanced Configuration and Power Interface) Support

          --> Processor (Disable)

      --> CPU Idle

          --> CPU idle PM support (Disable)

    * Pocessor type and features

      --> Enable maximum number of SMP processors and NUMA nodes (Disable)

      // Ref : http://xenomai.org/pipermail/xenomai/2017-September/037718.html

      --> Processor family

          --> Core 2/newer Xeon (if "cat /proc/cpuinfo | grep family" returns 6, set as Generic otherwise)

      // Xenomai will issue a warning about CONFIG_MIGRATION, disable those in this orde

      --> Transparent Hugepage Support (Disable)

      --> Allow for memory compaction (Disable)

      --> Contiguous Memory Allocation (Disable)

      --> Allow for memory compaction

          --> Page Migration (Disable)

    * Device Drivers

      --> Staging drivers

          --> Unisys SPAR driver support

             --> Unisys visorbus driver (Disable)

配置完成后界面如下
Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

5. 进一步构建实时内核

sudo apt install kernel-package 

Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

6.编译内核

CONCURRENCY_LEVEL=$(nproc) make-kpkg --rootcmd fakeroot --initrd kernel_image kernel_headers

7.安装生成的系统文件

cd ..
sudo dpkg -i linux-headers-4.9.38-xenomai-3.1_4.9.38-xenomai-3.1-10.00.Custom_amd64.deb linux-image-4.9.38-xenomai-3.1_4.9.38-xenomai-3.1-10.00.Custom_amd64.deb
#我编译的放在文章最后

8. 允许非root用户

sudo addgroup xenomai --gid 1234
sudo addgroup root xenomai
sudo usermod -a -G xenomai $USER

9. 配置GRUB

sudo gedit  /etc/default/grub
#具体修改如下
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.9.38-xenomai-3.1"

#GRUB_DEFAULT=saved

#GRUB_SAVEDEFAULT=true

# Comment the following lines

#GRUB_HIDDEN_TIMEOUT=0

#GRUB_HIDDEN_TIMEOUT_QUIET=true

GRUB_TIMEOUT=5

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash xenomai.allowed_group=1234"

GRUB_CMDLINE_LINUX=""
#更新GRUB并重新启动
sudo update-grub
#重启电脑
sudo reboot
#重新开机后选择Ubuntu高级内核

Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

10. 安装xenomai用户空间库

uname -r
# 4.9.38-xenomai-3.1 
dmesg | grep Xenomai

Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)
Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)
虚拟机的话就是上面样子
电脑或者工控机是话就是下面样子

cd xenomai-3.1
./configure --with-pic --with-core=cobalt --enable-smp --disable-tls --enable-dlopen-libs --disable-clock-monotonic-raw
make -j`nproc`
sudo make install

11. 更新环境变量

echo '
### Xenomai
export XENOMAI_ROOT_DIR=/usr/xenomai
export XENOMAI_PATH=/usr/xenomai
export PATH=$PATH:$XENOMAI_PATH/bin:$XENOMAI_PATH/sbin
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$XENOMAI_PATH/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$XENOMAI_PATH/lib
export OROCOS_TARGET=xenomai
' >> ~/.xenomai_rc
echo 'source ~/.xenomai_rc' >> ~/.bashrc
source ~/.bashrc

12. 测试

#增加权限
sudo chmod -R 777 /dev/rtdm/memdev-private
sudo chmod -R 777 /dev/rtdm/memdev-shared
xeno latency
#或者
cd /usr/xenomai/bin
sudo ./latency

Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)

Ubuntu18.04+Xenomai3.1详细步骤(附内核deb文件)
上图为虚拟机,下图为工控机

#延迟为负数,修复方法
sudo -s
echo 0 > /proc/xenomai/latency
# Now run the latency test
# If the minimum latency value is positive,
# then get the lowest value from the latency test (ex: 0.088 us)
# and write it to the calibration file ( here you have to write 88 ns) :
echo my_super_value_in_ns > /proc/xenomai/latency

13. 最后附上我编译的内核包

链接:https://pan.baidu.com/s/1qVAoUttiPyqt9byUv58MQg
提取码:kntf
复制这段内容后打开百度网盘手机App,操作更方便哦

上一篇:浏览器不好使?那是你没装上这些插件


下一篇:百度网盘下载