release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide
translations



Search | Go
Wiki > Main > RockboxDevelopment > CrossCompiler

Building a cross compiler

Step 1: Gather information

Host environment

In this example it will be assumed that you are running Linux with the bash shell (or cygwin). We will only build the C compiler along with the assembler, linker and stuff. Note that the procedure is exactly the same if you are running cygwin on Windows, and on Macintosh OS X.

Find your target CPU

The Archos Jukebox and Ondio models have an SH-1 CPU, so the target name is sh-elf.

The iriver H-xxx, iAudio X5 and M5 models have a Coldfire CPU, so the target name is m68k-elf.

The iPod, iriver IFP-7x0, iriver H10, m:robe, Sansa e200/c200/fuze/clip, D2, YH-xxx and Gigabeat F/X/S builds have ARM cores, so the target name is arm-elf-eabi.


Step 2a: Automatic build

rockboxdev.sh

In the tools/ directory of your checked out Rockbox source code, there's this shell script called rockboxdev.sh that will perform the cross-compiler installation for you fully automatically.

When run, it will first prompt you for what architecture to build for, and then it'll proceed to download, unpack, build and install both binutils and the proper gcc version for you. If necessary it will even patch gcc accordingly.

All compilers are installed to /usr/local/bin, which is usually in your PATH already. If it isn't, add it to the .bashrc file in your home directory.

When using this script, you do not need to follow the rest of this instruction below this point. That is only for pure manual installation.

Note for Ubuntu users: you will need build-essential and texinfo installed: sudo apt-get install build-essential texinfo

Note for Ubuntu/Debian users: if rockboxdev.sh complains about missing libtool, you need to install libtool-bin: sudo apt-get install libtool-bin

Note for Cygwin users: the script may take up to 6-8 hours to complete, depending on your CPU

Note for systems that have /tmp in ram: change the temp path at the top of rockboxdev.sh to avoid running out of space

Below is a list of stuff that must be installed before starting:
  • gcc
  • g++
  • make
  • patch
  • perl
  • zip
  • gawk
  • bison
  • flex
  • automake
  • libtool
  • curl
  • texinfo
  • gmp

for arm-app (Samsung ypr0, ypr1) only:
  • subversion
  • libncurses5-dev


Step 2b: Manual build

Note that the automatic build using rockboxdev.sh is strongly recommended. If automatic building doesn't work, ask for help on the forums or raise a bug.

Note: These manual instructions describe how to build the SH-1 cross compiler (sh-elf). To build a ColdFire, or ARM compiler, substitute sh-elf with your target name from above in the --target parameter, and use another path in the --prefix parameter as well.

Instructions here might be obsolete. as nobody does it manually really.

Download the toolchain source code

You will need the following archives:

Target binutils gcc
Coldfire (m68k-elf) 2.16.1 (download, mirrors, info) 3.4.6 (download, mirrors, info)
ARM (arm-elf) 2.16.1 (download, mirrors, info) 4.0.3 (download, mirrors, info)
SH (sh-elf) 2.16.1 (download, mirrors, info) 4.0.3 (download, mirrors, info)
Mips (mipsel-elf) 2.17.1 (download, mirrors, info) 4.1.2 (download, mirrors, info)

(optional) gdb-6.6.tar.bz2 (download, mirrors, info)

Note: We know that there are newer versions of gcc/binutils available. See the last paragraph in this document.

Download any required patches for your host and target

Host Target Patch Comments
All sh-elf gcc-4.0.3-rockbox-1.diff  
Cygwin & Mac OS X m68k-elf gcc-3.4.6.patch  
Linux AMD64 m68k-elf gcc-3.4.6-amd64.patch  
All arm-elf rockbox-multilibs-arm-elf-gcc-4.0.3.diff Enables multilibs for Thumb and different ARM architectures.

NOTE: rockboxdev.sh downloads these patches automatically - you do not need to download them separately if you're running rockboxdev.sh

Target-specific notes:

Coldfire (iAudio, iRiver)

Note: For better (read: smaller) code, apply the patch gcc-3.4.6-rockbox-2.diff below. It changes how gcc selects between using multiplication and shift-and-add for some calculations. (It is a bit of a hack, because it affects more target CPU models than it should. Not a problem as long as you only use the compiler for Rockbox development.) - MagnusHolmgren

Host specific notes

  • Binutils needs flex installed in order to compile. On Mandrake I did urpmi flex
  • Binutils require gettext, bison, and m4 installed to compile (urpmi gettext, urpmi bison, and urpmi m4 on Mandrake, apt-get install gettext and bison and m4 on Debian)

(OS X) start the bash shell

   [Linus-Computer:~] linus% bash

Unpack the archives

(some may need to get the sources off CVS servers, as noted above)

   /home/linus> tar xvjf binutils-2.16.1.tar.bz2
   /home/linus> tar xvjf gcc-core-4.0.3.tar.bz2
   /home/linus> tar xvjf gdb-6.6.tar.bz2

Apply patches if necessary (see the table above)
   /home/linus> patch -p0 <gcc-4.0.3-rockbox-1.diff

Create the build tree

   /home/linus> mkdir build
   /home/linus> cd build
   /home/linus/build> mkdir binutils
   /home/linus/build> mkdir gcc
   /home/linus/build> mkdir gdb

Choose installed location

Now is the time to decide where you want the tools to be installed. This is the directory where all binaries, libraries, man pages and stuff end up when you do "make install".

In this example I have chosen "/home/linus/sh1" as my installation directory, or prefix as it is called. Feel free to use any prefix, like /usr/local/sh1 for example.

Build binutils

We will start with building the binutils (the assembler, linker and stuff). This is pretty straightforward. We will be installing the whole tool chain in the /home/linus/sh1 directory.

If you are building on a Macintosh OS X machine, you have to disable the precompiled headers:
   /home/linus> export CC="gcc -no-cpp-precomp"
Then configure, make and install:
   /home/linus> cd build/binutils
   /home/linus/build/binutils> ../../binutils-2.16.1/configure --target=sh-elf --prefix=/home/linus/sh1
   /home/linus/build/binutils> make
   /home/linus/build/binutils> make install

Build GCC

Now you are ready to build GCC. To do this, you must have the newly built binutils in the PATH.

Then set the PATH, configure and make:
   /home/linus> export PATH=/home/linus/sh1/bin:$PATH
   /home/linus> cd build/gcc
   /home/linus/build/gcc> ../../gcc-4.0.3/configure --target=sh-elf --prefix=/home/linus/sh1 --enable-languages=c
   /home/linus/build/gcc> make
   /home/linus/build/gcc> make install

Build GDB

If you are planning to debug your code with GDB, you have to build it as well.

   /home/linus> cd build/gdb
   /home/linus/build/gdb> ../../gdb-6.6/configure --target=sh-elf --prefix=/home/linus/sh1
   /home/linus/build/gdb> make
   /home/linus/build/gdb> make install

NOTE: If you are using GNU/Linux Ubuntu 8.10, you need to add the option "--disable-werror" to configure, like this:
   /home/linus/build/gdb> ../../gdb-6.6/configure --target=sh-elf --prefix=/home/linus/sh1 --disable-werror

(Debian) Termcap dependency problems

If you're using a Debian-based distribution, you may run into problems with termcap dependencies (see http://packages.debian.org/stable/oldlibs/termcap-compat).

A workaround for this is to build termcap libs before building GDB:

   /home/linus> tar zxvf termcap-1.3.1.tar.gz
   /home/linus> cd termcap-1.3.1
   /home/linus/termcap-1.3.1> ./configure --prefix=/home/linus/sh1
   /home/linus/termcap-1.3.1> make
   /home/linus/termcap-1.3.1> make install
The final step did produce errors as it tried to remove existing header files from /usr/include, so beware, and don't run as root.

Now go ahead and make GDB.

Done

If someone up there likes you, you now have a working tool chain.

Good luck!

Linus

Why don't you use version X.Y.Z of the compiler?

Because the versions we use now works. We upgrade when it becomes necessary. Here's a small summary of some other versions we have tried:

  • GCC 3.4.6 does not build iRiver targets when binutils-2.17 is installed. Therefore we don't use it.
  • GCC 4.0.x seems to work fine when building Rockbox for Coldfire platforms. For the time being, it is not the recommended or preferred version to use. It should generate valid binaries, though, but it is quite untested. Some codecs might fail to build due to the fact that 4.0.x generates larger code, and sometimes crashes are observed.
  • GCC 4.1.0 is not able to build Rockbox correctly (it currently fails on some inline assembly and with the Tremor codec). You may also experience problems during the 4.1.0 cross compiler build; if so using the option "--enable-libssp=no" during configure should help.

I Attachment Action Size Date Who Comment
gcc-3.3.6-rockbox-1.diffdiff gcc-3.3.6-rockbox-1.diff manage 1.7 K 11 Jul 2006 - 21:12 JensArnold Gcc 3.3.6 patch, fixes SH builds with -O2 / -Os
gcc-3.4.4.patchpatch gcc-3.4.4.patch manage 0.6 K 11 Jul 2006 - 21:12 JensArnold Patch for failed cygwin coldfire builds (gcc 3.4.4
gcc-3.4.6-amd64-subst.patchpatch gcc-3.4.6-amd64-subst.patch manage 0.8 K 26 Sep 2006 - 19:12 JensArnold Patch for building m68k-elf-gcc 3.4.6 on AMD64 (somewhat hackish)
gcc-3.4.6-amd64.patchpatch gcc-3.4.6-amd64.patch manage 1.2 K 29 Jun 2007 - 09:42 BjornStenberg Backport of the patch for GCC bug 28911. It fixes cross compiler build for m68k-elf on x86_64 hosts.
gcc-3.4.6-rockbox-1.diffdiff gcc-3.4.6-rockbox-1.diff manage 1.7 K 11 Jul 2006 - 21:12 JensArnold Gcc 3.4.6 patch, fixes SH builds with -O2 / -Os
gcc-3.4.6-rockbox-2.diffdiff gcc-3.4.6-rockbox-2.diff manage 1.4 K 04 Jun 2007 - 20:50 MagnusHolmgren Gcc 3.4.6 patch. Improves code generation. Does not include gcc-3.4.6-rockbox-1.diff.
gcc-3.4.6.patchpatch gcc-3.4.6.patch manage 0.6 K 10 Aug 2006 - 22:38 BarryWardell Patch for failed macos m68k builds (gcc-3.4.6)
gcc-4.0.3-rockbox-1.diffdiff gcc-4.0.3-rockbox-1.diff manage 1.7 K 11 Jul 2006 - 21:12 JensArnold Gcc 4.0.3 patch, fixes SH builds with -O2 / -Os
gcc.patchpatch gcc.patch manage 0.4 K 11 Jul 2006 - 21:12 LinusNielsenFeltzing Patch for failed cygwin Coldfire builds
rockboxdev-3.patchpatch rockboxdev-3.patch manage 0.8 K 10 Aug 2006 - 23:08 BarryWardell Patch for failed macos m68k builds (gcc-3.4.6)
r109 - 02 May 2022 - 16:52:53 - AidanMacDonald

Copyright © by the contributing authors.