Monday, March 8, 2010

QuickHowto: Building Real time Linux using RTAI


I have always been interested in Real-Time Kernels and O.S.es. I have started looking for Real time version of Linux almost immediately since I started working on Linux. There are multiple solutions out there to address the problem of making regular Linux-kernel into RTOS. While scanning through them I came acorss RTAI (Real Time Application Interface). This is Free, comes with good docmentation and RTAI addresses the problem neatly. Did I mention that RTAI is actively developed? Check out www.rtai.org

I have decided to build my own free usable realtime linux that could run on regular PC. This is what i did:

1) get the latest kernel image
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.tar.bz2

2) Download latest or one of the rtai package from www.rtai.org. My firefox firefox 3.6 didnt let me open this site.
So I tried in Firefox 2.0 and 2.0 complained about certificate but it let me open the page after i asked the browser to ignore.
I downloaded rtai-3.8.tar.gz

3) Now, untar the Linux kernel and rtai images. you will find directories linux-2.6.23/ and rtai-3.8/

4) Explore the direcotry rtai-3.8/ There are kernel patches for 2.6.20,2.6.22,2.6.23 under
rtai-3.8/base/arch/i386/patches

5)Patch the kernel.
$cd linux-2.6.23/ $patch -p1

Compile the Linux Kernel

6) Now, configure the kernel.
$ make menuconfig
Make sure the loadable kernel module is enabled.

7)compile the kernel with 'make' The linux kernel successfully compiles.

Compile RTAI - Kernel

8) inside rtai-3.8/ directory,
$make menuconfig
Under General -> Change the Linux directory and final installation directories to point to appropriate directories.
Under Machine (x86) -> make sure the number of CPUs in your machine is given correctly.
$ make
this will compile the RTAI referring your patched-kernel source.
$ make install

Testing
Now, you have RTAI as well as Linux kernel. You can either do "make install" the kernel. Or you can use test this realtime kernel with just initrd, which i will do next.
Create your own initrd image. I am going to just follow the steps explained my previous post. Basically, this should result in a system directory structre based on busybox. Create a linux system directory structure. additionally create realtime/ directory under usr/. Then Copy all realtime/ folder contents installed form previous step into it.
So your "root" directory structure should look something like this.

[root@sm initramfs-rtai3.8]# ls -lhrt
total 36K
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 sys
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 sbin
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 proc
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 newroot
-rw-r--r-- 1 root root 20 2010-03-08 17:31 initramfs.igz
-rwxr-xr-x 1 root root 1.2K 2010-03-08 17:31 init
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 etc
drwxr-xr-x 2 root root 4.0K 2010-03-08 17:31 bin
drwxr-xr-x 3 root root 4.0K 2010-03-08 17:31 usr

Then from inside your directory strcuture issue folllowing command

[root@sm initramfs-rtai3.8]# find . | cpio -H newc -o > ../initramfs.-rtai3.8.cpio
This creats your own initrd image. So, you have initrd , kernel are ready. Recollect that we have copied all "realtime" directory into initrd. Once these two are ready you can test it with qemu.

# qemu -kernel /mnt/lfs1/linux-2.6.23/arch/i386/boot/bzImage -initrd initramfs.-rtai3.8.cpio -append "root=/dev/ram" /dev/cdrom

This opens a new PC-emulator window and loads kernel and initrd image, runs the kernel.


Reference:
* This is a very good and latest tutorial on howto compile kernel. http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html
* A good Howto on howto create initramfs image is here. http://jootamam.net/howto-initramfs-image.htm It works for me.

1 comment:

  1. i am trying to use rtai with python have you some c, or python examples?

    ReplyDelete