Toolchain

From iPodLinux

Jump to: navigation, search

To build binaries for the iPod you will need a special version of the GNU toolchain, where the compiler is configured as a cross compiler. This is used to generate binaries on your development machine which are executable on another platform, in this case the iPod. Since the iPod is an ARM based platform we need an ARM cross compiler. Fortunately there are pre-built versions of the cross compiler available for Linux, OS X, and Windows (via Cygwin). If you need to customize the toolchain, you'll have to build it yourself.

Contents

Installing a pre-built toolchain

There are two versions of the toolchain: 2.95 and 3.4.3. They contain different versions of the compiler (gcc). While the 2.4.24 kernel, podzilla legacy and a few other old applications needs to be built with 2.95, many other apps need to be built with the newer version.

Note about installing both toolchains

These two toolchains can coexist on the same system, but you may need to remove the compatibility symlinks from the newer toolchain once you have installed it (Note: this applies only to Linux systems - for Mac OS X see the note further down):

rm -f /usr/local/arm-uclinux-tools2/bin/arm-elf-*

If you do this, be sure you set the HOST appropriately for each toolchain you want to use: arm-elf for 2.95, and arm-uclinux-elf for 3.4.3.

For the kernel (2.95 toolchain)

The arm-elf 2.95 toolchain is not for applications. This toolchain has several problems, namely:

  • C++ support is passable at best.
  • No i18n support.
  • Cannot handle constructs like anonymous structures.

The new version, arm-uclinux-elf 3.4.3, fixes all these issues (and is much more modern). Unfortunately, the Linux 2.4 kernel source doesn't quite agree with 3.4.3 so you need to apply this patch to the kernel source before you compile the kernel for the iPod.

If you are using a pre-compiled kernel (e.g. from a nightly build), you can skip this section.

If any of the links are nonresponsive, you can access them also through a mirror set up here: http://umlautllama.com/ipl/

After you have installed your toolchain, you must remember to export the path to your toolchain before you can start compiling things.

Linux on x86

Download:

http://www.uclinux.org/pub/uClinux/arm-elf-tools/arm-elf-tools-20030314.sh

Install the toolchain as root user:

sudo ./arm-elf-tools-20030314.sh

If you get the error message 'tail: cannot open `+43' for reading: No such file or directory' when installing, change line 39 from:

tail +${SKIP} ${SCRIPT} | gunzip | tar xvf -

to:

tail -n+${SKIP} ${SCRIPT} | gunzip | tar xvf -

Mac OS X on PPC

(Note: works only on PowerPC Macs, not on Intel Macs)

Download and run the installer:

http://prdownloads.sourceforge.net/ipodlinux/arm_elf_stl.pkg.tar?download

Note: If you should later install the 3.4.3 toolchain as well, the "arm-elf"-files in /usr/local/bin will get replaced with the new toolchain commands, meaning that you then cannot build the kernel with the 2.95 toolchain any more. While the 2.95 installer also creates its own private directory /usr/local/arm-elf/bin, it does miss out on placing a few needed files into that dir (e.g. objcopy is missing there). So I suggest you issue this command in Terminal after having used the above installer in order to preserve all tools of the 2.95 toolchain (this will then later allow you to refer to these copies to build the kernel):

cp /usr/local/bin/arm-elf-* /usr/local/arm-elf/bin

Cygwin on Windows on x86

Download the zip file:

http://prdownloads.sourceforge.net/ipodlinux/arm-elf-gcc.zip?download

It contains the entire folder hierarchy (/usr/local/...), so you need to extract this to your Cygwin root directory, making sure you do not replace the contents of existing directories but add the new files into them. Be advised that some people have reported instability in this toolchain.

See also: Using Cygwin

Other Systems

You must build the toolchain from source. See below for instructions.

For applications (3.4.3 toolchain)

For applications, you can use the more modern 3.4.3 arm-uclinux-elf toolchain; its advantages are above. If you are running a Linux or OS X system on x86 or PowerPC, then you can just download the toolchain in binary form. The x86 toolchain also works on AMD64 systems provided you have IA-32 compatibility libraries installed; this is the default on most AMD64 Linux distributions (on Gentoo, emerge emul-linux-x86-baselibs).

Note: You only need the first of the three files listed for each system. The others are for development purposes.

The files you need are:

If any links are nonresponsive, you might want to check the mirror at http://umlautllama.com/ipl/

The toolchain is hardcoded to live in /usr/local/. You can extract it there by executing all three files as root:

# sh ./arm-uclinux-elf-tools-base-gcc3.4.3-20050722.sh
# sh ./arm-uclinux-elf-tools-c++-gcc3.4.3-20050722.sh
# sh ./arm-uclinux-elf-tools-gdb-20050722.sh

If you get an error like, tail: cannot open `+43' for reading: No such file or directory or tail: Warning: "+number" syntax is deprecated, please use "-n +number", you need to change the line from

tail +${SKIP} ${SCRIPT} | bunzip2 | tar xvf -

to

tail -n+${SKIP} ${SCRIPT} | bunzip2 | tar xvf -

With a command like

# nano --nonewlines --noconvert arm-uclinux-elf-tools-base-gcc3.4.3-20050722.sh

Or, you may corrupt the file.

For the Cygwin one, you should do

# tar -C / -xvjf arm-uclinux-tools-cygwin-20060116.tar.bz2

If you are getting file not found errors from the cygwain tar then try appending another .tar to the end of above. For example:

# tar -C / -xvjf arm-uclinux-tools-cygwin-20060116.tar.bz2.tar

After you have installed your toolchain, you must remember to export the path to your toolchain before you can start compiling things.

Building your own toolchain

This is not recommended. It is far too easy to royally screw things up. Unless you have a really good reason not to, please stick with the prebuilt toolchains.
Also, these instructions are out of date - they're for 2.95. To build the 3.4.3 toolchain, see Building Toolchain.

Download all the files from here and this file into one directory. Extract all the archives. Follow the instructions in Kernel Building (up until the 'make dep' step) such that you have a patched 'linux-2.4.x' directory (rename the 'linux-2.4.24' directory to 'linux-2.4.x' and move it to the same directory as all the other above files).

When you have everything in place, edit build-uclinux-tools.sh (the 'edit' section). Put in the correct name for the uClinux source dir. If you want to install the toolchain in a different directory (e.g. /opt/arm-elf), put in a line like

PREFIX=/opt/arm-elf
PATH="${PREFIX}/bin:$PATH"; export PATH

If you are building on Cygwin, uncomment the Cygwin lines (lines 85 and 86). Now you can run build-uclinux-tools.sh.

If the script complains that it can't write to $PREFIX, create $PREFIX manually.

mkdir /opt/arm-elf

If you get an error from patch saying some file is locked in Perforce, you should set an environ var 'POSIXLY_CORRECT' to work around that, or unset your P4PORT env.

export POSIXLY_CORRECT=1
OR
export P4PORT=

If you get an error from patch saying that it can't find the file gcc-uclinux-elf.mak, add a line

touch STLport-4.5.3/src/gcc-uclinux-elf.mak

before

${PATCH} -p0 < STLport-4.5.3.patch

Setup your build environment

After you've installed your toolchain and before you start compiling, you must first export the path to your toolchain's executables. Note that you will need to do this every time you start terminal/command prompt (unless you permanently add it to PATH).

For the 2.95 toolchain (any OS), type:

% export PATH=/usr/local/bin:$PATH 

For the 3.4.3 toolchain, for Linux, type:

% export PATH=/usr/local/arm-uclinux-tools2/bin:$PATH 

For the 3.4.3 toolchain, for OS X, type:

% export PATH=/usr/local/arm-uclinux-tools/bin:$PATH 

For the 3.4.3 toolchain, for Cygwin, type:

% export PATH=/usr/local/arm-uclinux-elf-tools/bin:$PATH 

Debian / Ubuntu issues

On Ubuntu Linux (and possibly other Debian-based systems), attempting to run these tools under sudo (for example, in 'make install' steps) will fail with 'command not found', even when the above directory is in your path. This is because Debian's sudo package is compiled with the --with-secure-path option, which causes it to use a hard-coded path instead of your actual one.

The only known 'proper' fix is to recompile your own copy of sudo. As a workaround, you can add symlinks to the arm-uclinux tools to /usr/local/bin with this command:

sudo ln -s /usr/local/arm-uclinux-tools2/bin/arm-uclinux-elf-* /usr/local/bin/