1. 程式人生 > >ubuntu核心編譯及RTAI的安裝

ubuntu核心編譯及RTAI的安裝

準備工作

apt-get install qt3-apps-dev build-essential kernel-package vim

apt-get install libncurses5-dev  (meke menuconfig要呼叫的)


Step1 下載原始碼並解壓到/usr/src目錄下

Get the kernel source (version 2.6.32-21.32) from Ubuntu repository

# apt-get install linux-source-2.6.32=2.6.32-21.32
# wget https://www.rtai.org/RTAI/rtai-3.8.tar.bz2
# tar xjvf linux-source-2.6.32.tar.bz2
# tar xjvf rtai-3.8.tar.bz2
# ln -s linux-source-2.6.32 linux
# cd linux 

(實際上我使用的是2.6.35的核心+rtai-3.9) 

Step2 打patch

# patch –p1 –b< ../rtai-3.9/base/arch/x86/patches/hal-linux-2.6.35.9-x86-2.8-04.patch

Step3 配置

# make menuconfig

Code maturity level options-> 不選
General Setup->
Support for paging of anonymous memory(swap)選
System V IPC選
BSD Process Accounting選
Loadable Module Support ->
選上Automatic kernel module loading
Processor type and features->
選上Math emulation
去掉Use register arguments
選上Compact VDSO support
Power management options->
Button改成M
Fan改成M
Processor改成M
Thermal Zone改成M
Kernel Hacking –>
去掉Compile the kernel with frame pointers

Step4  編譯核心

完成後,先去配置/usr/src/linux-source-2.6.32/linux-source-2.6.35/ubuntu/omnibook /Makefile檔案。
   不然會出現ld: /ubuntu/omnibook/sections.lds: No such file: No such file or directory錯誤
    在根使用者下開啟該Makefile檔案,將其中的PWD=$(shell pwd)剪下到ifeq ($(KERNELRELEASE),) 前面。然後儲存。

If you are using an older RTAI patch you may get the following error: include/linux/ipipe.h:76:2: error: #error "CONFIG_NR_CPUS is too large, please lower it."To fix this disable sparse irq numbering (CONFIG_SPARSE_IRQ=n):Processor type and features ---> Support sparse irq numbering ---> disabled

方法一:手動編譯並安裝

make clean

make -j4  (-j4是讓處理器分成四個執行緒來編譯核心,速度快,推薦CPU好的使用)

make modules_install

make install

生成initrd並修改grub相關檔案

# mkinitramfs -o ...

# update-grub

# vi /boot/grub/grub.cfg

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.35.4+rtaitestwensitest' --class ubuntu --class gnu-linux --class gnu --class os {
 recordfail
 insmod part_msdos
 insmod ext2
 set root='(hd0,msdos1)'
 search --no-floppy --fs-uuid --set e900ef3d-fe04-413b-aaa1-54b61c68430b
 linux /boot/vmlinuz-2.6.35.4+rtaitestwensitest root=UUID=e900ef3d-fe04-413b-aaa1-54b61c68430b ro   quiet splash
 initrd /boot/initrd.img-2.6.35.4+rtaitestwensitest
}
menuentry 'Ubuntu, with Linux 2.6.35.4+rtaitestwensitest (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
 recordfail
 insmod part_msdos
 insmod ext2
 set root='(hd0,msdos1)'
 search --no-floppy --fs-uuid --set e900ef3d-fe04-413b-aaa1-54b61c68430b
 echo 'Loading Linux 2.6.35.4+rtaitestwensitest ...'
 linux /boot/vmlinuz-2.6.35.4+rtaitestwensitest root=UUID=e900ef3d-fe04-413b-aaa1-54b61c68430b ro single
 echo 'Loading initial ramdisk ...'
 initrd /boot/initrd.img-2.6.35.4+rtaitestwensitest
}

方法二:使用ubuntu自帶的工具

make-kpkg clean

make-kpkg --initrd --append_to_version rati39 kernel_image kernel_headers

其中--initrd必需要,不然生成不了initrd檔案

--append生成多重映象,也就是在啟動選單裡看到的選項

rati39是你自己取的映象的名字,必須以數字結尾,映象名字不能大寫。

編號核心後,就會顯示linux-2.6.20.1rati39最後兩項是生成映象包和標頭檔案包

make完之後,會在上一層目錄看到兩個deb包

dpkg –i *.deb


可以去/boot目錄下看看Vmlinuz、initrd、System.map檔案是否都在

最後,reboot

=================================================================================================

RTAI安裝
# cd /usr/src/rtai-3.9

# make menuconfig

# make && make install

新增modprobe支援

# mkdir /lib/modules/2.6.32.11+drm33.2.openairinterface/rtai 
# cp -r /usr/realtime/modules/* /lib/modules/2.6.32.11+drm33.2.openairinterface/rtai/ 
# depmod -a 
# export PATH=/usr/realtime/bin:$PATH

Add the following lines at the end of /etc/modules (this loads the rtai modules needed by openair) :
rtai_smi
rtai_fifos
rtai_sem
rtai_math
rtai_sched
rtai_hal
In order to execute it at each terminal launch :

# vim /root/.bashrc 
Add what follows, to the end of the file
# export PATH=/usr/realtime/bin:$PATH 

測試

# cd /usr/realtime/testsuite/kern/latency

# ./run