Documents/ARM ELF Toolchain Build

From Nutwiki
Jump to: navigation, search

Building a GNU Toolchain for ARM on Linux

The GNU toolchain is a collection of free programming tools, which allows to create executables for a large number of target systems, using several different programming languages. It is further capable of creating executables for a platform other than the development environment. This is called cross compiling.

Generally there are two ways of installing an executable toolchain:

  • Using a package manager to install the executables.
  • Building the executables from source code.

This document describes, how to build a C/C++ cross compiler toolchain for the ARM CPU. It will be build from source code on a Linux PC running Debian Etch.

Prerequisites

Depending on your environment, the build procedure may fail at various stages. In such cases some basic knowledge about installing, updating or replacing Debian packages will be required.

The following tool version had been used here

$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

$ make --version
GNU Make 3.81

$ autoconf --version
autoconf (GNU Autoconf) 2.61

$ automake --version
automake (GNU automake) 1.10

$ bison --version
bison (GNU Bison) 2.3
 

Further, the following relevant packages and libraries had been installed, among many others of course.

  • libc6-dev 2.3.6.ds1-13
  • libncurses5-dev 5.5-5
  • binutils 2.17-3

Note, that earlier and later releases of these tools and libraries may or may not work.

Getting the Source Archives

binutils-2.17.tar.bz2
GNU binary utilities, a set of tools to manipulate binary objects.
Available at www.gnu.org/software/binutils

gcc-4.1.2.tar.bz2
GNU compiler collection.
Available at gcc.gnu.org

newlib-1.14.0.tar.gz
Standard C library for embedded systems.
Available at www.sourceware.org/newlib

insight-6.5.tar.bz2
Graphical user interface for and including GDB, the GNU debugger.
Available at www.sourceware.org/insight

Unpacking the Source Archives

Move all archives to a directory of your choice. We will call this our top build directory. Change to this directory and expand all archives by using the following command sequence:

$ tar xjf binutils-2.17.tar.bz2
$ tar xjf gcc-4.1.2.tar.bz2
$ tar xzf newlib-1.14.0.tar.gz
$ tar xjf insight-6.5.tar.bz2

The archives are no longer needed and may be moved to a separate directory.

$ mkdir ~/sources
$ mv *.tar.bz2 ~/sources/
$ mv *.tar.gz ~/sources/

Building binutils

Although possible, we will not build the packages directly in their source directories. Instead we will create specific directories for building the executables.

$ mkdir binutils-arm-build

Change to the build directory and configure binutils for our target.

$ cd binutils-arm-build
$ ../binutils-2.17/configure --target=arm-elf --prefix=/usr \
  --enable-interwork --enable-multilib --disable-nls --disable-shared \
  --disable-threads --mandir=/usr/share/man --infodir=/usr/share/info

Start building with make.

$ make

If everything went fine, install binutils by calling make install as root.

# make install

Finally return to the top build directory as a normal user.

$ cd ..

Building a Limited Compiler

Two steps are required to build the GNU compiler. We will first build a limited version, which is capable of compiling the standard libraries. Create a specific build directory first.

$ mkdir gcc-arm-build
$ cd gcc-arm-build

Configuring the compiler requires root access.

# ../gcc-4.1.2/configure --target=arm-elf --prefix=/usr --disable-nls \
  --disable-shared --disable-threads --with-gcc --with-gnu-ld --with-gnu-as \
  --with-stabs --enable-interwork --enable-multilib --enable-languages="c,c++" \
  --with-newlib --with-headers=../newlib-1.14.0/newlib/libc/include \
  --disable-libssp --disable-libstdcxx-pch --disable-libmudflap \
  --mandir=/usr/share/man --infodir=/usr/share/info
# make all-gcc
# make install-gcc

Return to the top build directory when done.

$ cd ..

Building newlib

We will now use limited compiler to build the libraries in a dedicated build directory.

$ mkdir newlib-arm-build
$ cd newlib-arm-build

Not sure if we need root access for configuration and building. At least it is required for the installation process.

# ../newlib-1.14.0/configure --target=arm-elf --prefix=/usr --enable-interwork \
  --enable-multilib --with-float=soft --mandir=/usr/share/man --infodir=/usr/share/info
# make
# make install

Finally go back to the top build directory.

$ cd ..

Building the Final GCC

After having build the libraries, we are now able to build the full compiler. Change to the GCC build directory.

$ cd gcc-arm-build

Start the build process as root.

# make all
# make install

Leave the GCC build directory.

$ cd ..

Building Insight

Configure and build Insight including GDB.

$ mkdir insight-arm-build
$ cd insight-arm-build
$ ../insight-6.5/configure --target=arm-elf --prefix=/usr \
  --enable-interwork --enable-multilib --disable-nls \
  --mandir=/usr/share/man --infodir=/usr/share/info
$ make
                  We need root access to install the executables.
# make install

Once again, return to the top build directory.

$ cd ..