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
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.
Copyright © by the contributing authors.