This page gives you help to set up the GNU crosscompiler toolchain for ARM processors.
It is assumed that you work on some unix-ish system, that is, BSD, Linux, MacOS-X or similar. If you use Microsoft® Windows®, you are on your own; my experience with that operating environment is limited to to Microsoft® Word® 1.0 and Minesweeper® on Windows® 3.1.
The process below tells you how to install the crosscompiler for a bare metal system. If you want to set up a crosscompiler for an ARM based Linux system, the process is much more involved and it is way beyond the scope of this manual.
To set up the ARM crosscompiler toolchain, you will need the following packages to already having been installed on your system:
gcc, the GNU C compiler for your systemmake, the build utilitybison, the GNU parser generatorflex, the GNU lexical analyser generatorm4, the GNU macro processorlibtool, a package to manipulate library installationsgmp, the GNU multi-precision library, plus its headersmpfr, the multiple-precision float-point library, plus its headerstexinfo, the info page formatting packageOn a BSD or Linux system the above can usually be installed by simply telling your package manager to put them on (don't forget that you need the "development" package for gmp and mpfr). On MacOS-X it might be a little more complex than that, but a little research on the Web will help you through.
Download the binutils source from the FSF website or from a mirror. The following assumes that you have obtained binutils-2.20.1.tar.bz2 but the process is the same for any other version.
Unpack the source:
tar xfj binutils-2.20.1.tar.bz2
Do not go into the source directory. Create a separate build directry instead, then go there and configure binutils for arm-eabi target. If you prefer ELF over EABI, then use arm-elf instead of arm-eabi. If you have no idea what ELF and EABI are all about, you should first read ELF versus EABI at the end of this page and come back here.
mkdir build cd build ../binutils-2.20.1/configure --target=arm-eabi
If configure did not complain about any missing packages, you can now build the binary utilities:
make
The above command should complete without error. Now you can install your crossassembler, linker, etc. Pretty much all GNU packages install in /usr/local by default, which is usually not writeable by ordinary users. So, you have to install as root, either by doing
sudo make install
or if you don't have sudo on your system, by becoming root (and, depending on your su configuration, going back to the build directory) and typing:
make install exit
If the installaction succeeds, as it should, you should now get rid of the build directory:
cd .. rm -rf build
Now that you have binutils installed, you are ready for the gcc installation.
Note that you must install binutils before you can compile gcc as it needs the already existing crossassembler and other tools to build the run-time library.
Also note that the instructions below allow you to install 4.0.x to 4.4.x versions of gcc. The 4.5.x or newer versions require additional packages, like a polyhedra library development package and alike to be installed.
Download the source rom the FSF website or from a mirror. The following assumes that you have obtained gcc-4.4.3.tar.bz2 but the process is the same for any other 4.[0-4].x version.
First, unpack the source:
tar xfj gcc-4.4.3.tar.bz2
Create a build directory and enter it:
mkdir build cd build
Now configure to build a crosscompiler. There are a few configuration options that you have to pass. It wouldn't fit in a single line, so it is broken to multiple lines here, but it is a single command. Note that if you used arm-elf for binutils then you must use that for gcc as well.
../gcc-4.4.3/configure --target=arm-eabi --enable-interwork --disable-threads \ --disable-tls --disable-libada --disable-libssp --disable-libgomp \ --enable-languages=c
The command should finish without an error. If it complains about a package missing or being a too old revision, you will have to resolve that issue before being able to build the compiler. Assuming that configure finished successfully, you can build the crosscompiler:
make
It will take some time, several minutes (or several tens of minutes if you have some really old hardware) to complete. It should finish without any errors; although as it advances, you will see warning messages, but you can safely ignore them. When it's done, you can install it by:
sudo make install
just like you did with the binutils package. Get rid of the build directory before you forget:
cd .. rm -rf build
To test that your install was really successful and everything is fine, you can try this:
echo 'void foo( void ) {}' > test.c
arm-elf-gcc -c test.c -o /dev/null
You should just get the prompt back, without any error messages. If that is the case, you have a working crosscompiler, you can compile the library, and of course your own stuff.
If you can not make up your mind regarding to the ELF vs. EABI issue, then you can install both, by going through the above configuration, compilation and installation procedure twice. When you are completely happy with everything, you can delete the source directories and the tarfiles:
rm -rf gcc-4.4.3* binutils-2.20.1*
EABI stands for Embedded Application Binary Interface. It is basically a specification about register allocation, alignment rules, object sizes, calling conventions and so on. If your compiler conforms to the EABI, then the object code it generates will be usable by any other EABI compliant toolchain.
ELF stands for Executable and Link Format, a specification of how the object files and loadable executables are built. Among other things it is also an EABI, in that it specifies (most of) the conventions described by an EABI.
From your point of view both ELF and EABI are a specification of object size and alignment rules as well as register allocation and calling convention rules. Both will work. However, while they serve the same purpose, there are differences that you should be aware. Based on these differences you can make an informed decision about which one to use. The list below applies only to the 32-bit variants of ARM, for other processor architectures the rules are different!
char is 8 bits, short is 16 bits, int, long, float and pointers are 32 bits, long long and double are 64 bits.long long in the native endianness of the processor. However, a double is stored in Big-Endian word order in ELF and in the native endianness in EABI.double is stored in different order for ELF and EABI, it will also be mapped to registers differently.int followed by a double, ELF will put the double right after the int but EABI will introduce an additional word between them, to guarantee that the double starts at an 8-byte boundary.int and the second is a long long, then ELF will put the first argument in R0 and the second in R1-R2 while EABI will put the first argument in R0 but the second in R2-R3 and R1 will not ne used for argument passing. If you have a function that has a long long, an int and an other long long, then ELF will put the first argument in R0-R1, the second in R2 and the third will be split, one word will be in R3 and the other on the stack. EABI will pass the first two arguments in R0-R1 and R2, will not use R3 and pass the third argument on the stack. Eabi never splits a 64-bit object when passing it to functions.char member, then ELF will align it to 4-bytes and put 3 bytes of padding into it. EABI will not pad it and will align it on 1-byte boundary. If you have a structure with a double and an int member, then ELF will not pad the structure and align it on a 4-byte boundary, while EABI will introduce a pad word and align the structure on an 8-byte boundary.
1.7.1