Sunday, May 9, 2010

Getting started with RTEMS

Here are some notes to help (anybody and me) getting started with RTEMS. In case you get stuck, the best place to ask for help would be the IRC - #rtems on freenode

Setting up the development environment.

The best start would be to see something working. This requires setting the development environment and running the "Hello World" application consequently.

To have a development environment up and running you would need
  • A development PC, running on Linux (preferably an RPM based system. Eg: Fedora)
  • Or you could use vmware [0] or virtualbox [1] with fedora from [2] or [3] on it
  • If you are comfortable with building tool chains from source, you could manage with Ubuntu (debian based) too.
  • Internet connectivity
I would best guide you to relevant links on the web and fill in the missing gaps, if any instead of putting down the whole thing here. (Documentation reuse, like code reuse :) )

1. Building the toolchain

If you are keen on working on Debian based systems, see [4]
If you are using rpm based systems, [5] (Damn easy, I tell you)
  • Get the file: rtems-X.XX-yum-conf-.YY.noarch.rpm (XX - RTEMS version, YY - OS version). Eg: I got the rpm at [6]
  • rpm -ivh above_file
  • Get the file : rtems-X.XX-release-.YY.noarch.rpm (XX - RTEMS version, YY - OS version). Eg: I got the rpm at [7]
  • rpm -ivh above_file
  • yum install rtems-4.9-auto*
  • yum install rtems-4.9-* ; Eg: yum install rtems-4.9-sparc* would install the required toolchain for i386 platform
With this, you are done with installing the toolchain required for a particular platform. With the above steps, the binaries were in /opt/rtems-4.10/bin/

  • extend the $PATH variable to include the path where all the rtems-specific compilers, gdbs and other binaries are present, which in this case would be /opt/rtems-4.10/bin

2. Getting RTEMS:
  • Have a look at [8]
  • Use cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS login ; which uses the required CVSROOT and tries to log you in. If prompted for a password, press return (no password)
  • Get rtems by issuing cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS -z 9 co -P rtems
  • To get a particular branch, use cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS -z 9 co -r rtems-x-y-branch rtems
Once the above steps are done and successful, you will have a directory in the location where you issued the check out command called rtems.

3. Building rtems:
  • Follow [9]
  • Heads up: One MUST build RTEMS for the same platform you got / built the toolchain for. Eg: Both RTEMS (below) and the toolchain have to be i386 specific or sparc specific or arm specific or
Some notes about the build steps:
  • I started with rtems-4.10 and it requires >autoconf-2.64. When I was building, Fedora had autoconf-2.63 and I had to get 2.64. So make sure you have 2.64
  • Firstly, while issuing the configure, you have to the target using --target=XXX, enable some corresponding BSP using --enable-rtemsbsp=YYY and the location where RTEMS needs to be installed using --prefix=. The XXX and YYY are best obtained from the README.configure in the rtems root directory
  • make
  • make install (might require su rights, depending on install path)
Eg: My configure looked like:
../configure --target=sparc-rtems4.10 --enable-rtemsbsp=sis --prefix=/opt/rtems-4.10/rtems/

Getting example applications:
  • You can get the example applications, by checking out the examples directory from CVS by cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS -z 9 co -P examples
Compiling applications:
  • Reference [10]
  • move to the directory hello_world_c
  • before you make, you need to set the RTEMS_MAKEFILE_PATH as per [10]
  • issue make there
Eg: With the above configuration, the RTEMS_MAKEFILE_PATH needs to be set to /opt/rtems-4.10/rtems/sparc-rtems4.10/sis/

Getting ready for the 1st run:

Of the several possible bsps/platforms, I am putting down two of them below which I have had tried: sparc and pc386

Lets start of with the easier one, which uses a simulator with gdb

1. sparc

  • make your that the $PATH variable now can reach the rtems-specific compilers, gdbs and other binaries
  • Run the sparc gdb: sparc-rtems4.10-gdb o-optimize/hello.exe
  • set target as simulator, load the program and run; tar sim; start; load o-optimize/hello.exe; start
  • You should now be seeing the output of hello.exe
So, what you did till now was running the test.c, compiled for sparc platform on a sparc simulator using the sparc specific gdb, that came along with the toolchain you installed

2. pc386 using qemu

  • Make sure you have build the rtems for i386 / pc386. Eg:
  • You now need qemu, a simulator, which simulates many platforms [11]. We will be using it to simulate the pc386 for us; yum install qemu should do the trick
  • Download the images [12] that qemu provides and test if the qemu installation works well
  • To quickly use and test qemu, [13]
  • Get the gcc-testing folder from the rtems site (CVS access): cvs -d :pserver:anoncvs@www.rtems.com:/usr1/CVS -z 9 co -P gcc-testing
  • Lets consider a folder (call it root)
  • Get the rtems-boot.img from [14] and rtems-grub.cfg from [15] and place it in this directory
  • Edit rtems-grub.cfg to have valid boot entries
  • Also place the executable build for pc386 in this directory
  • Invoke qemu while in this directory as qemu -boot a -fda rtems-boot.img -hda fat :. (boot from floppy(a), use current directory as hda, with these make sure your rtems-grub.cfg has the valid root as (hd0,0) and the valid path for the executables (hd0,0)/
Eg:
Have hello.exe you built for i386, rtems-boot.img and rtems-grub.cfg in a directory
rtems-grub.cfg would look like
set default=0

menuentry "RTEMS - Hello" {
set root=(hd0,0)
multiboot (hd0,0)/hello.exe
}
Use qemu -boot a -fda rtems-boot.img -hda fat:. and you should see the hello.exe output


3. An extension: Using gdb with qemu

Here is a small, but powerful extension to the above method (with qemu) where one can debug programs for pc386 using the i386-specific gdb

Reference: [17]
All the steps are the same as for the above method, except for the following:
  • Invoke qemu with the additional switch -s (meaning wait for a gdb connection on localhost:1234)
  • Invoke i386-rtems4.10-gdb
  • On gdb prompt, connect to remote target, as tar remote localhost:1234
  • On this one can put breakpoints, watch registers and all the other debugging possibilities
4. Using the gcc-testing rtems-testing module:

Another way to get things working is what I call "the easy Dr.Joel" way where all is ready, put things in place and bamm-you are good to go.

Reference: [16] - works like magic...!

Notes:

  • In the sim-scripts/pc386, you might want to change the shell you want to use. I had to change it to /bin/bash
  • Also, to see some "output" in front of your eyes, just change the way qemu is invoked to something similar to what was done in the previous method
Another method to see things running is using the qemu-nic in the qemu-support directory.
  • You need to have the ~/qemu and the pc386_fda in that directory. Also the ~/qemu/hd should be present
  • Copy the executable built for i386 into ~/qemu/hd as test.exe
  • In qemu-nic, change the QEMUDIR to $HOME
  • Invoke qemu-nic
  • You should now be seeing the output of hello.exe
Next up: Getting started with coverage

Links and references: Accessed on 9th May, 2010

[0] - http://www.vmware.com/
[1] - http://www.virtualbox.org/
[2] - http://www.thoughtpolice.co.uk/vmware/#fedora12
[3] - http://www.rtems.org/wiki/index.php/Virtual_Machines_for_RTEMS_Development
[4] - http://www.rtems.com/wiki/index.php/Building_the_RTEMS_toolset_on_Ubuntu
[5] - http://www.rtems.com/wiki/index.php/APT/Yum_Repository
[6] - http://www.rtems.org/ftp/pub/rtems/linux/4.10/fedora/12/i386/rtems-4.10-yum-conf-0.20100423.0-1.fc12.noarch.rpm
[7] - http://www.rtems.org/ftp/pub/rtems/linux/4.10/fedora/12/i386/rtems-4.10-release-0.20100423.0-1.fc12.noarch.rpm
[8] - http://www.rtems.com/wiki/index.php/RTEMS_CVS_Repository
[9] - http://www.rtems.org/wiki/index.php/Quick_Start
[10] - http://www.rtems.org/wiki/index.php/Example_Application_Compiling
[11] - http://wiki.qemu.org/Main_Page
[12] - http://wiki.qemu.org/Download#QEMU_disk_images
[13] - http://wiki.qemu.org/download/qemu-doc.html#pcsys_005fquickstart
[14] - http://www.rtems.org/ftp/pub/rtems/people/chrisj/grub/rtems-boot.img
[15] - http://www.rtems.org/ftp/pub/rtems/qemu/i386-pc/rtems-grub.cfg
[16] - http://www.rtems.com/wiki/index.php/QEMU#Using_the_gcc-testing_Module
[17] - http://www.rtems.com/wiki/index.php/QEMU#Debugging_with_QEMU

No comments:

Post a Comment