Search:  
Gentoo Wiki

HOWTO_RTAI_and_COMEDI_on_2.6_Kernel

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

THESE INSTRUCTIONS DO NOT WORK. Most of the files, such as the 2.6.6 kernel, aren't even available from portage. However, all is not lost. These instructions still seem to be quite detailed and are a good starting block for a better understand of RTAI.

Introduction

So you want to setup a system using the COntrol and MEasurement DEvice Interface, and you want it to be real-time enabled. Where it comes to real-time kernels there are a few choices:

This HOWTO will cover the installation of RTAI only. I invite others to edit the document to include other Real-Time options.

Setup RTAI3.1-test3 on kernel 2.6.6

I chose to use development-sources-2.6.6-rc2, but any 2.6.6 kernel should work, use: emerge "=development-sources-2.6.6-rc2". I recommend finding a useable kernel configuration before applying the RTAI patch. Try rebooting in 2.6 a couple of times.

My setup was adding RTAI to the setup described in HOWTO Small Footprint Gentoo on USB, the hostname I was working on was scp. I found that this version of the kernel is unable to see the USB stick as a SCSI drive until after the first root mount. So I had to make an initrd:

mkinitrd -f --fstab=/etc/fstab --nopivot /boot/scp.initrd-2.6.6 2.6.6-rc2

Patching and Building a new kernel

I had a working 2.6.6 kernel, it was time to try and break it. I unpacked rtai-3.1-test3 to /usr/src. I made a copy of the 2.6.6-rc2 kernel source tree at /usr/src/linux-2.6.6-rtai and then added to it the patches provided by the rtai guys:

cd /usr/src/linux-2.6.6-rtai
patch -p1 < ../rtai-3.1-test3/rtai-core/arch/i386/patches/hal5-2.6.6.patch

and modified the makefile:

File: scp:/usr/src/linux-2.6.6-rtai/Makefile
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 6
EXTRAVERSION = -rtai
NAME=Zonked Quokka
...

The kernel needed to be reconfigured to get the rtai-patched kernel to boot. RTAI, requires that CONFIG_MODVERSIONS is disabled. To ensure that /dev/sda was present when the kernel tried to mount the rootfs - I had to set both SCSI Disks(sd_mod.o) and USB-Storage(usb-storage.o) to modules ('<M>') not built-in ('<*>'). Then I built a new kernel and initrd image.

cd /usr/src/linux-2.6.6-rtai
cp .config ..
make mrproper
cp ../.config .
make oldconfig
make && make modules_install
mount /boot
cp System.map /boot/scp.System.map-2.6.6-rtai
cp .config /boot/scp.config-2.6.6-rtai
cp arc/i386/boot/bzImage /boot/scp.kernel-2.6.6-rtai
mkinitrd --omit-raid-modules --omit-lvm-modules -f --fstab=/etc/fstab --nopivot \
 --preload=usb-storage --preload=sd_mod /boot/scp.initrd-2.6.6-rtai 2.6.6-rtai

Finally, I edited GRUB's menu.lst:

File: scp:/boot/grub/menu.lst
# Boot automatically after 30 secs.
timeout 5

# By default, boot the first entry.
default 0

# Fallback to the second entry.
fallback 1

splashimage=(hd0,0)/grub/splash.xpm.gz

title=SCP: RTAI+Development-2.6.6
root (hd0,0)
kernel /scp.kernel-2.6.6-rtai root=/dev/sda2 vga=791
initrd /scp.initrd-2.6.6-rtai

Building RTAI Kernel Modules and Userland

I made an ebuild to handle compiling and installing the RTAI kernel modules and userland stuff.

File: scp:/usr/local/portage/app-sci/rtai/rtai-3.1.ebuild
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit kernel-mod

DESCRIPTION="RTAI 3.1"

HOMEPAGE="http://www.aero.polimi.it/~rtai/index.html"
SRC_URI="http://www.aero.polimi.it/RTAI/rtai-3.1-test3.tar.bz2"
LICENSE="GPL-2"
SLOT="0"
RESTRICT="distcc"
KEYWORDS="~x86"
IUSE=""
DEPEND=""
S=${WORKDIR}/${P}-test3

src_compile() {
        cp ${FILESDIR}/.rtai_config .rtai_config
        make -j1 oldconfig ARCH="i386" || die
        addwrite /usr/src/linux
        emake -j1 || die "emake failed"
}

src_install() {
         kernel-mod_getversion
        make \
               prefix=${D}/usr/realtime \
               mandir=${D}/usr/share/man \
               infodir=${D}/usr/share/info \
               install || die

        #need to install .ko's into /lib/modules/... not /usr/realtime/modules/...
        pushd ${D}/usr/realtime/modules/
        dodir /lib/modules/${KV_VERSION_FULL}/rtai
        insinto /lib/modules/${KV_VERSION_FULL}/rtai
        insopts -m0644
        doins *.ko
        popd

        #need to install lib's into /lib, not /usr/realtime/lib
        pushd   ${D}/usr/realtime/lib/
        dolib.a *.a
        dolib.so *.so *.la
        popd
}

The ebuild above depends on .rtai_config, which I produced by using make menuconfig in /var/tmp/portage/rtai-3.1/work/rtai-3.1-test3/ after executing ebuild rtai-3.1.ebuild unpack. Once created, the file should be copied to /usr/local/portage/app-sci/rtai/files/ for the compile and install stages.

File: scp:/usr/local/portage/app-sci/rtai/files/.rtai_config
#
# Automatically generated make config: don't edit
#
CONFIG_MODULES=y
CONFIG_RTAI_VERSION="3.1-test3 (vesuvio)"

#
# General
#
CONFIG_RTAI_INSTALLDIR="/usr/realtime"
CONFIG_RTAI_LINUXDIR="/usr/src/linux"

#
# RTAI Documentation
#
# CONFIG_RTAI_DOX_DOC is not set
# CONFIG_RTAI_LATEX_DOC is not set
# CONFIG_RTAI_DBX_DOC is not set
CONFIG_RTAI_TESTSUITE=y
# CONFIG_RTAI_COMPAT is not set
# CONFIG_RTAI_EXTENDED is not set

#
# Machine (x86)
#
CONFIG_RTAI_FPU_SUPPORT=y
CONFIG_RTAI_CPUS="1"

#
# Core system
#

#
# Native RTAI schedulers
#
CONFIG_RTAI_SCHED_UP=y
# CONFIG_RTAI_SCHED_SMP is not set
# CONFIG_RTAI_SCHED_MUP is not set
CONFIG_RTAI_SCHED_LXRT=y

#
# IPC support
#
CONFIG_RTAI_BITS=m
CONFIG_RTAI_FIFOS=m
CONFIG_RTAI_NETRPC=m
CONFIG_RTAI_NETRPC_RTNET=y
CONFIG_RTAI_SHM=m
CONFIG_RTAI_SEM=m
CONFIG_RTAI_MSG=m
CONFIG_RTAI_MBX=m
CONFIG_RTAI_TBX=m
CONFIG_RTAI_MQ=m

#
# Other features
#
CONFIG_RTAI_MATH=y
# CONFIG_RTAI_MATH_C99 is not set
CONFIG_RTAI_MALLOC=y
CONFIG_RTAI_TASKLETS=m
# CONFIG_RTAI_TRACE is not set
CONFIG_RTAI_USI=m
CONFIG_RTAI_WD=y
CONFIG_RTAI_LEDS=m

#
# Xenomai sub-system
#
# CONFIG_RTAI_XENOMAI is not set

#
# Add-ons
#
# CONFIG_RTAI_COMEDI_LXRT is not set
# CONFIG_RTAI_CPLUSPLUS is not set
# CONFIG_RTAI_SERIAL is not set

#
# RTAI Lab
#
# CONFIG_RTAI_LAB is not set

#
# RTAI Simulator
#
# CONFIG_RTAI_MVM is not set

Then I added a line to /etc/portage/package.keywords

File: /etc/portage/package.keywords
...
 =app-sci/rtai-3.1 ~x86
...

and issued the command: emerge -av rtai, emerge indicated it would merge the ebuild located in /usr/local/portage, so I said yes.

Finally I checked that modules had all the right symbols with depmod -a 2.6.6-rtai

Setup COMEDI-CVS

Comedi (Kernel Drivers)

I was unable to use comedi-0.7.68 on kernel 2.6.6, as the makefiles are not configured to use this kernel version. So I created a 'live' cvs ebuild:

File: /usr/local/portage/app-misc/comedi/comedi-0.7.69.ebuild
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-misc/comedi/comedi-0.7.69.ebuild,v 1.3 2004/06/24 21:56:04 agriffis Exp $

ECVS_SERVER="cvs.comedi.org:/cvs/comedi"
ECVS_MODULE="comedi"
inherit cvs kernel-mod

IUSE="python doc"
HOMEPAGE="http://www.comedi.org"
KEYWORDS="x86"
LICENSE="LGPL-2.1"
SLOT="0"

DEPEND="python? ( dev-lang/python )
        doc? ( app-text/docbook2X )"

S="${WORKDIR}/${PN}"


SRC_URI=""
src_unpack()
{
        cvs_src_unpack
}

src_compile()
{
        ./autogen.sh

        kernel-mod_getversion

        addpredict ${KERNEL_DIR}

        LOCALARCH=$(uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
                -e s/arm.*/arm/ -e s/sa110/arm/ \
                -e s/s390x/s390/ -e s/parisc64/parisc/ )

        #KV_VERSION_FULL=$(echo ${KERNEL_DIR}|rev|cut -f 2 -d '/'|rev)

        ARCH=${LOCALARCH} ./configure \
                --prefix=${D}/usr \
                --libdir=${D}/lib \
                --with-modulesdir=${D}/lib/modules/${KV_VERSION_FULL}\
                --with-linuxdir=${KERNEL_DIR}   || die
        emake -j1 || die
}

src_install()
{
        make \
                prefix=${D}/usr \
                mandir=${D}/usr/share/man \
                infodir=${D}/usr/share/info \
                DEPMOD=/bin/true \
                install || die
}


After run this command to create Manifest file : ebuild /usr/local/portage/app-misc/comedi/comedi-0.7.69.ebuild digest

Then I added a line to /etc/portage/package.keywords:

File: /etc/portage/package.keywords
...
=app-misc/comedi-0.7.69 ~x86
...

I was able to install the cvs version of comedi using only the command: emerge -av comedi.

Since it was the first build of comedi, I needed to create the device files, and assign a device to a driver. I used #ebuild /usr/local/portage/app-misc/comedi/comedi-0.7.69.ebuild unpack to get the sources in /var/tmp/portage/comedi-0.7.69/work/comedi/. From that directory I issued the commands

make dev
comedi_config /dev/comedi0 ni_pcidio

I added a line to /etc/conf.d/local.start:

File: /etc/conf.d/local.start
...
comedi_config /dev/comedi0 ni_pcidio
...

I also added a line to /etc/modules.autload.d/kernel-2.6

File: /etc/modules.autoload.d/kernel-2.6
...
ni_pcidio
...

this way everytime the system boots, all the neccessary modules for operation are loaded.

Comedilib

The newer version of comedi required a matching version of comedilib, so I created a second 'live' cvs ebuild:

File: /usr/local/portage/app-misc/comedilib/comedilib-0.7.22.ebuild
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-misc/comedilib/comedilib-0.7.22.ebuild,v 1.3 2004/06/24 21:56:04 agriffis Exp $

ECVS_SERVER="cvs.comedi.org:/cvs/comedi"
ECVS_MODULE="comedilib"
inherit cvs

IUSE="python doc"
HOMEPAGE="http://www.comedi.org"
KEYWORDS="x86"
LICENSE="LGPL-2.1"
SLOT="0"

DEPEND=">=app-sci/comedi-0.7.63
        python? ( dev-lang/python )
        doc? ( app-text/docbook2X )"

S="${WORKDIR}/${PN}"

src_compile()
{
        ./autogen.sh
        ./configure --prefix=${D}/usr --localstatedir=${D}/var
        make
}

src_install()
{
        make install
        keepdir /var/calibrations
	dosym ${D}/usr/lib/libcomedi.so ${D}/usr/lib/libcomedi.so.0
}

After run this command to create Manifest file : ebuild /usr/local/portage/app-misc/comedilib/comedilib-0.7.22.ebuild digest


Once again, I added a line to /etc/portage/package.keywords:

File: /etc/portage/package.keywords
...
=app-misc/comedilib-0.7.22 ~x86
...

Then I issued the command: emerge -av comedilib.

See Also

Retrieved from "http://www.gentoo-wiki.info/HOWTO_RTAI_and_COMEDI_on_2.6_Kernel"

Last modified: Sun, 07 May 2006 21:52:00 +0000 Hits: 22,255