Setting up RTEMS – Part 2: Hello World

We now have the RTEMS toolchain and a local checkout up to date on the system.  Now we must build a BSP that targets some specific architecture.  The getting starting docs recommend starting with sparc-sis, so that’s what we are going to do.  A much more concise wiki page focusing on Fedora Core 12 on Virtual Box has been put together, so I recommend for those following along at home they start there.

Change into the top of your build directory:

cd $B

This directory isn’t under version control, but all the subdirectories are checkouts from the official CVS repository.  Now that we have RTEMS configured for our host machine (Fedora Core 12 on x86) we can build different BSPs by configuring them out of directory. Most unix/linux users will be familiar with the regular incantation of “./configure && make && make install” that result in the configuration and building and installation of a program from source.  RTEMS (and, from what I understand from the docs, most cross-compilation) can be configured and built from outside the source tree.  This allows us to configure RTEMS once and then have a separate build for each different BSPs.

Let’s build the sparc-sis BSP.  First, create a folder to hold all the cross-compiled goodness:

mkdir b-sis
cd b-sis

Now configure RTEMS to build a sparc-sis-esque setup:

../rtems/configure --target=sparc-rtems4.10 --enable-rtemsbsp=sis --enable-tests=samples --disable-posix --disable-itron

and then build it

make

and then install it

su
make install

The “su” may be unnecessary but you may run into permission errors so it’s a safe bet.

You have now installed the sparc-sis on your system. We need to set one environment variable to tell the make processes which BSP to build for.  This environment variable allows you to have multiple BSPs installed at once and easily switch building targets on the fly.  So make sure you are in the “b-sis” directory:

cd $B/b-sis

And then search for the Makefile.inc file:

find . -name Makefile.inc

This should return the location of the Makefile.inc relative to your path.  I got the following:

./sparc-rtems4.10/c/sis/make/Makefile.inc

To find out your current directory, use

pwd

My system is setup (the virtual box development image provided by RTEMS) so I am currently at

/home/rtems/rtems-4.10-work/b-sis

Putting those two together the absolute path of the Makefile.inc (for sparc-sis) is:

/home/rtems/rtems-4.10-work/b-sis/sparc-rtems4.10/c/sis/make/Makefile.inc

We now need to set the environment variable $RTEMS_MAKEFILE_PATH.  Assuming your shell is bash or some slightly compatible variant, environment variables start with a dollar sign ($) and one word (including underscores) in all caps.  Go ahead and edit your .bash_profile to set this variable:

RTEMS_MAKEFILE_PATH=/home/rtems/rtems-4.10-work/b-sis/sparc-rtems4.10/c/sis/make
export RTEMS_MAKEFILE_PATH

There is perhaps a better place to put this, but .bash_profile will work.  Your .bash_profile is located in your home directory (which you can get to by typing “cd ~”) and is run every time a terminal is open, ensuring that this variable is present.  Note that we pointed to the directory where the Makefile.inc is located, not to the Makefile.inc itself.

Now, let’s build some examples.  Go to the examples provided:

cd $B/examples-v2

And marvel at all the examples that have been provided.  You can run “make” from this directory but since we are on sparc-sis and explicitly disabled POSIX some of the examples will not build.  So let’s go and build the hello world example:

cd hello/hello_world_c
make

If you see an error about not being able to find some .cfg or Makefile.inc, you’ve set your path incorrectly.  If you see the error that it can’t find /Makefile.inc, then your environment variable isn’t set at all.  Try “echo $RTEMS_MAKEFILE_PATH” to see what the variable is currently set as.  If it’s in your .bash_profile but not showing, you need to reload your .bash_profile by running “. ~/.bash_profile”.  Try the echo again and hopefully you will see the environment variable set.

Assuming it all went well at this point, you can load up the executable in GDB.  If you don’t know much about GDB,  you should go and read up about how to use it. Fire up the RTEMS sparc GDB:

sparc-rtems4.10-gdb o-optimize/hello.exe

You should be greeted with the RTEMS GDB built for sparc. You’ll need three commands to execute the program:

tar sim
load
r

The first command “tar sim” targets the simulator for sparc.  (See “help targets” for more information and options.) The second loads the program.  The third “r” is short for “run”.  You should see the basic “Hello World” program.

Let’s edit the program to do something slightly more interesting and prove that our build environment is mostly sane.  Go ahead and edit test.c:

gvim test.c

And add a few lines to change what is being printed out.  Run “make” again to rebuild the executable.  Now fire up GDB as before and make sure the output has changed.  You can see my diff and my results below:

Posted in Google Summer of Code | Comments Off on Setting up RTEMS – Part 2: Hello World

Comments are closed.