Showing posts with label RTEMS tutorial. Show all posts
Showing posts with label RTEMS tutorial. Show all posts

27/07/2011

Running a C HelloWorld on ARM BeagleBoard

In this simple tutorial I will show you howto prepare your linux distribution for compiling and running C code on a BeagleBoard (ARM architecture). In short, you will need to install the cross-compiler, connect the board with your computer, load the compiled binaries to the board and finally execute them. Here we go in more details:

0. Prerequisites
  • Linux OS distribution (Ubuntu or Fedora should do)
  • BeagleBoard-xm with ARM A7 processor (or higher)


1. Install the ARM compiler

Image
You will need to install a compiler for ARMv7 / Linux. See for example ARM/GNU Linux.

Let's assume you have installed the compiler into the following location: /opt/CodeSourcery/Sourcery_G++_Lite.

Then add the location into your PATH:
$ export  PATH=$PATH:/opt/CodeSourcery/Sourcery_g++_Lite/bin

And test your compile by executing:
$ arm-none-linux-gnueabi-gcc  -o hello.arm hello.c

This should work, later on we will use the generated hello.arm to run it on the beagle-board.

2. Connecting the BeagleBoard

Here is a nice manual on setting up the BeagleBoard on a linux-server machine:
http://elinux.org/BeagleBoardBeginners

After going through the manul, your board should be sitting on your network at some IP address, it may be for example 192.168.0.2

To connect to the board:
$ shh root@192.168.90.2

Tip: If you reboot your linux desktop, you probably want to do the following to re-enable the connection with the board:
$ sudo ifconfig usb0 192.168.0.3

3. Running HelloWorld on BeagleBoard

First, we need to copy the executable to the BeagleBoard:
$ scp hello.arm root@192.168.0.3

And then just login to the board and run the executable:
$ shh root@192.168.90.2
$ ./hello.arm 
Hello World!

And that should be all.

[Note: This tutorial is based on my notes when working with the beagle-board, so it may omit some details. Hope it will help anyway.]

23/06/2010

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.
                rtems-4.9-autoconf-2.62-4.suse11.2.noarch.rpm      
                rtems-4.9-automake-1.10.3-1.suse11.2.noarch.rpm    
                rtems-4.9-binutils-common-2.19-3.suse11.2.i586.rpm 
                rtems-4.9-gcc-common-4.3.2-24.suse11.2.i586.rpm    
                rtems-4.9-gdb-common-6.8-11.suse11.2.noarch.rpm
                rtems-4.9-newlib-common-1.16.0-24.suse11.2.i586.rpm
                rtems-4.9-sparc-rtems4.9-binutils-2.19-3.suse11.2.i586.rpm
                rtems-4.9-sparc-rtems4.9-gcc-4.3.2-24.suse11.2.i586.rpm
                rtems-4.9-sparc-rtems4.9-gcc-c++-4.3.2-24.suse11.2.i586.rpm
                rtems-4.9-sparc-rtems4.9-gdb-6.8-11.suse11.2.i586.rpm
                rtems-4.9-sparc-rtems4.9-newlib-1.16.0-24.suse11.2.i586.rpm
    Install (SUSE):
    $ rpm -Uvh <package name>.rpm

    Install (Fedora):
    $ yum install "installation_package_name"

    Notes:
    • 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
    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.

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

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