crosstool
as suggested by the author(s) of the above link. The project seems to be
orphaned at version 0.43, circa Dec 2006. However it works well enough
with minor tweaks on a recent Linux installation (as of April 2009). One
important tweak is for the version of gcc on your host (build)
system; mine is 4.3.2, which is more modern than envisioned in
crosstool.
Once you download
crosstool-0.43.tar.gz, you can un-tar it somewhere convenient
to work.
wget http://www.kegel.com/crosstool/crosstool-0.43.tar.gz tar -xzf crosstool-0.43.tar.gzThe SR5 version of the NAS frimware is based on
gcc-3.4.3 and glibc-2.3.2 as well as Linux kernel
2.6.11, so the cross development environment of crosstool needs
to be configured for them. Subsequent releases of the firmware may be based on
different versions, so the suggestions below may need to be modified.
First, we must create a processor definition file. Crosstool
provides a number of
predefined ones, but none specific to the MPC8349 which is an e300 variant
of the PowerPC architecture. So you can create a definition file
crosstool-0.43/powerpc-8349.dat like this:
TARGET=powerpc-linux-gnu TARGET_CFLAGS="-O3 -pipe -fsigned-char -mcpu=603e -mpowerpc-gfxopt" GCC_EXTRA_CONFIG="--with-cpu=603e --enable-cxx-flags=-mcpu=603e"The gcc/glibc definition file that we'll use,
crosstool-0.43/gcc-3.4.3-glibc-2.3.2.dat, also needs a
modification (remove the lines that start with a "-" and insert the lines
that start with a "+"):
BINUTILS_DIR=binutils-2.15 GCC_DIR=gcc-3.4.3 GLIBC_DIR=glibc-2.3.2 -LINUX_DIR=linux-2.6.8 +LINUX_DIR=linux-2.6.11 LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0 GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.2 +SHELL=/bin/sh +GCC_CORE_DIR=gcc-3.3.6The reason for the change to the kernel version should be obvious, and will most likely change with the next release of the firmware. The
SHELL definition is for people like me who use an alternate shell;
the build process requires and assumes the Bourne shell. The final definition
was due to a build failure that was a bit of a pain to track down. However,
I found a fix for it
here.
Now you need to construct a script file that will pull it all together and
actually build your cross compiler environment. The stock
crosstool comes with a handful of redefined
demo-* files but none
of them will do the trick for us. But we can construct our own,
crosstool-0.43/demo-powerpc-8349.sh like this:
#!/bin/sh # Generated manually; do not forget to update # patches/glibc-2.3.2/glibc-2.3.3-allow-gcc-4.0-configure.patch # from 4.[01] to 4.[0-3] for newer GCC set -ex TARBALLS_DIR=$HOME/src/crosstool/downloads RESULT_TOP=$HOME/src/crosstool export TARBALLS_DIR RESULT_TOP GCC_LANGUAGES="c,c++" export GCC_LANGUAGES # Really, you should do the mkdir before running this, # and chown /opt/crosstool to yourself so you don't need to run as root. mkdir -p $RESULT_TOP eval `cat powerpc-8349.dat gcc-3.4.3-glibc-2.3.2.dat` sh all.sh --notestThere are some important choices in this file, you can change them to suit you and your system. Many people might choose to install crosstool into their
/opt filesystem. If you would like to do so, change
it to RESULT_TOP=/opt/crosstool. You may need to
sudo mkdir /opt/crosstool and then
sudo chown $USER /opt/crosstool if you choose to go this route.
When you're done, don't forget to
sudo chown -R root /opt/crosstool. I prefer to leave it in my
home directory so I don't clutter my system. Also, you might want to select
/tmp for the TARBALLS_DIR since you won't need them
once your build is finished.
Finally, as noted above, if your gcc is newer than 4.1.X, the
final order of business it to tweak the patch
crosstool-0.43/patches/glibc-2.3.2/glibc-2.3.3-allow-gcc-4.0-configure.patch.
This is a patch of a patch so it's tricky to describe. Here's the
original line to be fixed:
+ 3.[2-9]*|4.[01]*)to the following (depending on your version of
gcc you may need to
modify this):
+ 3.[2-9]*|4.[0-3]*)This tweak is necessary to avoid the confusing (and incorrect) later
configure failure:
"*** These critical programs are missing or too old: gcc".
At last, we are ready to build. It took me a while to get this far, but
everything should just work. Be forewarned - it will take a while. From the
diectory crosstool-0.43, start the build process:
sh demo-powerpc-8349.sh
One final note: if you are building for a newer GCC for some reason, then there
are a few more tricks that you need to know about. One is the following
powerpc-linux-gnu-gcc wrapper to deal with problems due to
unknown command line options
from the crossgcc compilation board at RedHat in
build//powerpc-linux-gnu/.../gcc-core-prefix/bin:
#!/bin/sh for arg; do case $arg in -Wold-style-definition) ;; -fno-unit-at-a-time) ;; -fvisibility=hidden) ;; *) newargs="$newargs $arg" ;; esac done powerpc-linux-gnu-gcc-3.3.6 $newargsThe trick here is that
crosstool will break in the middle of the
build, so you'll have to comment out the code that will try to delete this
file in both all.sh and crosstool.sh. Additionally,
autoconf and gcc's configure have gotten
too smart and crosstool.sh must be modified to
--- crosstool.sh.org 2006-12-06 14:17:40 +++ crosstool.sh 2009-06-04 00:13:28 @@ -603,3 +603,3 @@ # systems don't really need message catalogs... - ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --host=$GCC_HOST --prefix=$PREFIX \ + ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --prefix=$PREFIX \ ${GCC_EXTRA_CONFIG} \This removes the "--host=" option for the configure of the final gcc.
Zlib is an important compression shared library that is used by many projects. It is necessary for some of the later projects, so it should be built into our cross development environment.
wget http://www.zlib.net/zlib-1.2.3.tar.bz2 tar -xjf zlib-1.2.3.tar.bz2 cd zlib-1.2.3
I constructed a simple shell script to automate the build process for this
library, and that I will use as a skeleton for subsequent projects. I call it
doit.sh:
#!/bin/sh BASE=~/src/crosstool/gcc-3.4.3-glibc-2.3.2/powerpc-linux-gnu export CC=powerpc-linux-gnu-gcc export AR="powerpc-linux-gnu-ar rc" export PATH=$BASE/bin:$PATH ./configure --shared --prefix=$BASE/powerpc-linux-gnu \ --libdir=$BASE/powerpc-linux-gnu/lib \ --includedir=$BASE/powerpc-linux-gnu/include make all libz.a cp libz.a $BASE/powerpc-linux-gnu/libIf you chose to put
crosstool into /opt/crosstool,
then change the BASE variable to
BASE=/opt/crosstool/gcc-3.4.3-glibc-2.3.2/powerpc-linux-gnu.
Then simply execute doit.sh
in the zlib-1.2.3
directory:
sh doit.sh