Overview

The classic way of building RTEMS is to start by building your own tool chain for the specific target architecture for which you wish to build your RTEMS kernel for. This can be a tedious process as there are an abundance of little “gotcha’s” that lead to many failed compiles and hurt feelings.

The simplest way to build RTEMS is with the pre-built tool chains available on the rtems website. They are only available in .rpm format, and require the yum package manager for the easy – easy way of getting RTEMS compiled.

The website does have existing instructions on getting these pre-built tool chains setup, but I found them to be incomplete and confusing. So here is a guide to augment those instructions.

General vs. Example

For the sake of clarity, I’ll be showing general commands in normal code font and example commands in red code font . Since there are many different environments and build targets, the general case will be sort of “fill in the blank”, while following the examples in red will get to a working i386 RTEMS kernel.

Downloading Things

For the example build, I’ll be using i386 RTEMS 4.9.2 and the Fedora 12 32-bit O.S. If you aren’t using either Fedora, CentOS, RedHat, or Suse, these instructions are probably useless to you. You’ll need to either build the toolchain by hand or start using one of the supported operating systems.

*One important thing to note about the RTEMS naming convention is that the toolchain drops the last digit of the version number of the RTEMS version you want to build. For example, if you’re building RTEMS 4.9.2, you use the 4.9 toolchain.

Download

Go to www.rtems.org/ftp/pub/rtems/linux/ and click through the links until you’ve found the page listing rpm packages relevant to your OS and desired RTEMS version. There will be an .rpm (probably at the bottom) in the form:
rtems-BRANCH-yum-conf-VERSION-DISTRO.noarch.rpm
For example,
wget http://www.rtems.org/ftp/pub/rtems/linux/4.9/fedora/12/i386/rtems-4.9-yum-conf-0.20-1.fc12.noarch.rpm
will download the correct file into your current directory.

Load

Load the .rpm into yum with command: sudo rpm -ivh [package] . For example, I did
sudo rpm -ivh rtems4.9-yum-conf-0.20-1.fc12.noarch.rpm
Now reload yum and search for rtems to display all the different toolchain components you can download for all the different available target architectures:
sudo yum update
yum search rtems

Install

Install the toolchain of build target of your choice. There are some things that all targets need, and then there are architecture specific things. First, the general stuff:
sudo yum install rtems-4.9-auto*
Now for the architecture specific stuff:
sudo yum install rtems-4.9-[ARCH]*
Playing along with the i386 example, the command would be:
sudo yum install rtems-4.9-i386-*

Sadly yum fails to completely install our tools. It puts everything in /opt/rtems-[VER]/bin/ which is not a part of your $PATH, so trying to compile will still result in "no compatible cc found" at this point. To correct this, tell the $PATH where the tools are with either a quick:
PATH=/opt/rtems-[VER]/bin:$PATH
(or the following for the i386 example):
PATH=/opt/rtems-4.9/bin:$PATH
or for a better solution, edit your ~/.bashrc and add the above line. If you go this route, the changes will take place after you reboot, and will continue to work after every reboot.

Now verify that the toolchain is available for use with the which command.
which [ARCH]-rtems[VER]-gcc
Or for the i386 example:
which i386-rtems4.9-gcc

If you don't get something along the lines of "/opt/rtems-VER/bin/ARCH-rtemsVER-gcc" as your output, you did something wrong.

Compile RTEMS

Compiling RTEMS is no different than compiling other programs. First call the configure script with the options you want, and then hit the make button. However the make files do seem to ignore the "--prefix=" flag if you try to use it (relevant only during make install), and dumps all the output into /opt/... anyway. In the general case, to compile RTEMS, you want to use a command (from the build directory, where [...] is the location of the source files for RTEMS) is:
[...]/rtemsVER/configure --target=ARCH --[ other options ]
In the i386 example:
[...]/rtems4.9/configure --target=i386-rtems4.9 --enable-tests --enable-networking --enable-posix --enable-rtemsbsp="pc386"

To quickly find the output files (assuming you built the tests) do a simple:
sudo find / -name hello.exe
This will reveal the directory holding all of the sample output files, and you can copy or move those somewhere into your home directory so they're more convenient to use.

Congratulations, you built RTEMS!

To get RTEMS booted in QEMU using GRUB, see my article about that