wiki:TBR/UserManual/RTEMSAda

Version 63 (modified by Cicalese, on Jun 14, 2008 at 12:02:29 AM) (diff)

/* Source Code and Patches */

RTEMSAda

GNAT/RTEMS is used to refer to the configuration of the GNU Ada compiler (GNAT) when used with RTEMS as the run-time environment. GNAT/RTEMS provides a very full featured Ada programming and run-time environment. An early version of GNAT/RTEMS was validated (http://sw-eng.falls-church.va.us/ajpo_databases/ada95_validated_compilers.html#67) on the SPARC/ERC32. RTEMS has long had support for the Ada programming languages with the earliest work done against gnat 2.x. In fact, the GNAT/RTEMS port predates the other ports of GNAT to embedded RTOS environments.

History and Status

These instructions were developed and initially tested with GCC 4.2.0 for the following target/bsp combinations with the indicated level of testing

  • arm-rtems4.8 - Ada hello world ran on edb7312 simulator
  • bfin-rtems4.8 - nothing ran
  • i386-rtems4.8 - Ada hello world ran on qemu with pc386 BSP
  • m68k-rtems4.8 - nothing ran
  • mips-rtems4.8 - Ada hello world ran on jmr3904
  • powerpc-rtems4.8 - Ada hello world and ACATS ran on psim
  • sparc-rtems4.8 - Ada hello world and ACATS ran on erc32

These instructions have been used to build GNAT/RTEMS with GCC 4.2.3 and the GCC SVN trunk for the following target/bsp combinations with the indicated level of testing

Laurent Guerby originally wrote these instructions using the sparc-rtems4.7 target and erc32 BSP. His times are based on a Pentium M 1.7 GHz SuSE 9.3 machine.

JoelSherrill updated these instructions on 6 July 2007. My times are based on a 2.00 Ghz T2500 Centrino Duo running Fedora Core 7. I used the RTEMS RPMs as much as possible and ONLY built the packages that were absolutely necessary. In all cases, you should use the latest patches available which correspond to shipping RPMs. These should always be in the RTEMS source code at rtems/contrib/crossrpms/patches and at ftp://ftp.rtems.com/pub/rtems/SOURCES.

Cindy Cicalese updated these instructions on 13 February 2008 based upon testing psim on Fedora 7 with RTEMS 4.9. Cindy wrote a set of scripts that largely automate this process. Joel used these and reports a total build time of approximately 1 hour from autotools to two RTEMS BSPs.

As of 14 February 2008, there is a single technical issue which prevents Ada from being included in the standard RTEMS RPMs. The Ada run-time libraries are NOT built multilib. If this is resolved, then it is expected that Ada will be included in the RTEMS RPMs.

General Ada Programming/RTEMS Build Instructions

These instructions assume the following strings in the instructions are replaced with values appropriate for you. These may not work if you use these as environment variables, so do so at your own risk.

  • INSTALL_DIR is the prefix (installation directory) for the toolchain installation
  • TARGET is the target code (tested with TARGET=sparc-rtems4.7)
  • BSP the RTEMS BSP (tested with BSP=erc32)

It is critical that you have a recent enough C/Ada native GCC in your $PATH before beginning.

Please perform each configure/make/make install trio in a separate empty build directory. In the directions below, the versions for RTEMS 4.9 are used. If you are building RTEMS 4.8, update the commands below with the appropriate older versions. Also set PATH=INSTALL_DIR/bin:$PATH.

Finally, some weird behavior has been observed when trying to build GCC on Fedora using an NTFS file system.

Source Code and Patches

If you are building from source code, download all of the necessary source code archives, unpackage them, and apply the appropriate patches.

Please use the latest patches available for the tool versions you are using. These should always be in the RTEMS source code at rtems/contrib/crossrpms/patches and at ftp://ftp.rtems.com/pub/rtems/SOURCES.

As of 1 April 2008, the current source code and patches for RTEMS 4.9 are as follows:

<blockquote> {| border=1 cellspacing=0 cellpadding=10 style="background:#ccffcc;"

!Component !Version !Source Code !Diff Date !Diff

|autoconf |2.61 |ftp |N/A |

|automake |1.10 |ftp |N/A |

|binutils |2.18 |ftp |2008-02-11 |ftp

|rowspan=2|gcc |rowspan=2|4.2.3 |rowspan=2|ftp |core: 2008-02-05 |ftp

|Ada: 2008-02-07 |ftp

|newlib |1.16.0 |ftp |2008-03-02 |ftp

|gdb |6.7.1 |ftp |2007-12-16 |ftp

|} </blockquote>

As of 21 December 2007, the current source code and patches for RTEMS 4.8 are as follows:

<blockquote> {| border=1 cellspacing=0 cellpadding=10 style="background:#ccffcc;" |+ RTEMS 4.8 Sources and Patches

!Component !Version !Source Code !Diff Date !Diff

|autoconf |2.61 |ftp | |

|automake |1.10 |ftp | |

|binutils |2.17 |ftp |2006-10-21 |ftp

|rowspan=2|gcc |rowspan=2|4.2.0 |rowspan=2|ftp |core: 2007-06-13 |ftp

|Ada: 2007-07-05 |ftp

|newlib |1.15.0 |ftp |2007-12-21 |ftp

|gdb |6.6 |ftp |2007-12-16 |ftp

|} </blockquote>

Rather than building from source code, you may be able to use the pre-built versions of the code provided for various architectures at ftp://ftp.rtems.com/pub/rtems/. For example, an RPM for autoconf 2.61 for Fedora 7 is available at ftp://ftp.rtems.com/pub/rtems/linux/4.8/fedora/7/i386/rtems-4.8-autoconf-2.61-5.fc7.noarch.rpm. However, be aware that problems have been identified if the version of the pre-built binutils has an INSTALL_DIR different from the one you are using for the other tools. It is also possible to install the binutils RPMs in a non-default location using rpm2cpio and mv, but this may cause problems in finding "as" on some platforms.

Building autoconf and automake (1 minute)

mkdir b-autoconf
cd b-autoconf
../autoconf-2.61/configure --prefix=INSTALL_DIR
make 
make install
mkdir b-automake
cd b-automake
../automake-1.10/configure --prefix=INSTALL_DIR
make 
make install

Building binutils (3 minutes)

mkdir b-bin
cd b-bin
../binutils-2.18/configure  --verbose --disable-nls \
--target=TARGET --prefix=INSTALL_DIR
make
make install

GCC and newlib Setup

It is usually necessary to build a native C/Ada native GCC of EXACTLY the same version as the version you are building cross to target RTEMS. So, starting from a relatively recent native C and Ada GCC, you will probabaly need to build a new native C and Ada GCC. You will then proceed to build a C cross-compiler and then a C and Ada cross-compiler.

Be sure to patch your gcc newlib with the latest RTEMS newlib patch mentioned BEFORE linking newlib and libgloss into the gcc tree.

Add newlib and libgloss links in the gcc source top level directory.

cd ../gcc-4.2.3/
ln -s ../newlib-1.16.0/newlib ../newlib-1.16.0/libgloss .

Build Native C and Ada Compiler (1 hour)

mkdir b-native
cd b-native
../gcc-4.2.3/configure --disable-multilib --enable-languages=c,ada --prefix=INSTALL_DIR
make
make install

Build non-multilib C Cross-Compiler (12 minutes)

Building GNAT is a bit idiosyncratic. You must build and install a toolset WITHOUT Ada first since building the GNAT run-time depends on at least an installed C Library. In addition, as mentioned earlier, the Ada run-time libraries are not built multilib so you must compile them with CPU dependent CFLAGS which match those required by your intended target CPU.

mkdir b-gcc1
cd b-gcc1
../gcc-4.2.3/configure --enable-threads=rtems  --with-gnu-as --disable-multilib \
  --with-gnu-ld --with-newlib  --verbose --with-system-zlib --disable-nls \
  --enable-version-specific-runtime-libs \
  --enable-languages=c --target=TARGET --prefix=INSTALL_DIR
make
make install

NOTE: Be sure to have a native GCC Ada compiler of the same of similar version. Otherwise, it is possibly the cross-GNAT will fail to compile with a mysterious looking error.

Build non-multilib C and Ada Cross-Compiler (21 minutes)

mkdir b-gcc2
cd b-gcc2
../gcc-4.2.3/configure --enable-threads=rtems  --with-gnu-as --disable-multilib \
  --with-gnu-ld --with-newlib  --verbose --with-system-zlib --disable-nls \
  --enable-version-specific-runtime-libs \
  --enable-languages=c,ada --target=TARGET --prefix=INSTALL_DIR
make
make install

You can include c++ in the list of languages if you wish.

Or Slower Build of multilibed C, C++, and Ada Cross-Compiler (XX minutes)

Note: untested,

../gcc-4.2.3/configure --enable-threads=rtems  --with-gnu-as \
  --with-gnu-ld --with-newlib  --verbose --with-system-zlib --disable-nls \
  --enable-version-specific-runtime-libs --enable-libada \
  --enable-languages=c,c++,ada --target=TARGET --prefix=INSTALL_DIR
make
make install

Build GDB (4 minutes)

mkdir b-gdb
cd b-gdb
../gdb-6.7.1/configure --verbose --disable-nls \
  --enable-sim --enable-sim-timebase --enable-sim-hardware \
  --target=TARGET --prefix=INSTALL_DIR
make
make install

Build RTEMS from CVS (4 minutes)

First, get the RTEMS source code. For RTEMS 4.9, use:

cvs -z3 -d :pserver:anoncvs@www.rtems.com:/usr1/CVS login
cvs -z3 -d :pserver:anoncvs@www.rtems.com:/usr1/CVS co rtems

For RTEMS 4.8, use:

cvs -z3 -d :pserver:anoncvs@www.rtems.com:/usr1/CVS login
cvs -z3 -d :pserver:anoncvs@www.rtems.com:/usr1/CVS co -r rtems-4-8-branch rtems

Then, build RTEMS:

cd rtems
./bootstrap
cd ..
mkdir b-rtems
cd b-rtems
../rtems/configure --disable-multilib --disable-cxx --enable-posix \
  --enable-networking \
  --target=TARGET --prefix=INSTALL_DIR --enable-rtemsbsp=BSP
make
make install

Note: autoconf must be recent and include RTEMS patches.

Compile and Test

$ cat > t.adb
with Ada.Text_IO;
procedure T is
begin
   Ada.Text_IO.Put_Line ("Hello RTEMS Ada");
end T;
<Control-D>
$ powerpc-rtems-gnatmake -f -g t -largs -BINSTALL_DIR/TARGET/BSP -specs bsp_specs -qrtems
...
$ INSTALL_DIR/powerpc-rtems/psim/tests/runtest ./t

Then look in log/t.

Note1: It appears that gnat (gcc 4.2.0) is mangling target names with periods in them. CPU-rtems4.7 is turning into CPU-rtems4.

Note2: It appears that gnat (gcc 4.1 CVS) is always looking for the cross tools in /usr/bin. Unchecked in 4.2.0.

Note3: Does not appear to work in RTEMS 4.9.

Old Build Instructions with GCC 3.2

make
make -C gcc cross-gnattools
make -C gcc ada.all.cross
make -C gcc GNATLIBCFLAGS="${GNATLIBCFLAGS}" gnatlib
make install