RTEMS HelloWorld Tutorial

Let's go embedded.

RTEMS is a real-time executive which provides a high performance environment for embedded applications on a range processors and embedded hardware. In this tutorial you will learn howto:
  • install RTEMS and build RTEMS tools
  • run RTESM applications on TSIM simulator 
We leave the topic of compiling RTEMS applications for a separe howto article.  Check the blog for updates.
    Note: This tutorial is focused on the following platforms : SPARC LEON3 and ERC32/SIS.

    1) Prerequisities
    First, you will need a linux distribution supporting RTEMS. Try Fedora 11 or higher or SUSE 11 or higher.
    This tutorial is using the RTEMS version 4.9. RTEMS 4.10 is not officially distributed, but the instructions here in general should be valid once this new distribution is released.
    2) RTEMS OS installation
    As part of the installation, we need to install the RTEMS prebuilt tools first.
    Install (SUSE):
    $ rpm -Uvh <package name>.rpm

    Install (Fedora):
    $ yum install "installation_package_name"

    • All the packages will be installed in /opt/rtems-4.9/ by default.
    • During installation you can get some warnings about keys. Don't worry about them.
    • During installation you can get some dependency errors. Find the required packages from suse repositories and install them.
    3. Build RTEMS  
    In this step we will build RTEMS for two different configurations - LEON3 and ERC32/SIS.

    3.1 Build RTEMS with LEON3 support 
    1. Become root
    2. Browse http://www.rtems.org/ftp/pub/rtems/4.9.3/
    3. Download rtems-4.9.3.tar.bz2. Extract archive in the /opt/ directory. This will create /opt/rtems-4.9.3/
    4. Execute the following:
    $ cd /opt/rtems-4.9/
    $ export PATH=/opt/rtems-4.9/bin:$PATH
    $ ./bootstrap
    $ mkdir leon3
    $ cd leon3
    $ ../../rtems-4.9.3/configure --target=sparc-rtems4.9 
             --enable-rtemsbsp=leon3 --enable-posix
    $ make
    $ make install        
    3.2 Build RTEMS with ERC32/SIS support (optional)
    The same approach as above, only the configuration during the building is different:
    $ cd /opt/rtems-4.9/
    $ export PATH=/opt/rtems-4.9/bin:$PATH
    $ ./bootstrap
    $ mkdir bsis
    $ cd bsis
    $ ../../rtems-4.9.3/configure --target=sparc-rtems4.9 
    --enable-rtemsbsp=sis --enable-posix
    $ make
    $ make install    
    3.3 TSIM simulator
    Go to TSIM distribution at Gaisler Inc.
     - install the TSIM simulator, eg. in /opt/tsim 
    - the simulator will allow you to execute RTEMS binnaries on your x86

    4. RTEMS Helloworld with TSIM:
    First, you need to compile RTEMS C application. We will however not address this step here, we will dedicate a separate tutorial for this step. But, in order to verify that your installation is correct, RTEMS distribution contains many pre-compiled examples that you can use to run out of the box.
    You can also download it here: RTEMS HelloWorld binnary (compiled for SPARC LEON3).

    And then load the binnary file into the TSIM simulator and run it:
    $ /opt/tsim/linux/tsim-eval
    tsim> load hello
    tsim> go
    resuming at 0x40000000
    Hello World!
    Program exited normally.
    tsim> quit

    5. RTEMS installation - Building a toolchain and target C library  (optional)
    First, fetch gcc-core and gcc-c++ 4.3.2, binutils 2.19, newlib 1.16.0, and related patches from http://www.rtems.org/ftp/pub/rtems/SOURCES/4.9/. You need only the newest patch (the filenames include the date) for each component. Extract and patch each component from the same directory (we'll call it $TOP), so that you have $TOP/gcc-4.3.2/, $TOP/binutils-2.19/, and $TOP/newlib-1.16.0/.

    Link $TOP/newlib-1.16.0/newlib to $TOP/gcc-4.3.2/newlib:
    ln -s $TOP/newlib-1.16.0/newlib $TOP/gcc-4.3.2
    Create a build directory for each of binutils and gcc, indicating the architecture; something like binutils-2.19-$ARCH, where $ARCH is i386, sparc, etc.

    Pick an install directory; we will call it $PREFIX -- I use /opt/rtems-4.9.
    Configure and build binutils:
    cd $TOP/binutils-2.19-$ARCH
    ../binutils-2.19/configure --target=$ARCH-rtems4.9 
    --prefix=$PREFIX --disable-werror
    make install

    Configure and build gcc; this may require some platform-specific arguments:
    cd $TOP/gcc-4

    6. Other Tips (optional)

    RTEMS on x86:
    If you wish to boot RTEMS using grub (as for qemu), provide --enable-rtems-grub. This forces the binary to load up above the 1MB mark.

    FPU support:
    In case your RTEMS configuration is not FPU-friendly, when building your tools, provide --with-float=soft to the gcc configuration.

    1) Another RTEMS installation tutorial
    2) RTEMS: http://www.rtems.com/

    Acknowledgment: Thanks to Petr Maj and Ethan Blanton for help with this tutorial! 

    No comments:

    Post a Comment