The following document explains how to rebuild your own tool chain for an ARM v4/v5 processor in a Unix environment for the eCos platform. The toolchains have been successfully rebuilt on the following host platforms:
- Mac OS X 10.5.5
- Linux 2.6.26
- Cygwin / WinXP Pro SP3
Prerequisites
It is assumed that you have a valid environment for native compilation, with
- GNU C compiler suite
- GNU Make
- texinfo
- flex/bison
- gettext (including the 'development' version)
- m4
- makeinfo
If Insight is to be installed
- Tcl/Tk
- expat
- ncurses, including the development package
If you wish to build GCC 4.3.0 or later, you also need two mathematical libraries: GMP and MPFR
- if these libraries are not available on your host, you can recompile them from the source.
- it is recommended to install them into the same directory than the GCC tool chain if you are not using a package manager.
Getting the source code
The following source distribution are required:
- Binutils (assembler, linker and other binary file tools)
- Go to http://www.gnu.org/software/binutils and grab the latest release
- GNU C compiler core
- Go to http://gcc.gnu.org then pick up a mirror, go down the releases directory and grab the latest release that starts with gcc-core
- GNU C++ compiler extension
- same as above, download the archive that starts with gcc-g++
- Newlib
- Go to http://sourceware.org/newlib, follow the download link then the FTP directory link and grab the latest release
- Insight & GDB [optional]
- Go to http://sourceware.org/insight, follow the FTP directory link and grab the latest release
- GMP [only if not already available on your platform]
- Go to http://gmplib.org/#DOWNLOAD and download the latest version
- MPFR [only if not already available on your platform]
- Go to http://www.mpfr.org/mpfr-current/#download and download the latest version
- Be sure to also download the cumulative patch from the same page
Note
- Insight and the GDB debugger are not required to build ARM libraries and applications. However it is useful to build GDB and the Insight GUI to enable application debugging.
The GNU tool chain has been rebuilt with the following versions of the tools
- Binutils 2.18: binutils-2.18.tar.bz2
- GMP 4.2.4: gmp-4.2.4.tar.bz2
- MPFR 2.3.2: mpfr-2.3.2.tar.bz2
- GNU C/C++ 4.2.4: gcc-core-4.2.4.tar.bz2, gcc-g++-4.2.4.tar.bz2
- GNU C/C++ 4.3.2: gcc-core-4.3.2.tar.bz2, gcc-g++-4.3.2.tar.bz2
- Newlib 1.16: newlib-1.16.0.tar.gz
- Insight 6.8: insight-6.8.tar.bz2
cd $HOME/tmp wget
mkdir src build cd src for a in ../*.bz2; do tar xjvf $a; done for a in ../*.gz; do tar xzvf $a; done for d in *; do mkdir ../build/$d; done cd gcc* ln -s ../newlib*/libgloss ln -s ../newlib*/newlib cd ../..
Defining the global parameters
Here we define where the toolchain will be installed (PREFIX) and the target (TARGET) for which we want to build the toolchain.
- You can change the installation prefix, although depending on the OS (Linux, Windows, ...) you should follow the installation path guidelines...
- Never change the target, as long as you build a toolchain for an ARM processor
export PREFIX=/usr/local/gnu export TARGET=arm-elf
Clean up your PATH environment. You need to be sure that no other cross-compiler for the same target already exists in your executable path.
Typical settings, YMMV:
- Windows/Cygwin
export PATH=/usr/bin:/bin:/cygdrive/c/WINDOWS/System32:/cygdrive/c/WINDOWS
- Linux
export PATH=/usr/bin:/bin
Note
Keep in mind that these environment variables are only valid within the current shell, so if you close the session before the tool chain compilation is complete, you need to redefine these values in the new session before resuming the compilation
Compiling the tool chain
Preliminary notes
- On Mac OS X, it is recommended to build with the new GCC compiler, so prefix each ./configure statement with
CC=gcc-4.2 ./configure ...
- On 64-bit hosts (Core2 Duo for ex.), you may want to compile the toolchain in 64-bit mode.
Add the following flag before the ./configure statement
CFLAGS="-O2 -m64" ./configure ...
Compiling the binutils
Configuration options
- discard native language support (all execution messages are dumped in english)
- ensure we used shared libraries to save space (and SDK size)
Building
cd build/binutils* ../../src/binutils*/configure --prefix=$PREFIX --target=$TARGET \ --enable-shared --enable-serial-configure --disable-nls make sudo make install cd ../..
Notes
- On Cygwin, you do not need the sudo command to install the toolchain.
- Replace sudo make install with make install in the the following instructions
- On Mac OS X, you need to build the static version of binutils (or fear compilation issues of the GCC cross compiler)
- Replace --enabled-shared with --disabled-shared in the above configuration line. All the other tools of the toolchain may be built as shared libraries.
- On some Linux host, the configure script fails to detect the installed makeinfo tool, and in turn prevent from building the binutils.
As a dirty hack you can replace the ../../src/binutils-2.18/missing file with the env command, so that it actually invoke the makeinfo tool - be sure it is installed though
(cd ../../src/binutils-2.18 && mv missing missing.old && ln -s /usr/bin/env missing)
Compiling the GMP library
This extra step is only required if GMP is already available on your platform.
Before rebuilding it from the sources, please check your favorite package manager cannot install it from your distribution server.
Note that many Linux distributions still offer outdated versions of these libraries which are too old for rebuilding GCC.
Cygwin package manager -setup.exe- now offers the GMP amd MPFR libraries.
Building GMP
cd build/gmp* ../../src/gmp*/configure --prefix=$PREFIX --disable-nls make make check sudo make install cd ../..
Compiling the MPFR library
This extra step is only required if MPFR is already available on your platform.
Before rebuilding it from the sources, please check your favorite package manager cannot install it from your distribution server.
Configuration options
- MPFR need to know where GMP has been installed
Building MPFR
cd build/mpfr* ../../src/mpfr*/configure --prefix=$PREFIX --with-gmp=$PREFIX make sudo make install cd ../..
Compiling the GNU C/C++ compiler
Updating the execution path
Now that the binutils have been installed, the PATH environment variable needs to be updated so that the compiler may find them to generate the required libraries:
export PATH=$PATH:$PREFIX/bin
Configuration options
- discard native language support (all execution messages are dumped in english)
- ensure we used shared libraries to save space (and SDK size)
- enable compiler support for both C and C++ language (the latter is required to build the eCos kernel)
- both the assembler and the linker are part of the GNU tool chain (i.e. the GNU binutils)
- use the newlib library rather than the GNU libc library
- use a custom build string to differentiate this custom build from the official binary release
- do no build all the variants of the libraries (save a lot of time and space)
- the ARMv4/v5 processors do not sport a floating-point hardware unit (FPU)
- define the default settings for the ARMv4/v5 processor:
- endianess: little
- no support for Thumb 16-bit instruction set
- GNU ABI
Building
cd build/gcc* ../../src/gcc*/configure --prefix=$PREFIX --target=$TARGET --enable-shared --enable-languages=c,c++ \ --disable-nls --with-gnu-as --with-gnu-ld --with-newlib --with-pkgversion=eCos-SDK \ --with-gxx-include-dir=$PREFIX/$TARGET/include --disable-multilib --enable-softfloat \ --disable-bigendian --disable-fpu --disable-interwork --disable-underscore \ --with-float=soft --with-abi=apcs-gnu --with-fpu=fpa --with-mode=arm --disable-__cxa_atexit make suo make install cd ../..
Notes
- same remark as for binutils about the super-user requirement
- if you have recompiled GMP and MPFR from the sources, you also need to tell the configure script where to find these libraries; append the following option switches to the configure parameters:
--with-gmp=$PREFIX --with-mpfr=$PREFIX
- if you have chosen to build in 64-bit mode (-m64), you need to:
- Append the following flags before the ./configure command:
CFLAGS_FOR_BUILD="-O2 -m64" CFLAGS_FOR_TARGET="-O2" CFLAGS="-O2 -m64"
- Tweak the generated arm-elf/libgcc/Makefile, as gcc configure script fails to deal with some cross-compilation setting, and attempts to apply the -m64 flag to the ARM compiler.
Add the following line right before the INTERNAL_CFLAGS = line, to strip out the -m64 flag.
override LIBGCC2_CFLAGS := $(filter-out -m64,$(LIBGCC2_CFLAGS))
- Append the following flags before the ./configure command:
Compiling the GDB debugger with Insight graphical user interface
Configuration options
- The default configuration settings for Insight GDB do not require further customization.
- If you use a recent (4.x) GCC compiler to build up GDB, you'll need to tweak the generated Makefile: it enables the 'stop on warning' GCC compiler option, however the GDB source code does not compile without warnings with a recent GCC compiler:
After running the GDB configure script, and before invoking make, execute the following actions:
- Edit the generated gdb/Makefile file
- Search for occurences of -Werror and remove them
- Save the file
Building
cd build/insight* ../../src/insight*/configure --prefix=$PREFIX --target=$TARGET make sudo make install cd ../..
Fixing build issues
You may have to edit a couple of Makefile to fix up the definitions (before invoking make)
- gdb/Makefile: remove the "-Werror" option, as GDB cannot be built without warnings with a GCC 4.x compiler
- on Mac OS X, add the path to the X11 library: add LDFLAGS=-L/usr/X11R6/lib before the ./configure statement
Saving space
All the executable files are built with optimization and debugger symbols enabled. There is no need to keep those debugging symbols except if the GNU compiler suite itself is to be debugged.
Several dozens of megabytes can be saved off the generated executable files, hence producing a smaller GNU tool suite and a more compact installer file.
Stripping down application files
find $PREFIX -path "*bin/"* -exec strip {} \; 2> /dev/null
Verifying the GNU tool chain
Automatic test suite cannot be run as the tool chain being built is a cross-compilation tool chain, i.e. it produces applications that may not be run on the machine where the applications are buit.
However the compiler configuration can be dumped and verified this way:
arm-elf-gcc -v --help 2>&1 | less
Final notes
Please remember to add the installation prefix to your PATH before building application, i.e. $PREFIX/bin
Windows users: You may want to consider using a virtual machine with a Linux guest OS to build up eCos projects rather than using Cygwin. Cygwin is a clever way to run software designed for Unix in a Windows environment, but it dramatically slows down compilation - a typical build runs 8 to 10 times slower than Linux on the same host machine. Using a Windows VM to run Linux brings compilation time close to the native compilation time.