CrossCompilation (2005-04-12 17:39:50)

Hardware Specific Compilation Information

Each hardware implementation has their own quirks for building:

With different crt0/libraries, the same tool chain should also work for developing firmware for the VemsFrontier/ArmEfi boards.


Building An ARM Cross-compiler Using The GNU Toolchain

In order to easily/quickly build binaries from C for the ARM processor, it's necessary to build a cross-compiler to run on a non-ARM machine (you can build natively if you've got the resources, but speaking as someone who has built all of XFree86 on a 200 MHz StrongARM, it sucks -- Alexander). Almost any desktop/workstation/server running Windos/Linux/*BSD/Mac OS X can host a cross-compiler, but it's a bit easier to get up and running under UNIX.

[Devkitpro project] makes it a simpler process (tried with success on Linux and win32):

While on linux you might be tempted to do the "compile yourself" method below, on win32 this is about your only choice to get going easily.

All of the following was done under Linux (Debian/testing), but it can be easily applied to building the GNU toolchains on any other platform.

1. Obtaining Source

Grab the following off of a GNU mirror of your choice (e.g. ftp.gnu.org):

In order to get some semblance of libc support, you'll need to get newlib from sources.redhat.com:

Before we continue to build things, a couple assertions need to be made:

2. Setting Up The Source/Build Environment

Start by decompressing/extracting all of the source into one directory. Next, create empty build directories for each of the source packages:

\\n
drwxr-xr-x  15 alexander alexander     4096 Dec 27 16:32 binutils-2.15
-rw-r--r--   1 alexander alexander 15134701 Dec 27 16:15 binutils-2.15.tar.gz
drwxr-xr-x  10 alexander alexander     4096 Dec 27 16:48 build.binutils
drwxr-xr-x   7 alexander alexander     4096 Dec 27 17:01 build.gcc
drwxr-xr-x   4 alexander alexander     4096 Dec 27 17:08 build.newlib
drwxr-xr-x  11 alexander alexander     4096 Dec 27 17:00 gcc-3.4.3
-rw-r--r--   1 alexander alexander 13040222 Dec 27 16:23 gcc-core-3.4.3.tar.bz2
drwxr-xr-x   9 alexander alexander     4096 Dec 17 15:03 newlib-1.13.0
-rw-r--r--   1 alexander alexander  7786190 Dec 27 16:38 newlib-1.13.0.tar.gz

In order to not have to do the builds/installs as root, it's nice to make the base directory of the toolchain (i.e. /usr/local/arm-efi) a directory owned by your user. This avoids having to run configure scripts and make files as your super-user. After everything has been built/setup, you can change ownership over to whomever you feel is correct for your system (e.g. root).

3. Configure/Build/Install binutils

Enter into your build.binutils directory, and execute the following:

\\n
../binutils-2.15/configure  --target=arm-elf --prefix=/usr/local/arm-elf

Next, run make, and then make install. To make sure the rest of your builds can now see your new tools, add /usr/local/arm-elf/bin to your PATH. In a Bourne-a-like shell (e.g. sh, or bash), you do something like:

\\n
PATH=$PATH:/usr/local/arm-elf/bin

4. Configure/Build/Install gcc

Inside build.gcc, execute the following:

\\n
../gcc-3.4.3/configure  --target=arm-elf --with-cpu=arm7tdmi --with-newlib --enabl
e-multilib --enable-interwork --disable-threads --enable-targets=arm-elf --enable-la
nguages=c --prefix=/usr/local/arm-elf

Now make and make install.

5. Configure/Build/Install newlib

Inside build.newlib, execute the following:

\\n
../newlib-1.13.0/configure --target=arm-elf --prefix=/usr/local/arm-elf 

Again, make and make install.

6. Test Out Your Creation

Open up your favorite editor, and edit a file called test.c:

\\n
int
main(void)
{
    return 0;
}

Now compile/link this program with your new toolchain, and then verify the contents of the product:

\\n
alexander@midget:/tmp$ arm-elf-gcc armtest.c -o armtest
alexander@midget:/tmp$ arm-elf-objdump -f armtest

armtest:     file format elf32-littlearm
architecture: arm, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x00008110

Rejoice, your compiler/linker worked.