Building a MIPS cross toolchain

Cross compiling userspace is very complicated and mostly unneeded as not time is the difficult factor but bootstrapping on a new system. We need a cross-compiler only for kernel building purposes wheres we start like bootstrapping for a new architecture. We are doing a cross-toolchain here - step-by-step.

debian toolchain-source

Install the toolchain-source package via apt e.g. apt-get install toolchain-source. Change into a directory with enough space to build gcc + binutils. Issue a tpkg-make mips-linux or tpkg-make mipsel-linux. Enter the binutils directory issue a debuild and install the resulting package. Then change into the gcc directory and change the debian/rules file from --enable-shared to --disable-shared. Then start debuild and install the resulting package.

binutils

Building cross-binutils has never been a problem and probably will never be one. Just get your favorite version of binutils. I am using the debian source package. Get the package by issuing an apt-get source binutils.

flo@split:~/xdevel$ apt-get source binutils Reading Package Lists... Done Building Dependency Tree... Done Need to get 8526kB of source archives. Get:1 http://source.rfc822.org sid/main binutils 2.12.90.0.1-4 (dsc) [827B] Get:2 http://source.rfc822.org sid/main binutils 2.12.90.0.1-4 (tar) [8334kB] Get:3 http://source.rfc822.org sid/main binutils 2.12.90.0.1-4 (diff) [191kB] Fetched 8526kB in 10m6s (14.1kB/s) dpkg-source: extracting binutils in binutils-2.12.90.0.1 flo@split:~/xdevel$ cd binutils-2.12.90.0.1/ flo@split:~/xdevel/binutils-2.12.90.0.1$ debian/rules stampdir/patch test -d stampdir || mkdir stampdir touch stampdir/created mkdir -p stampdir/sources build-tree stampdir/log/sources Extracting source binutils-2.12.90.0.1.tar.bz2 ... [...] flo@split:~/xdevel/binutils-2.12.90.0.1$ cd build-tree/binutils-2.12.90.0.1/ flo@split:~/xdevel/binutils-2.12.90.0.1/build-tree/binutils-2.12.90.0.1$ flo@split:~/xdevel/binutils-2.12.90.0.1/build-tree/binutils-2.12.90.0.1$ ./configure \ --prefix=/usr/local --target=mips-linux --disable-shared --disable-nls [...]

Now continue issueing a make and make install. I prefer installing into a stow directory to be able to have different binutils in the path. I do so be make install prefix=/usr/local/stow/mips-linux-binutils-2.12.90.

gcc

Depending on the gcc or egcs version you need different parameters and steps to get a gcc which does not need libc and/or headers. You need to have the just built mips-linux-as, mips-linux-ld and others in the path to continue building the gcc. Here are some compilers i used:

egcs 1.1.2

Get the egcs 1.1.2 + patches prefereably from from oss.sgi.com.

flo@split:~/xdevel$ tar -jxf egcs-1.1.2.tar.bz2 flo@split:~/xdevel$ cd egcs-1.1.2 flo@split:~/xdevel/egcs-1.1.2$ zcat ../egcs-1.1.2.diff.gz | patch -p1 -E -s flo@split:~/xdevel/egcs-1.1.2$ ./configure --prefix=/tmp/ct --with-newlib --target=mipsel-linux flo@split:~/xdevel/egcs-1.1.2$ make SUBDIRS="libiberty texinfo gcc" ALL_TARGET_MODULES= \ CONFIGURE_TARGET_MODULES= INSTALL_TARGET_MODULES= LANGUAGES="c"

gcc 2.95.4 (debian woody)

gcc 2.95.4 is from my experience the most tricky to build cross compiler - nothing works as before or after gcc 2.95. Here is how i did it:

flo@dump:/tmp$ apt-get source gcc-2.95 Reading Package Lists... Done Building Dependency Tree... Done Need to get 15.0MB of source archives. Get:1 http://source.rfc822.org woody/main gcc-2.95 2.95.4.ds11-7 (dsc) [1397B] Get:2 http://source.rfc822.org woody/main gcc-2.95 2.95.4.ds11-7 (tar) [14.6MB] Get:3 http://source.rfc822.org woody/main gcc-2.95 2.95.4.ds11-7 (diff) [404kB] Fetched 3B in 0s (4B/s) dpkg-source: extracting gcc-2.95 in gcc-2.95-2.95.4.ds11 flo@dump:/tmp$ cd gcc-2.95-2.95.4.ds11/ flo@dump:/tmp/gcc-2.95-2.95.4.ds11$ debian/rules patch [...] flo@dump:/tmp/gcc-2.95-2.95.4.ds11$ cd src-native/ flo@dump:/tmp/gcc-2.95-2.95.4.ds11/src-native$ ./configure --target=mipsel-linux \ --disable-threads --disable-nls --without-shared --enable-languages=c --without-headers --with-newlib --prefix=/usr/local [...] flo@dump:/tmp/gcc-2.95-2.95.4.ds11/src-native$ make all-gcc flo@dump:/tmp/gcc-2.95-2.95.4.ds11/src-native$ make install-gcc \ prefix=/usr/local/stow/gcc-2.95.4.ds11-mipsel

gcc 3.1 (prerelease)

Get your compiler sources from the debian source repository with apt-get source gcc-snapshot but beware - currently (2002-04-28) you need sid in your deb-src lines.

flo@split:~/xdevel$ apt-get source gcc-snapshot [...] flo@split:~/xdevel$ cd gcc-snapshot-20020426 flo@split:~/xdevel/gcc-snapshot-20020426$ debian/rules patch flo@split:~/xdevel/gcc-snapshot-20020426$ cd src flo@split:~/xdevel/gcc-snapshot-20020426/src$ ./configure --prefix=/usr/local \ --target=mips-linux --disable-shared --disable-nls --enable-languages=c \ --with-as=/usr/local/bin/mips-linux-as --with-ld=/usr/local/bin/mips-linux-ld --with-ar=/usr/local/bin/mips-linux-ar --with-nm=/usr/local/bin/mips-linux-nm \ --with-objdump=/usr/local/bin/mips-linux-objdump

Now continue running make and make install - If you are using stow like i do run make install prefix=/usr/local/stow/mips-linux-gcc-20020416.

gcc 3.3.4

Get your compiler sources from the debian source package with apt-get source gcc-3.3.4 but beware - You need to satisfy some build-depends to actually be able to apply all patches cleanly. Issue a "debian/rules patch" and change to the src directory.

flo@heisenberg:~/toolchain/build/gcc-3.3-3.3.4/src$ ./configure --disable-threads \ --disable-shared --disable-nls --with-newlib --enable-haifa \ --enable-languages=c --enable-hacker-mode --without-headers \ --prefix=/home/flo/toolchain/20040924-mips-linux/ --target=mips-linux [...] flo@heisenberg:~/toolchain/build/gcc-3.3-3.3.4/src$ make SUBDIRS="libiberty gcc" [...] flo@heisenberg:~/toolchain/build/gcc-3.3-3.3.4/src$ make SUBDIRS="libiberty gcc" install [...]

gcc 3.4.3

I took the debian 3.4 source package via apt-get source gcc-3.4. Issue a debian/rules patch and change to the src directory.

flo@source:~/toolchain/build/gcc-3.4-3.4.3/src$ ./configure --prefix=/home/flo/toolchain/20050116-mips64-linux \ --target=mips64-linux --disable-threads --disable-nls --disable-shared --enable-languages=c --without-headers --with-newlib [...] flo@source:~/toolchain/build/gcc-3.4-3.4.3/src$ make all-gcc [...] flo@source:~/toolchain/build/gcc-3.4-3.4.3/src$ make install-gcc [...]
-->