Problem
The rtai package in Ubuntu 9.10 doesn’t contain a patch for the latest Ubuntu kernel, so a kernel with RTAI support can’t easily be compiled with standard packages.
A solution
Compile a custom kernel image package using vanilla sources and patches from a CVS snapshot of RTAI.
Required packages
I think the packages kernel-package and cvs are enough.
# aptitude install kernel-package cvs
The kernel
Browse the RTAI CVS repository. Right now, the latest version is called vulcano. The kernel patches are located in vulcano/base/arch/x86/patches. My current Ubuntu kernel version was 2.6.31-19-generic, so I chose the patch named hal-linux-2.6.31.8-x86-2.4-09.patch, which is for the kernel version 2.6.31.8. Since the versions are almost the same, it will be easier to use the old Ubuntu kernel configuration.
The next step is to download and extract the vanilla kernel sources in /usr/src. Finally add a symlink which points to the kernel sources.
# cd /usr/src
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.8.tar.bz2
# tar xvjf linux-2.6.31.8.tar.bz2
# ln -s linux-2.6.31.8 linux
To get the required patch, checkout the latest CVS sources.
# cvs -d:pserver:anonymous@cvs.gna.org:/cvs/rtai co vulcano (latest stable version)
Next, patch the kernel sources with the correct patch.
# cd /usr/src/linux-2.6.31.8
# patch -p1 -b < ../vulcano/base/arch/x86/patches/hal-linux-2.6.31.8-x86-2.4-09.patch
It’s time to build the kernel. It will be built as an Ubuntu kernel image, which means it will be added automatically to the boot loader upon installation and fits nicely into the existing structure.
The current kernel configuration is copied from /boot.
# make-kpkg clean
# cp /boot/config-2.6.31-19-generic .config
# make oldconfig
Reply to the questions which pop up (about Interrupt Pipelines, for example). Just press ENTER for defaults if you aren’t sure about a question.
There are a few things left to configure, at least I had to configure them to get rid of some error messages.
Problem: include/linux/ipipe.h:76:2: error: #error “CONFIG_NR_CPUS is too large, please lower it.”
Solution: Disable “Support sparse irq numbering” (SPARSE_IRQ=n)
Problem: ipipe.c prints an error message about per_cpu__irq_state_union being undefined
Solution: Disable “Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)” (CC_STACKPROTECTOR=n)
Problem: The RTAI docs say that module versioning support should be disabled.
Solution: Disable “Module versioning support” (CONFIG_MODVERSION=n)
Now, build the kernel! You might as well build the headers at the same time.
# fakeroot make-kpkg --initrd kernel_image kernel_headers
Go do something else while the kernel compiles if your computer is slow.
When it’s done, it’s time to install the new kernel. The new .deb-files have been placed in /usr/src.
# cd /usr/src
# dpkg -i linux-image-2.6.31.8_2.6.31.8-10.00.Custom_i386.deb linux-headers-2.6.31.8_2.6.31.8-10.00.Custom_i386.deb
Now, reboot the computer to see if your new kernel works. It should, but if it doesn’t, choose an older kernel in the boot loader to get back into your system.
RTAI
When the patched kernel is up and running, it’s time to compile RTAI itself and install it. The default options in the configuration should be fine, but change them if you want a certain feature. Note that the default setting for the kernel source location is /usr/src/linux, which our symlink takes care of.
# cd /usr/src/vulcano
# make menuconfig
# make
# make install
Note: The RTAI documentation tells you to have a separate build directory, but when I tried that I got the following error messages:
Makefile:303: ../vulcano/scripts/Kbuild.include: No such file or directory
Makefile:527: ../vulcano/arch/x86/Makefile: No such file or directory
When I did everything in the source directory as above, the error messages never appeared.
After the installation
Enter your new RTAI directory.
# cd /usr/realtime/
You’ll find the RTAI modules in modules/ and some tests to run in testsuite/.
Remember, load rtai_lxrt.ko for ‘user’ tests and rtai_sched for ‘kern’ tests.
Good luck!