Build RTEMS With the RTEMS Source Builder and Waf
Build an RTEMS 6 toolchain with the RTEMS Source Builder, then compile the kernel and a BSP with Waf, using the SPARC erc32 simulator target as the example.

RTEMS, the Real-Time Executive for Multiprocessor Systems, is an open-source RTOS with a long record in space, defense and industrial systems. Getting started has two stages that are different from most RTOSes: you build a cross-compilation toolchain for your architecture, and then you build the kernel itself as a library for a particular board support package, called a BSP. The tools are the RTEMS Source Builder for the first stage and Waf for the second. This post follows the project's quick-start flow for RTEMS 6 on a Linux host, using the SPARC erc32 BSP, which runs on a simulator, so you need no hardware. The steps are from the RTEMS User Manual quick start; the manual is the authority, and versions and URLs change, so check it against what you see.
What gets built
Three artifacts come out. First, a cross toolchain: a compiler, assembler, linker and debugger that run on your host and produce code for the target, here sparc-rtems6-gcc and friends. Second, the RTEMS kernel and libraries compiled for one BSP, installed under a prefix. Third, optionally, tools such as a simulator. An application is compiled with the toolchain and linked against the installed kernel libraries.
The reason for two stages is that RTEMS wants its own toolchain configured for its own target triple, with the C library built to match, so using a generic bare-metal toolchain is not the supported path.
Prepare the host
You need a C and C++ compiler for the host, Python 3, Git, make, bison, flex, texinfo, unzip, patch, zlib and a few development libraries. The manual lists the packages by distribution. Choose a prefix, a directory that will hold everything, and use the same one in every command:
export RTEMS_PREFIX=$HOME/quick-start/rtems/6
mkdir -p $HOME/quick-start/src
cd $HOME/quick-start/srcBuild the toolchain with the Source Builder
Clone the Source Builder, check that your host has the required tools and build the toolset for SPARC:
git clone https://gitlab.rtems.org/rtems/tools/rtems-source-builder.git rsb
cd rsb/rtems
../source-builder/sb-check
../source-builder/sb-set-builder --prefix=$RTEMS_PREFIX 6/rtems-sparcsb-check prints whether your host passes, and names missing tools if it does not. sb-set-builder reads a build set, here 6/rtems-sparc, which lists the packages for the SPARC toolset: binutils, GCC, the C library newlib, GDB and tools such as the simulator. It downloads the sources, builds each and installs into the prefix. This takes a while, from half an hour to several hours depending on the machine, and it needs network access. When it finishes the tail of the log reports success, and the tools are in $RTEMS_PREFIX/bin:
export PATH=$RTEMS_PREFIX/bin:$PATH
sparc-rtems6-gcc --versionsparc-rtems6-gcc (GCC) 13.3.1 20240521 (RTEMS 6, RSB ..., Newlib ...)The version numbers depend on the release of the Source Builder you cloned. If the command is not found, the PATH export is missing or the build failed; look at the log files that the builder wrote.
Get the kernel and choose a BSP
Clone the RTEMS source next to the Source Builder:
cd $HOME/quick-start/src
git clone https://gitlab.rtems.org/rtems/rtos/rtems.git
cd rtemsA BSP is named by architecture and board, sparc/erc32 for the simulated ERC32 board. The list of BSPs is in the tree and in the manual. Waf, the Python build tool that RTEMS uses, reads its options from a file named config.ini, which it can generate with defaults for the BSP you want:
./waf bsp_defaults --rtems-bsps=sparc/erc32 > config.iniOpen config.ini and look at the options for the BSP. For a first build the defaults are fine; the file is where you later enable tests, tracing or options such as the number of CPUs. Without bsp_defaults you would pass the same options on the command line, but the file is easier to keep.
Configure, build and install the kernel
./waf configure --prefix=$RTEMS_PREFIX
./waf
./waf installconfigure checks the toolchain and writes the build settings. The Waf build compiles the kernel and the BSP in parallel and prints progress. install copies the headers and libraries into $RTEMS_PREFIX/sparc-rtems6/erc32. After that you have everything an application needs: a compiler and a kernel library for the BSP.
For a quick confirmation, look at the installed library directory:
ls $RTEMS_PREFIX/sparc-rtems6/erc32/libbsp_specs libm.a libc.a librtemsbsp.a librtemscpu.a linkcmds ...The names in your listing depend on the version. The files librtemsbsp.a and librtemscpu.a hold the board and CPU code, bsp_specs tells the compiler how to find them, and linkcmds is the linker script for the BSP.
Build tests
The kernel comes with a large set of tests that double as examples. Enable them in config.ini by setting BUILD_SAMPLES = True and BUILD_TESTS = True for the BSP section, then re-run ./waf configure and ./waf. The samples are small programs such as hello and ticker. Running them on the simulator is the quick check that the whole chain works. The next post writes a program of your own.
Using a real board
The same steps apply to a board BSP. You build the toolset for the architecture, for example 6/rtems-arm for Arm boards, choose the BSP, such as arm/stm32f4 or one of the Xilinx or Raspberry Pi boards, and configure. BSP-specific options, such as the clock speed, console baud rate or memory layout, are the keys in config.ini. Check that your board's BSP exists before planning around it, and read its documentation for the flash and debug procedure, because that part is board-specific and outside what Waf does.
Reading the layout of the install
After the install, take a minute to look around, because the layout is the same for every BSP and you will rely on it. The prefix holds a bin directory with the cross tools, a share directory with documentation and a directory named for the target triple, sparc-rtems6, which holds one subdirectory per installed BSP. Inside the BSP directory, include has the RTEMS headers, including rtems.h for the Classic API, and lib has the libraries and the linker script. When you compile an application, the compiler is told to look there with a -B option, which is why the next post's compile command names the BSP's lib directory. Installing several BSPs under the same prefix is normal: each gets its own directory and they share the toolchain.
Waf also records its settings in a build directory inside the source tree, so you can build out of tree for several BSPs from one checkout by running configure with a different --rtems-bsps value and a different build directory. Keep config.ini under version control with a comment on each change, since it is the record of how your kernel was built.
Troubleshooting
If sb-check fails, install the packages it names. If a download fails, retry, since upstream hosts occasionally move files; the Source Builder keeps a cache so completed work is not repeated. If ./waf configure cannot find the compiler, PATH does not contain $RTEMS_PREFIX/bin. If the build fails after you changed config.ini, re-run ./waf configure, because Waf caches the settings. If the host is a recent Linux with a newer compiler than the tested one, some builds need extra warnings relaxed; the project's issue tracker is the place to look.
Keep the prefix versioned by RTEMS release, as the quick start does with .../rtems/6, so a later upgrade can sit beside the old version.


