Friday, March 29, 2013

Setting up an RTEMS development environment for the Raspberry Pi

Setting up an RTEMS development environment for the Raspberry Pi

For this tutorial, I’m going to use Ubuntu 12.10 64 bit (updated to 14.10 LTS on April 2014). It is possible to do RTEMS development on almost any recent version of Linux, OS X, FreeBSD, and Windows. The RTEMS project provides pre-built compilers for all RTEMS architectures for a number of different development hosts including Fedora, CentOS, Suse, and Windows.

In addition to the pre-built compilers provided, there is a tool called RTEMS Source Builder that can download, patch, build, and install the compiler for you. This is what we will use for our Ubuntu setup.

Note
  1. You will need a RTEMS compiler, an ARM bare metal GCC will not do.

  2. I have posted some instructions for setting up the environment for Windows 7 here

  3. The following instructions start with a fresh install of Ubuntu 14.10 LTS 64 bit, with all updates applied.

Install Ubuntu prerequisites:

$ sudo apt-get install build-essential
$ sudo apt-get install git
$ sudo apt-get install python-dev
$ sudo apt-get build-dep binutils gcc g++ gdb unzip git

Decide where the RTEMS tools and projects will reside

Here is the directory structure we will be using:

Path Description

$HOME/development/rtems

The base directory for all RTEMS work

$HOME/development/rtems/compiler

Where the compiler is installed

$HOME/development/rtems/rtems-git

Where the RTEMS source code is checked out

$HOME/development/rtems/bsps

Where the RTEMS board support packages/libs are installed

$HOME/development/rtems/rtems-source-builder

The RTEMS source builder tool

Table 1. Directory Structure

Lets get started on this:

$ cd $HOME
$ mkdir development
$ cd development
$ mkdir rtems
$ cd rtems
$ mkdir compiler

Build the RTEMS ARM cross compiler

The RTEMS Source builder documentation is located here:
http://www.rtems.org/ftp/pub/rtems/people/chrisj/source-builder/source-builder.html

1. Check out the RTEMS source builder tool

$ cd $HOME/development/rtems
$ git clone git://git.rtems.org/chrisj/rtems-source-builder.git

2. Double check that all source builder dependencies are present:

$ cd rtems-source-builder
$ source-builder/sb-check

This command should return the following:

RTEMS Source Builder environment is OK
Note The separate autotools build is no longer needed. The source builder will install them for you.

3. Build and install the toolchain

$ cd $HOME/development/rtems/rtems-source-builder/rtems
$ ../source-builder/sb-set-builder \
         --log=build-log.txt \
         --prefix=$HOME/development/rtems/compiler/4.11 \
          4.11/rtems-arm

After the full download and build process, the toolchain is installed in:
$HOME/development/rtems/compiler/4.11

Tip This whole process can take about 10 to 30 minutes depending on your computer specs. This has been run on a Raspberry Pi: Expect that to take all day!

4. Add the toolchain bin directory to your path, and you are ready to download and build RTEMS:

$ cd $HOME

Using your favorite editor, edit the .profile file and add the following line at the end of the file

PATH=$HOME/development/rtems/compiler/4.11/bin:$PATH

5. Now, logout and log back in. Open a terminal and type:

$ arm-rtems4.11-gcc -v

You should see the compiler version message. The compiler is installed and ready to use!

Next: How to download and build RTEMS

15 comments:

  1. Hi, alan
    I'm try to build on debian (fresh installation into a VMWare machine).
    after:
    $ ../source-builder/sb-set-builder --log=build-log.txt --prefix=$HOME/development/rtems/compiler/4.11 4.11/rtems-arm

    shell returned:
    Traceback (most recent call last):
    File " ../source-builder/sb-set-builder", line 26, in
    setbuilder.run()
    File " ../source-builder/sb/setbuilder.py", line 364, in run
    log.default = log.log(opt.logfiles())
    File " ../source-builder/sb/defaults.py", line 594, in logfiles
    return self.opts['log'].split(',')
    AttributeError: 'NoneType' object has no attribute 'split'
    You know how to fix it.
    Thank you.

    ReplyDelete
    Replies
    1. try running ../source-builder/sb-check
      This will let you know if all of the required tools are installed

      Also, what version of debian are you running? And what version of python?

      Delete
    2. Also, the RTEMS project has debian packages for the tools:
      http://www.rtems.org/ftp/pub/rtems/linux/4.11/debian/

      If you use these, you will have to change the arm-rtems4.11 prefix to arm-rtemseabi4.11 when configuring and building rtems.

      Delete
  2. -the debian mount 2.6.32-5-amd64 kernel;
    -the python version is 2.6;
    -I made the check after git cloning and the result was ok;

    ReplyDelete
  3. Ok ... may be I fix it.
    Under Debian the requirements are:
    $ sudo apt-get install autoconf automake bison flex binutils gcc g++ gdb \
    texinfo unzip ncurses-dev python-dev git.

    Then we must add autoconf automake bison flex texinfo ncurses-dev python-dev to the list above!

    I hope the build will finish without error.

    ReplyDelete
  4. The build was gone fine!
    in my macbookpro 5.5 and the Debian VM the time elapsed was 1h 17min;

    In this moment I'm doing the same thing on my macBookPro the requirements for building process:
    from official chrisj reference:
    MacOS X:
    The RTEMS Source Builder has been tested on Mountain Lion. You will need to install the Xcode app using the App Store tool, run Xcode and install the Developers Tools package within Xcode.

    But I've tryed ...and not work. Then I installed the Debian requirements on MacOS using homebrew.
    I've used others tool-chains, in past, in my system then installing packages listed below (that I have installed throught homebrew) worked fine for me:
    $ brew install autoconf automake binutils texinfo xz

    In general I suppose that in a fresh install we need of Xcode, DevelopesTools and all Debian requirements.

    The time elapsed for this building was 1 hour and 08 minutes.
    A bit surprisly, the time in DebVM is similar for both building process...
    The VM was created using only one of the two processor present in the laptop.....
    Yes Debian have a fresh install, and yes Debian is Debian... ( :) ) but ..... o_O

    ReplyDelete
  5. Question:
    In ypur opinion, can I install in this way also RTEMS running in MacOSX (i386 for a MBPro5.5)??

    if yes can I follow this tutorial modifying it in this way:

    1:SettingUp RTEMS dev-env for MacOsX:
    a.
    satisfy requirements;

    b.
    $ cd $HOME
    $ mkdir -p development/rtems/compiler
    $ cd development/rtems/compiler
    (skip this point if another RTEMS build is present in the sys.
    and jump to point e)

    c.
    $ cd $HOME/development/rtems
    $ git clone git://git.rtems.org/chrisj/rtems-source-builder.git

    d.
    $ cd rtems-source-builder
    $ source-builder/sb-check

    e.
    $ cd rtems (you should be in $HOME/development/rtems/rtems-source-builder/rtems )
    $ ../source-builder/sb-set-builder --log=build-log.txt \
    --prefix=$HOME/development/rtems/compiler/4.11 \
    4.11/rtems-i386

    f.
    $ ../source-builder/sb-set-builder \
    --log=autotools-log.txt \
    --prefix=$HOME/development/rtems/compiler/4.11 \
    4.11/rtems-autotools

    I think that I can skip this point if another build is present.
    Is true???

    g.
    $ cd $HOME
    and set the path with a persistent environment system variable.
    I think that I can skip this point if another build is present.
    Is true???

    h.
    after logout & login I will find i386-rtems4.11-gcc ???

    then I can move to the next step….

    ReplyDelete
    Replies
    1. Yes, it should work as you describe. The same PATH will work for any number of RTEMS architecture toolchains. I often have m68k, sparc, and arm on one system.

      Delete
  6. While I'm tryng to port to powerpc G3 lombard I read that there is the
    GDB ARM Simulator -- gdbarmsim support.
    You think that including this in the building of gdb I can debugg into RaspPi & into MacOS ??

    ReplyDelete
  7. Step 3 in the instructions is missing the following as the first line:

    $ cd $HOME/development/rtems/rtems-source-builder/rtems

    ReplyDelete
  8. Hi,
    I see that this blog is about rtems-raspberry, but a have an issue with arm-rtems same arhitecture .
    I am trying to build the rtems for arm and I have an issue on the asm part in file armv7m-context-restore.c in function:
    void __attribute__((naked)) _CPU_Context_restore(
    Context_Control *heir
    the error is : rtems_stm32f4/cpukit/score/cpu/arm/armv7m-context-restore.c:29:3: error: impossible constraint in ‘asm’

    I'm using gcc-4.8.0-rtems4.11-20130502
    Has someone a good idea how to solve this ?
    I'm using gcc-4.8.0-rtems4.11-20130502
    Have someone a good idea how to solve this ?

    ReplyDelete
    Replies
    1. Hi, I'm not quite sure how to solve this one..
      A couple of days ago, I installed arm-rtems4.11 4.8.1 20130531 ( for windows ) and compiled the latest rtems git head for the raspberry pi.

      I have not tried building a armv7 target for RTEMS. I suspect you might need a more recent GCC/newlib combination.

      I would try posting the question on the RTEMS users mailing list, or perhaps asking on the RTEMS IRC.
      http://rtems.org/wiki/index.php/RTEMSMailingLists
      http://www.rtems.org/wiki/index.php/RTEMS_IRC

      hope this helps,
      Alan

      Delete
  9. New to git, and the operation generated the following:
    ~/development/rtems> git clone git://git.rtems.org/chrisj/rtems-source-builder.git
    Cloning into 'rtems-source-builder'...
    fatal: remote error: access denied or repository not exported: /chrisj/rtems-source-builder.git

    Thanks!

    ReplyDelete
    Replies
    1. Sorry, the directions are getting old. I really need to update.
      Try:
      git clone git://git.rtems.org/rtems-source-builder.git

      When you build the tools using RSB, make sure you substitute 4.12 for 4.11 in my instructions. The RTEMS git repository defaults to RTEMS 4.12 now and you need to build the 4.12 tools to make RTEMS compile correctly. I recently did this and tested it on my Raspberry Pi ( Model A+ and Zero )

      Same applies to building RTEMS itself, substitute 4.11 with 4.12 like this:
      ../rtems-git/configure --target=arm-rtems4.12 \
      --enable-rtemsbsp="raspberrypi2 raspberrypi" \
      --enable-tests=samples \
      --enable-networking \
      --enable-posix \
      --prefix=$HOME/rtems/4.12

      I'm going to try to work on updating all of the instructions soon.


      Delete