Getting RTEMS Tools

Home | Next

In order to build the RTEMS operating system, you need to acquire the cross-compiling tools to build an RTEMS application. There are a few ways to go about this:

We will discuss building the tools from source here. For a linux distribution. These instructions have been tested on Ubuntu version 9.04.

First, the distribution needs to be configured with the correct tools. Here are a list of tools needed to build the RTEMS tools:

Note the the final two are necessary to have the correct version. It seems that RTEMS likes to stay more current on these than a lot of the repositorys keep up with.

Included below is a bash script originally written by Martin Decky, repurposed for use with the RTEMS/LUA project. This script will download the main components of the cross compiler (BINUTILS, GCC/G++, and NEWLIB).

#!/bin/bash

# Cross-Compiler Toolchain for ${PLATFORM}
#  by Martin Decky 
#
#  GPL'ed, copyleft
#


check_error() {
    if [ "$1" -ne "0" ]; then
	echo
	echo "Script failed: $2"
	exit
    fi
}

OPTIONDOWNLOAD=1
OPTIONUNPACK=1
OPTIONPATCH=1

BINUTILS_VERSION="2.20"
GCC_VERSION="4.4.2"
NEWLIB_VERSION="1.18.0"


CROSS_PREFIX=/home/<username>/rtems/rtemsi386/rtems/compilers/rtems10-i386-\
newlib${NEWLIB_VERSION}-binutils${BINUTILS_VERSION}-gcc-${GCC_VERSION}

if [ -z "${CROSS_PREFIX}" ] ; then
    CROSS_PREFIX="/usr/local"
fi


BINUTILS="binutils-${BINUTILS_VERSION}.tar.gz"
GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
NEWLIB="newlib-${NEWLIB_VERSION}.tar.gz"

BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
NEWLIB_SOURCE="ftp://sources.redhat.com/pub/newlib/"

PLATFORM="i386"
WORKDIR=`pwd`
TARGET="${PLATFORM}-rtems4.10"
PREFIX="${CROSS_PREFIX}/${PLATFORM}"
PROGRAMPREFIX="i386-rtems4.10"
BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
OBJDIR="${WORKDIR}/b-gcc"
BINBUILDDIR="${WORKDIR}/b-binutils"

echo ">>> Downloading tarballs"

if [ ${OPTIONDOWNLOAD} = '0' ]
then
	echo ">>>>>> Skipping download"
else
	if [ ! -f "${BINUTILS}" ]; then
	    wget -c "${BINUTILS_SOURCE}${BINUTILS}"
	    check_error $? "Error downloading binutils."
	fi
	if [ ! -f "${GCC_CORE}" ]; then
	    wget -c "${GCC_SOURCE}${GCC_CORE}"
	    check_error $? "Error downloading GCC Core."
	fi
	if [ ! -f "${GCC_OBJC}" ]; then
	    wget -c "${GCC_SOURCE}${GCC_OBJC}"
	    check_error $? "Error downloading GCC Objective C."
	fi
	if [ ! -f "${GCC_CPP}" ]; then
	    wget -c "${GCC_SOURCE}${GCC_CPP}"
	    check_error $? "Error downloading GCC C++."
	fi

	if [ ! -f "${NEWLIB}" ]; then
	    wget -c "${NEWLIB_SOURCE}${NEWLIB}"
	    check_error $? "Error downloading newlib."
	fi
fi

echo ">>> Creating destionation directory"
if [ ! -d "${PREFIX}" ]; then
    mkdir -p "${PREFIX}" 
    test -d "${PREFIX}"
    check_error $? "Unable to create ${PREFIX}."
fi

echo ">>> Creating GCC work directory"
if [ ! -d "${OBJDIR}" ]; then
    mkdir -p "${OBJDIR}"
    test -d "${OBJDIR}"
    check_error $? "Unable to create ${OBJDIR}."
fi

echo ">>> Creating BINUTILS build directory"
if [ ! -d "${BINBUILDDIR}" ]; then
    mkdir -p "${BINBUILDDIR}"
    test -d "${BINBUILDDIR}"
    check_error $? "Unable to create ${BINBUILDDIR}."
fi

echo ">>> Unpacking tarballs"
if [ "${OPTIONUNPACK}" = "0" ]
then
	echo ">>>>>> Skipping Unpacking tarballs"
else
	rm ${BINUTILSDIR} -rf 
	tar -xvzf "${BINUTILS}"
	check_error $? "Error unpacking binutils."
	rm ${GCCDIR} -rf
	tar -xvjf "${GCC_CORE}"
	check_error $? "Error unpacking GCC Core."
	tar -xvjf "${GCC_OBJC}"
	check_error $? "Error unpacking GCC Objective C."
	tar -xvjf "${GCC_CPP}"
	check_error $? "Error unpacking GCC C++."
	rm newlib-${NEWLIB_VERSION} -rf 
	tar -xvzf "${NEWLIB}"
	check_error $? "Error unpacking newlib."
fi

echo ">>> Applying patches"
if [ "${OPTIONPATCH}" = "0" ]
then
	echo ">>>>>> Skipping Applying patches"
else
	cd ${GCCDIR}
	cat ../archive/gcc-core-${GCC_VERSION}-rtems4.10-20091104.diff | patch -p1
	cd ../newlib-${NEWLIB_VERSION}
	cat ../archive/newlib-${NEWLIB_VERSION}-rtems4.10-20100426.diff | patch -p1
fi

echo ">>> Compiling and installing binutils"
cd "${BINBUILDDIR}" 
check_error $? "Change directory failed."
${BINUTILSDIR}/configure "--target=${TARGET}" "--prefix=${PREFIX}"
check_error $? "Error configuring binutils."

echo ">>> Compiling and installing GCC"
cd ${GCCDIR}
ln -s ../newlib-${NEWLIB_VERSION}/newlib .
cd "${OBJDIR}"
check_error $? "Change directory failed."
"${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" --with-gnu-as --with-gnu-ld\ 
--with-newlib --enable-threads --enable-languages=c --disable-libgcj --without-headers\ 
--disable-shared "--program-prefix=${PROGRAMPREFIX}-"

check_error $? "Error configuring GCC."
PATH="${PATH}:${PREFIX}/bin" 
make all-gcc install-gcc
make all
make install
check_error $? "Error compiling/installing GCC."

echo
echo ">>> Cross-compiler for ${TARGET} installed."
    
Pay extra attention to the patch section of the above script. You will need to find out what patches are necessary for your particular environment. They also need to be loaded into the correct location, as referenced in the script. The patches included above are here and here. You can find more up-to-date patches here. Also make sure you substitute <username> with your user account, otherwise the script will crash.

The above script will compile the tools and place them in the directory specified in CROSS_PREFIX. It will be useful to add this directory to your path, as we will be referencing them later.