Tuesday, May 7, 2013

An RTEMS Application Framework - RKI

Building and Running an RTEMS Application


In the previous entries, I described how to set up an RTEMS development environment for the Raspberry Pi on an Ubuntu 12.10 system, build RTEMS, and run a sample program on the Pi. This entry will describe how to build and run a more complicated application.

RTEMS Kernel Image

The name of my application is called the RTEMS Kernel Image or RKI. You may have noticed that RTEMS is hard enough to set up a development environment. Unless you are using the examples that can be downloaded, it can be a bit more work to put together your first standalone RTEMS application. Other real time operating systems such as vxWorks have the tools to configure and create a base "kernel image" for your processor card. This RKI project is an attempt to provide a similar environment. If nothing else, it will provide an example of how to put together an RTEMS application that consists of multiple C files.


If you have the arm-rtems4.11 tools installed, and the Raspberry Pi RTEMS BSP compiled and installed on your development machine, then this next step is pretty simple.

1. Clone my RKI git repository:

$ git clone http://github.com/alanc98/rki.git

2. Switch to the rki/build-arm-rpi directory

$ cd rki/build-arm-rpi

3. Edit the Makefile and adust the environment

In this case, I am using the same directories we used in the tool setup.

Set the following variables in the makefile

## paths for the RTEMS tools and RTEMS BSP

4. Now, just build:

$ make

You will end up with a binary file called rki.bin. Copy that to your SD card as kernel.img and you are ready to try it out.

For more details, see the readme file in the project, and spend some time checking out how the application is put together.

github RKI site

Whats next?

Eventually, I would like to see full perpheral support for the Raspberry Pi. We still need to add support for things like:

  • SD Card support - Ability to mount, read, and write files

  • USB and Network support

  • HDMI Console Support

  • Some sort of Graphics support - Could RTEMS use the GPU?

In addition, RTEMS has a few things on the horizon including a dynamic loader and support for porting BSD drivers.


  1. Hi, Alan,
    great job, I downloaded and builded... all works properly.
    When I have a minute I try into the RasPi....
    and I will read in depth your code.
    Thank you again for share your experience.

  2. Thankyou. Nice Post. Works fine on pi+usb/serial cable. Are you still working on the "whats next"?

    1. Thanks! I have been too busy to make much progress on my next steps, but I have not given up yet. I did play around with some graphics demos and I was thinking about a framebuffer driver that would let me use the RTEMS graphics toolkit.

  3. Hello,

    I noticed a GSOC post on the RTEMS mailing list. I am not a a GSOC student but I actually am interested in learning about RTEMS. I was thinking about working on
    5. Graphics / RTEMS Framebuffer Support (I have a graphics demo working in an RTEMS task)
    6. USB Device support
    7. HDMI/Graphics console (Requires framebuffer support and USB or GPIO connected keyboard device)
    I have been through all the steps on your website and have the tests running on the Pi with no problems. I am currently familiarizing myself with the RTEMS code. I was hoping to use this project as a way to learn RTEMS. I don't want to be duplicating work though. Is it possible to work along side you or even take up the tasks listed.

    1. Sure! My original hope when I started this BSP was to get all of the devices working for the Raspberry Pi on RTEMS.

      We will know in about 1 week what the GSOC student(s) will try to accomplish, so we can go from there. In the meantime, I can give you some resources to look at for some of these devices. I took a graphics example written in assembly for the "Baking Pi" course and made it work in the RKI image.

    2. Great I have read that course but did not work through it. I will look a little closer at the RKI image as well. My e-mail is dennis.rondeau at gmail if you want to send me links to the resources.

  4. Hello,

    I have been working too in a framebuffer driver, in my case through the mailbox system of the R-Pi.
    The communication with the mailbox seems to be working fine but when a receive a pointer to the
    framebuffer and try to write on it RTEMS hangs. I've tried using modiications of this address, according
    to if it is absolute or mapped thorugh the MMU of the VideoCore without sucess. I suspect that
    RTEMS might be using that memory for something else.
    This is quite logical, since the VideoCore knows nothing about the operating system that is running
    on top. By the way: the pointer that the mailbox returns in my case as the start of the framebuffer is
    just 20 Kb after the start of the video memory, according to the mapping (memory partition between
    usual RAM and RAM for the VC set by the correspondign parameter in the config.txt file.
    My question is: is there any way to make RTEMS aware of this division so that it only uses the
    usual ram? Should some parameters in the ldconfig be changed to take this into account?
    If you want to see my code or know more about the use I intend to make (robot control), send me
    an email to tr3t11 at gmail dot com.

    Thank you very much for your excellent work,


  5. Hi Alan,

    will you please write the according RTEMS BSP, so that your work can be appreciated by the RTEMS community, too?

    1. Hi,
      I am not sure what you mean..
      There is a raspberry Pi RTEMS BSP available in the latest RTEMS git repository (4.11)


  6. Alan,

    This is great stuff, but there's no build-arm-rpi directory in rki. I'm trying to hack the Makefile that is in rki but at the moment I am stuck with this error:

    ~/development/rtems/rki$ make
    arm-rtems4.11-gcc -Wa,-a=legacy-build/arm-rtems4.11-raspberrypi/init.lis --pipe -BOME/development/rtems/bsps/4.11/arm-rtems4.11/raspberrypi/lib/arm-rtems4.11/raspberrypi/lib -specs bsp_specs -qrtems -Wall -I. -Iinclude/ -I. -g -O2 -c -o legacy-build/arm-rtems4.11-raspberrypi/init.o init.c
    arm-rtems4.11-gcc: error: bsp_specs: No such file or directory
    make: *** [init.o] Error 1

    1. I need to update this page.. The rki was updated to use the waf build system, but we left the legacy makefile place. The legacy makefile should still work as long as you edit the makefile for the correct location of the RTEMS BSP. In your line above the -BOME/development.. line looks like it is causing the problem.
      You should only have to change the RTEMS_TOOL_BASE and RTEMS_BSP_BASE variables. What are yours set to?


    2. RTEMS_TOOL_BASE = $HOME/development/rtems/compiler/4.11
      RTEMS_BSP_BASE = $HOME/development/rtems/bsps/4.11/arm-rtems4.11/raspberrypi/lib

      there is a bsp_specs file in the RTEMS_BSP_BASE directory (as defined above) that has this in it:

      %rename endfile old_endfile
      %rename startfile old_startfile
      %rename link old_link

      %{!qrtems: %(old_startfile)} \
      %{!nostdlib: %{qrtems: start.o%s crti.o%s crtbegin.o%s -e _start}}

      %{!qrtems: %(old_link)} %{qrtems: -dc -dp -N}

      %{!qrtems: *(old_endfiles)} %{qrtems: crtend.o%s crtn.o%s }

    3. I just changed it to this and appeared to have build rki.elf! :-) (tgross being my username)

      RTEMS_TOOL_BASE = /home/tgross/development/rtems/compiler/4.11
      RTEMS_BSP_BASE = /home/tgross/development/rtems/bsps/4.11

    4. it also built rki.bin which I copied to my boot directory as kernel.img and it works!

    5. This comment has been removed by the author.

    6. Matt -- Did you get the rki to build?
      I just updated an Ubuntu 16.04 VM with the latest 4.12 tools and RTEMS git head.
      The RKI project builds for raspberrypi and raspberrypi2 BSPs.
      You will have to use the "rki-drivers" branch of the RKI project, which only builds with waf now. Let me know if you need more help.
      I am thinking of creating a github based site with the directions so there is always one place to go for the latest info.

    7. Alan,

      I did get it to build. For rtems 4.12 it should be

      for some reason the compiler didnt like or couldnt link to the bspspec in the bsp/4.12 folder. after changing that path, it compiled and ran correctly. I am delving more in depth into rtems now as will be working on a port to a zynq once i am comfortable writing a more in depth application. I am sure i will be in touch

  7. Hi,

    I have been following this tutorial using a Raspberry Pi 2. The ticker example works great! However, the RKI example doesn't seem to work.

    Does the code need any further modifications to run on a Raspberry Pi 2 besides the obvious changes in the makefile?

    By the way, this is great work!

    1. Hi,
      I have tested it with the Raspberry Pi 2, and it seems to work.
      Let me re-test it with the RTEMS git head and make sure..

      I'm also going to submit a patch to enable hardware floating point on the Pi 2.

    2. Hi,

      I've just redone all the steps using the latest versions of RTEMS and RKI. Everything seems to work now.

      Thank you for the hardware floating point patch. Again, great work!

    3. Thanks! I'm glad it works for you now..
      I have some more improvements coming. I have a way of integrating device drivers into the RKI tree. You can develop and test I2C and SPI drivers for devices you wire up to the Pi. This makes it easier to build an application without trying to integrate all of the drivers into the RTEMS tree.

  8. Hello,
    I am following this tutorial for raspberry pi B+. I am able to run ticker program but unable to build rki.

    make gives error at this command:

    arm-rtems4.11-gcc -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -mtune=cortex-a7 --pipe -B/opt/rtems-4.11/arm-rtems4.11/raspberrypi/lib -specs bsp_specs -qrtems -Wall -o legacy-build/arm-rtems4.11-raspberrypi/rki.elf legacy-build/arm-rtems4.11-raspberrypi/init.o legacy-build/arm-rtems4.11-raspberrypi/rtems_net.o legacy-build/arm-rtems4.11-raspberrypi/rtems_net_svc.o legacy-build/arm-rtems4.11-raspberrypi/local_shell_cmds.o legacy-build/arm-rtems4.11-raspberrypi/filesys.o legacy-build/arm-rtems4.11-raspberrypi/ramdisk.o legacy-build/arm-rtems4.11-raspberrypi/nvramdisk.o legacy-build/arm-rtems4.11-raspberrypi/task_cmd.o legacy-build/arm-rtems4.11-raspberrypi/hello_cmd.o legacy-build/arm-rtems4.11-raspberrypi/dhrystone_cmd.o legacy-build/arm-rtems4.11-raspberrypi/whetstone_cmd.o legacy-build/arm-rtems4.11-raspberrypi/benchmarks.o legacy-build/arm-rtems4.11-raspberrypi/tarfile.o -lm

    some part of error from make command:
    /home/deval/development/rtems/4.11/lib/gcc/arm-rtems4.11/4.9.3/../../../../arm-rtems4.11/bin/ld: error: legacy-build/arm-rtems4.11-raspberrypi/rki.elf uses VFP register arguments, /opt/rtems-4.11/arm-rtems4.11/raspberrypi/lib/librtemscpu.a(libposix_a-pthreadkill.o) does not
    /home/deval/development/rtems/4.11/lib/gcc/arm-rtems4.11/4.9.3/../../../../arm-rtems4.11/bin/ld: failed to merge target specific data of file /opt/rtems-4.11/arm-rtems4.11/raspberrypi/lib/librtemscpu.a(libposix_a-pthreadkill.o)
    /home/deval/development/rtems/4.11/lib/gcc/arm-rtems4.11/4.9.3/../../../../arm-rtems4.11/bin/ld: error: legacy-build/arm-rtems4.11-raspberrypi/rki.elf uses VFP register arguments, /opt/rtems-4.11/arm-rtems4.11/raspberrypi/lib/librtemscpu.a(libposix_a-pthreadself.o) does not
    /home/deval/development/rtems/4.11/lib/gcc/arm-rtems4.11/4.9.3/../../../../arm-rtems4.11/bin/ld: failed to merge target specific data of file /opt/rtems-4.11/arm-rtems4.11/raspberrypi/lib/librtemscpu.a(libposix_a-pthreadself.o)
    legacy-build/arm-rtems4.11-raspberrypi/init.o:(.rodata+0x20): undefined reference to `_CPU_Thread_Idle_body'
    collect2: error: ld returned 1 exit status
    make: *** [rki.elf] Error 1

    1. Maybe you are using the raspberry pi1. In the Makefile at line 29, uncomment the line related to the pi1 and comment the following line related to the pi2. Uncomment also lines 42 and 52.

    2. I I'm trying to build rki but I've this error:

      ubuntu@ubuntu-VirtualBox:~/development/rki$ make
      arm-rtems4.11-gcc -Wa,-a=legacy-build/arm-rtems4.11-raspberrypi/init.lis -mcpu=arm1176jzf-s -D__ARM__ -Wall -I. -Iinclude/ -I. -g -O2 -c -o legacy-build/arm-rtems4.11-raspberrypi/init.o init.c
      init.c:23:24: fatal error: netinet/in.h: No such file or directory
      compilation terminated.
      make: *** [init.o] Errore 1

      Coul you, please, help me?

  9. I I'm trying to build rki but I've this error:

    ubuntu@ubuntu-VirtualBox:~/development/rki$ make
    arm-rtems4.11-gcc -Wa,-a=legacy-build/arm-rtems4.11-raspberrypi/init.lis -mcpu=arm1176jzf-s -D__ARM__ -Wall -I. -Iinclude/ -I. -g -O2 -c -o legacy-build/arm-rtems4.11-raspberrypi/init.o init.c
    init.c:23:24: fatal error: netinet/in.h: No such file or directory
    compilation terminated.
    make: *** [init.o] Errore 1

    Coul you, please, help me?

  10. Hi Alan, this is great work. I'm pretty interested in doing some SPI and network functionality so will touch base with you at some point about it.

  11. Is 'Rki' will update for master branc?