Compile and test your modified RTEMS system

This blog post is about how to add code to the classical RTEMS API and compile the whole system, e.g. to test the newly implemented code in a test application. The requirement for this approach to work is that you already built the RTEMS tools and kernel, for example by following the Quick Start guide in the RTEMS user manual. I am using the erc32 board support package.

First we need to identify the RTEMS classical API's source code location. The folder location may differ depending on the configuration of the setup. Generally, the classical API implementation is located in the kernel folder, in  /rtems/cpukit/rtems/src. There, we find the implementation of several operating system services, e.g. for creating a new task in an RTEMS application, the function rtems_task_create(..) located in taskcreate.c needs to be called. In a similar way, semcreate.c allows the application developer to create and use semaphores for their resources.  

If you want to extend the classical API with your own code, you need to save your C file in  /rtems/cpukit/rtems/src as well. For my project, I implement new code in fts.c, and save it in src. fts.c contains all function calls accessible to the RTEMS user. (low level code can be stored in /rtems/cpukit/score/src (correct?))

The header files for your C file should be stored in /rtems/cpukit/rtems/include along with all the other header files for the existing classical API code.

If the C file and the header file are in their corresponding locations, they need to be added to the makefile.am, which is located in /rtems/cpukit/rtems. Following the way the other headers are included, add your header file to the list, in my case I need to add the line include_rtems_rtems_HEADERS += include/rtems/rtems/fts.h. The list is sorted alphabetically, we should follow the convention.

If you take a look at the file, the C files are listed after the header files. To add your C file to makefile.am, just add your file to the list. In my case, I add librtems_a_SOURCES += src/fts.c with the comment ##FTS_FILES, it is easier to find and follows the conventions.

I will cover what the makefile.am does in the following paragraphs (check the figure below). For now we have all the requirements to compile our modified system. 

Since we changed the makefile.am, we need to rerun bootstrap. Bootstrap runs certain commands so that all the needed files are in a state such that we can run configure, make, and make install, to compile the system.

First, set your path with

export PATH=$HOME/development/rtems/4.12/bin:$PATH

We then run bootstrap. Navigate to /kernel/rtems, and run

./bootstrap -c && ./bootstrap -p && \
$HOME/development/rtems/rsb/source-builder/sb-bootstrap

The second part of the command is the location of your rsb source builder bootstrap. The bootstrap runs autoreconf, which makes sure tools are run in a correct manner. These tools are automake, which uses our modified makefile.im to generate a Makefile.in, and autoconf, which uses the configure.ac file to generate a configure script. The bootstrap may take a few minutes.

Next, we want to run configure. A configure script examines the system and gathers the necessary information to convert the Makefile.in to a customized Makefile for our system (and then can be run with just make). Makefiles are a bit confusing, but in a nutshell, Makefile.am is a "automake" makefile. Makefile.in is a "template" makefile, and Makefile is a file created from the former two, usually using configure.

Navigate to the folder /kernel/erc32 and run

$HOME/development/rtems/kernel/rtems/configure --prefix=$HOME/development/rtems/4.12 \
--target=sparc-rtems4.12 --enable-rtemsbsp=erc32 --enable-posix

Now, we can finally run

make

make install

If the makefile.am is not changed again, we can just run the following commands to compile our modified system

export PATH=$HOME/development/rtems/4.12/bin:$PATH

cd /erc32/

make

make install



If we modify the makefile.am, bootstrap needs to be run again, followed by configure and make. Now we compiled our modified system and we can test our code by implementing a test case.

To test the code, navigate to the location where you implemented the C file of your test case. Create a Makefile, taking the Hello World implementation as a template for example.

Set your path variable with

export PATH=$HOME/development/rtems/4.12/bin:$PATH

and the path of the RTEMS makefile for erc32

RTEMS_MAKEFILE_PATH=$HOME/development/rtems/kernel/erc32/sparc-rtems4.12/c/erc32/make

export RTEMS_MAKEFILE_PATH

Then run make

make

which compiles the application to make it executable on the erc32 simulator.

Navigate to the location of your .exe file, initialize the simulator and run your program, replacing fts.exe with the name of your program

sparc-rtems4.12-gdb fts.exe

tar sim

load

r

-----------------
That's all for this post. 

Extra bits:

How a spacecraft lands: 
 

Kommentare

Beliebte Posts aus diesem Blog

Fault Tolerant Scheduler preliminary API

Static Pattern-based Execution (SRE) in the Fault Tolerant Scheduler

Fault Injection and Detection in Static Pattern-based Execution (SDR)