Cross Compilers
Background
There are several ways to build a cross compiler for an embedded system most people use a prepackaged compiler however when none is available or you need a later version. I turn to crosstool. Crosstool is a script written to aid in the build process of a GCC cross compiler. The website is at http://www.kegel.com/crosstool/.
Building a Cross Compiler
It's actually fairly easy to build a cross compiler however I must warn you that it takes an outrageous amount of time. On our 3 Ghz Pentium D it takes about 3 hours.
Prerequisites
Make sure that your build system has flex, bison and all neccesary tools to build software from source
On Debian 4.0,
sudo apt-get install flex bison build-essential
On Red Hat 5.2,
sudo yum groupinstall 'Development Tools'
Now we need to setup a directory for the cross compiler to install into the default is /opt/crosstool and you should replace USER_NAME with your actual username.
sudo mkdir /opt/crosstool/ # create the crosstool directory
sudo chown -r USER_NAME /opt/crosstool # Makes you the owner of the /opt/crosstool/directory
chmod u+rwx /opt/crosstool/ # Allow your user the ability to read, write and execute in the /opt/crosstool directory.
chmod a+rx /opt/crosstool/ # Allow everyone else to execure the binaries in the /opt/crosstool directory.
Download and Install
These commands will download, unpack the crosstool script, and start the build process for a powerpc-405 cross compiler.
wget http://www.kegel.com/crosstool/crosstool-0.43.tar.gz
tar xzf crosstool-0.43.tar.gz
cd crosstool-0.43
./demo-powerpc-405.sh
Make it easier to use.
Right now in order to use the cross compiler you'd have type an insanely long path name. However, by adding two lines to your ~/.bashrc you can cross-compile just as easy as native compiling.
edit ~/.bashrc add the following lines
# PowerPC Cross Compiler aliases
export PATH=$PATH:/opt/crosstool/gcc-4.1.0-glibc-2.3.6/powerpc-405-linux-gnu/bin
alias ppckmake="make ARCH=powerpc CROSS_COMPILE=powerpc-405-linux-gnu-"
alias ppcmake="make CC=powerpc-405-linux-gnu-gcc"
Using the Cross Compiler
Compiling the linux kernel is as simple as
ppckmake menuconfig
or
ppckmake simpleImage.virtex405-xupv2p
And compiling any standard piece of software is as easy as
ppcmake <target>