|
Building a cross compiler
Step 1: Gather information
Host environment
In this example I will assume 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, Sansa e200/c200 and Gigabeat F/X builds have ARM cores, so the target name is arm-elf
Note: The rest of this tutorial describes how to build the SH-1 cross compiler. 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.
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.
Once this is done, you will have to make sure that the toolchains you've installed are available to the environment via the PATH variable. You can change this in a number of places, but the recommended one (assuming you're using bash as your shell) would be your ~/.bashrc file. Add a line to the end of the file that looks like this :
export PATH=$PATH:/usr/local/arm-elf/bin:/usr/local/m68k-elf/bin:/usr/local/sh-elf/bin
If you've only installed some of the toolchain, you should remove the sections between "::" that you've not installed.
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 installed:
sudo apt-get install build-essential
Step 2b: Manual build
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) |
|---|
(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
(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
(Gentoo) Gentoo Crossdev
Gentoo Linux includes a script called sys-devel/crossdev that automatically builds and installs a cross compiler environment. As it uses the portage tree exactly the versions that are available to emerge can be used by crossdev. So, if you have eix installed you can easily check which versions of the tools are available.
Install eix
# emerge -av eix
List available binutils versions
# eix -e binutils
List available gcc versions
# eix -e gcc
Install crossdev
# emerge -av crossdev
Now install the desired cross compiling environment with the versions you found. For example for binutils 2.16.1-r3 and gcc 3.4.5-r1 this does the job
# crossdev -s1 --binutils 2.16.1-r3 --gcc 3.4.5-r1 --target m68k-elf
You can check that everything went okay by looking for the resulting top level directories, as they represent the version number
# ls /usr/i686-pc-linux-gnu/m68k-elf/binutils-bin
# ls /usr/i686-pc-linux-gnu/m68k-elf/gcc-bin
Take care, that the version you request is really available in the portage tree. For example, an earlier wiki page told you to use these versions
# crossdev -s1 --binutils 2.16.1-r2 --gcc 3.4.5-r1 --target m68k-elf
At the time of this writing binutils 2.16.1-r2 is no longer in the portage tree, but replaced by 2.16.1.r3. As crossdev will install the latest version up to the requested, 2.16.1-r2 in that case, it would in fact install 2.15.1 without really telling you about that. And 2.15.1 would result in a failure to compile.
Finally include the gcc bin directory into your PATH, for example for gcc 3.4.5.
# PATH=/usr/i686-pc-linux-gnu/m68k-elf/gcc-bin/3.4.5:$PATH
You can now change into your Rockbox source directory and continue there with the normal compile process.
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 © 1999-2008 by the contributing authors.
|
|