1,下载ubuntu内核源码(https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.80/)和补丁
>cd ubuntu-kernel
>git clone git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack -b v4.9.80 v4.9.80
0001-base-packaging.patch
0002-UBUNTU-SAUCE-add-vmlinux.strip-to-BOOT_TARGETS1-on-p.patch
0003-UBUNTU-SAUCE-tools-hv-lsvmbus-add-manual-page.patch
0004-UBUNTU-SAUCE-no-up-disable-pie-when-gcc-has-it-enabl.patch
0005-dh_builddeb-switch-to-Zgzip-to-avoid-dpkg-bug-on-lar.patch
0006-debian-changelog.patch
0007-configs-based-on-Ubuntu-4.9.0-11.12.patch
和
linux-image-4.9.80-040980-generic_4.9.80-040980.201802031730_amd64.deb
和rtai-5.1(目前的最高版本)(https://www.rtai.org/)并解压
>tar Jxf rtai-5.1.tar.bz2
2,打补丁:
>cd v4.9.80
>patch -p1 < ../0001-base-packaging.patch
>patch -p1 < ../0002-UBUNTU-SAUCE-add-vmlinux.strip-to-BOOT_TARGETS1-on-p.patch
>patch -p1 < ../0003-UBUNTU-SAUCE-tools-hv-lsvmbus-add-manual-page.patch
>patch -p1 < ../0004-UBUNTU-SAUCE-no-up-disable-pie-when-gcc-has-it-enabl.patch
>patch -p1 < ../0005-dh_builddeb-switch-to-Zgzip-to-avoid-dpkg-bug-on-lar.patch
>patch -p1 < ../0006-debian-changelog.patch
>patch -p1 < ../0007-configs-based-on-Ubuntu-4.9.0-11.12.patch
>patch -p1 < ../rtai-5.1/base/arch/x86/patches/hal-linux-4.9.80-x86-4.patch
应该都能打成功
3,获得.config文件
>cd ../
>dpkg -x linux-image-4.9.80-040980-generic_4.9.80-040980.201802031730_amd64.deb ./configs
>cp ./configs/boot/config-4.9.80-040980-generic ./v4.9.80/.config
4,配置内核:
按照rtai-5.1/README.CONF_RMRKS文档内容要把CONFIG_AUDITSYSCALL改成no,但与v4.4.115内核不同的是v4.9.80中CONFIG_AUDITSYSCALL变量被改成无法修改了,所以要改动一下:
打开v4.9.80/init/Kconfig找到
config AUDITSYSCALL
def_bool y
depends on AUDIT && HAVE_ARCH_AUDITSYSCALL
这么几行,把它改成:
config AUDITSYSCALL
bool "Enable system-call auditing support"
depends on AUDIT && HAVE_ARCH_AUDITSYSCALL
default y if SECURITY_SELINUX
help
Enable low-overhead system-call auditing infrastructure that
can be used independently or with another kernel subsystem,
such as SELinux.
#config AUDITSYSCALL
# def_bool y
# depends on AUDIT && HAVE_ARCH_AUDITSYSCALL
然后再:
>cd v4.9.80
>make menuconfig
按以下修改内核配置参数(见:https://github.com/relacs/makertai)
Basic kernel configuration
For making the Linux kernel work with RTAI you should check the following settings in the kernel configuration dialog.
This list is updated for RTAI 5.1. For other RTAI versions read /usr/local/src/rtai/README.CONF_RMRKS !
"General setup":
1,Disable "Enable sytem-call auditing support" (AUDITSYSCALL)
2,Important: //这个重要:如果不改,安装rtai_sched.ko时会死机
set "Stack Protector buffer overflow detection" (at the bottom of the menu) to "Regular" (CC_STACKPROTECTOR_REGULAR)
- or even "None" (CC_STACKPROTECTOR_NONE) if the latency test crashes.
"Processor type and features"
1,(重要)把
[*] Enable Maximum number of SMP Processors and NUMA Nodes
--改成(否则内核启动不了)--
[ ] Enable Maximum number of SMP Processors and NUMA Nodes
(64) Maximum number of CPUs
"Power management and ACPI options":
1,In "ACPI (Advanced Configuration and Power Interface) Support":
Disable "Processor" (ACPI_PROCESSOR)
2,Disable "CPU Frequency scaling" (CPU_FREQ)
3,In "CPU Idle":
Disable "CPU idle PM support" (CPU_IDLE)
"Device Drivers":
1,In "Staging drivers":
Deselect "Data acquisition support (comedi)" (COMEDI)
"Kernel hacking":
1,In "Compile-time checks and compiler options":
Disable "Compile the kernel with debug info" (DEBUG_INFO) Disabling debugging information makes the kernel much smaller. So unless you know that you need it disable it.
2,Disable "Tracers" (FTRACE)
Leave the configuration dialog by pressing "Exit" until you are asked "Save kernel config?". Select "Yes".
Then the new kernel is being compiled - be patient.
5,编译:
>make -j8 LOCALVERSION=-rtai-5.1 deb-pkg
6,安装:
>cd ../
>sudo dpkg -i linux-headers-4.9.80-rtai-5.1+_4.9.80-rtai-5.1+-1_amd64.deb
>sudo dpkg -i linux-image-4.9.80-rtai-5.1+_4.9.80-rtai-5.1+-1_amd64.deb
>sudo reboot //启动新内核
一般都能成功启动新内核。
7,在新内核下编译rtai-5.1库和驱动
>cd ubuntu-kernel/rtai-5.1
>make menuconfig
-----------------------
General --->
(/opt/rtai-5.1_v4.9.80) Installation directory
(/usr/src/linux-headers-4.9.80-rtai-5.1+) Linux source tree
--------------------------------------------------------------
>make
>sudo make install
>cd /opt/rtai-5.1_v4.9.80/modules
>sudo insmod rtai_hal.ko
>sudo insmod rtai_sched.ko //如果到这儿没死机就说明rtai安装成功了
>sudo insmod rtai_fifos.ko
>sudo insmod rtai_sem.ko
>sudo insmod rtai_shm.ko
>sudo insmod rtai_rtdm.ko
1,配置文件:https://github.com/liuzq71/config_of_rtai5.1
2,https://github.com/liuzq71/v4.4.115-rtai5.1