ubuntu 16.04 安装rtai实时内核教程

date_range 2019-03-12 14:20:36 access_time 2-minute read

直接切换到root权限吧

sudo -i

安装编译依赖包

apt install libncurses5-dev libssl-dev libelf-dev dpkg-dev bc 

进入到某个目录,这里以/usr/src为例

cd /usr/src

下载最新rtai包并解压并软链

wget https://www.rtai.org/userfiles/downloads/RTAI/rtai-5.1.tar.bz2
tar -xf rtai-5.1.tar.bz2
ln -s /usr/src/rtai-5.1 /usr/src/rtai

这里使用4.4的内核,查看rtai对应4.4内核用的版本是多少

ls /usr/src/rtai/base/arch/x86/patches/ | grep "4.4"
hal-linux-4.4.115-x86-10.patch

结果是4.4.115,去linux内核官网下载对应该版本的内核源码并解包加软链

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.4.115.tar.gz
tar zxvf linux-4.4.115.tar.gz 
ln -s /usr/src/linux-4.4.115 /usr/src/linux

下载ubuntu 官方已经编译好的ubuntu-image包并解包,主要是用到里面的.config内核配置文件

wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4.115/linux-image-4.4.115-0404115-generic_4.4.115-0404115.201802031230_amd64.deb
dpkg-deb -x linux-image-4.4.115-0404115-generic_4.4.115-0404115.201802031230_amd64.deb linux-image-4.4.115

进入内核源码目录,复制ubuntu官方的编译好内核镜像的配置文件

cd /usr/src/linux
cp /usr/src/linux-image-4.4.115/boot/config-4.4.115-0404115-generic /usr/src/linux/.config

打入rtai补丁包

patch -p1 < /usr/src/rtai/base/arch/x86/patches/hal-linux-4.4.115-x86-10.patch

等待补丁包打包完成,执行内核编译配置

make menuconfig

在内核配置参数中修改如下选项:

  1. General setup
    1. Stack Protector buffer overflow detection 
      Set to none.
  2. Processor type and features
    1. Symmetric multi-processing support 
      include.
    2. Preemption Model: Preemptible Kernel (Low-Latency Desktop)
    3. Processor family 
      Select processor family. If you are not sure, select “Pentium Pro” for 32bit or “Generic x86_64” for 64bit.
    4. Enable maximum number of SMP processors and NUMA nodes 
      exclude.
    5. Maximum number of CPU’s 
      Select the number of CPU cores. You can check the details in the system settings.
    6. SMT (Hyperthreading) scheduler support 
      exclude.
  3. Power management and ACPI options 
    Exclude what can be done except “ACPI”.
    1. ACPI 
      Exclude except Power Management Timer Support and button.
    2. CPU Frequency scaling 
      exclude.
    3. CPU idle Exclude 
      “CPU idle PM support”.

保存编译参数退出

手动修改.config

vim .config
CONFIG_DEBUG_INFO=y
改为:
CONFIG_DEBUG_INFO=n

开始编译打包内核

make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-rtai 

安装内核包

cd ../
dpkg -i linux-image-4.4.115-rtai_4.4.115-rtai-2_amd64.deb
dpkg -i linux-headers-4.4.115-rtai_4.4.115-rtai-2_amd64.deb

安装成功后重启系统,选择xxx进入,测试是否成功

uname -r

应该会显示: 4.4.115-rtai

修改grub配置文件

vim /etc/default/grub
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.4.115-rtai"
#GURB_HIDDEN_TIMEOUT=0
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash lapic=notscdeadline"
GRUB_TIMEOUT="2"

update-grub

重启确认

编译rtai modules

sudo -i
cd /usr/src/rtai
make menuconfig

不做任何修改,保存并退出,开始编译

make -j `getconf _NPROCESSORS_ONLN`

安装

make install

新增环境系统变量

vim /etc/profile.d/rtai.sh
export PATH=/usr/realtime/bin:$PATH 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/realtime/lib
vim /etc/ld.so.conf.d/rtai.conf
/usr/realtime/lib
ldconfig

latency test

cd /usr/realtime/testsuite/kern/latency 
./run

问题解决:

  1. 入发现启动后进入实时内核无法正确运行上一步的run脚本,使用dmesg 命令查看系统日志如发现该错误,需要在编辑rtai模块执行make menuconfig 时配置里面的Number of CPUs (SMP-only)  为当前运行该系统机器的正确cpu核心数,否则会运行不起来
    [ 169.915294] rtai_hal: loading out-of-tree module taints kernel.
    [ 169.915542] rtai_hal: module verification failed: signature and/or required key missing - tainting kernel
    [ 169.917652] RTAI[hal]: RTAI CONFIGURED WITH LESS THAN NUM ONLINE CPUS.

参考资料:

  1. RTAI on Ubuntu 16.04
  2. RTAI installation for Ubuntu 14.04

comments

comments powered by Disqus