Translations of this page?:

This page covers building a cross-compiling toolchain that is sufficient for kernel development. This does not cover building a toolchain required for userspace development.

Getting the Sources

Download the following packages (confirmed to build working kernels):

and extract them both (i.e. using tar xjf [filename]).

Building your toolchain

Now, let's build the toolchain we're going to use to build the kernel.

Preparing your environment

There are a few variables that are commonly used in the binutils/gcc that you can set as a part of your environment to make life easier. If you're using bash or another bourne shell lookalike:

export TARGET=mipsel-unknown-linux-gnu
export PREFIX=/opt/toolchain/${TARGET}

Note that you can change the value to mipsel-gdium-linux-gnu if you have multiple mipsel toolchains installed; as well, you can optionally put the toolchain somewhere other than /opt/toolchain; this is a matter of personal preference.

Building binutils

Now that binutils has been extracted and your environment has been setup, create a new directory (i.e. gdium-binutils) and switch to that as your cwd. Run the configure script that was extracted as a part of the binutils package in this directory. So, if you extracted binutils-2.19 into the same directory as the gdium-binutils directory:

I use a file “bin_utils_export_setup.sh” to set up the $TARGET and $PREFIX Global variables.

#!/bin/sh
export TARGET=mipsel-gdium-linux-gnu
#export PREFIX=/mnt/sdb5/gdium/toolchain/${TARGET}
export PREFIX=/opt/gdium/toolchain/${TARGET}
export PATH=${PATH}:${PREFIX}/bin
export C_INCLUDE_PATH=/usr/local/include
export LIBRARY_PATH="/usr/local/lib:/opt/gdium/lib"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LIBRARY_PATH}"
../binutils-2.19/configure --prefix=${PREFIX} --target=${TARGET}

Now you can do the traditional make && make install once the configure script has run through successfully.

In some distros (Ubuntu 8.10) you need this

export WARN_CFLAGS="-Wno-format-security"

if the build do not work correctly

Building a bootstrap GCC

GCC has a few more build options than binutils, but the process is very similar. Create, in the same directory as that where you extracted the gcc-4.3.3 sources, another directory (i.e. gdium-gcc) and switch to that directory. Next, append the ${TARGET}/bin directory to your PATH environment variable:

export PATH=${PATH}:${PREFIX}/bin

Next, run the configure script that was extracted as a part of the gcc package in this directory. So, if you had extracted gcc-4.3.3 in the same directory as the gdium-gcc directory:

../gcc-4.3.3/configure --prefix=${PREFIX} --target=${TARGET} \
    --enable-languages=c --without-headers --with-gnu-ld --with-gnu-as \
    --disable-shared --disable-threads --disable-libssp \
    --disable-libmudflap --disable-libgomp \
    --with-gmp=/usr/local --with-mpfr=/usr/local

And you can build and install your bootstrap gcc using the typical make && make install pair.

Build Errors?

this Gcc 4.3.3 requires more source libraries like GMP & MPFR see Prerequistes for GCC web page http://gcc.gnu.org/install/prerequisites.html to install GNU Multiple Precision Library (GMP) version 4.2 (or later) goto web page http://gmplib.org/ For MPFR Library version 2.3.2 (or later) The MPFR library is a C library for multiple-precision floating-point computations with correct rounding. It can be downloaded from http://www.mpfr.org/. Read the INSTALL file and run the update patches to the MPFR-2.4.1 source files.

It is strongly advised to apply the latest patches (if this has not been done yet), e.g.

   wget http://www.mpfr.org/mpfr-2.4.1/patches
   patch -N -Z -p1 < patches
 or
   curl http://www.mpfr.org/mpfr-2.4.1/patches | patch -N -Z -p1

Check the LD_LIBRARY_PATH settings with command export -p

You may have to add a couple extra configuration script options to the above ../gcc-4.3.3/configure when using the GMP & MPFG sources.

--disable-nls --enable-languages=c --without-headers --with-gmp=/usr/local --with-mpfr=/usr/local
  OR  
cd /usr/src
tar zxf gcc-4.3.3.tar.gz
tar zxf mpfr-2.3.1.tar.gz
tar zxf gmp-4.2.2.tar.gz
cd gcc-4.3.3
ln -s ../mpfr-2.3.1 ./mpfr
ln -s ../gmp-4.2.2 ./gmp
cd ..

# the following as per cross compiler article
[color=#FF0000]mkdir build
cd build
mkdir gcc
cd gcc[/color]
export PATH=$PATH:$PREFIX/bin
../gcc-4.3.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers --with-newlib
make all-gcc
make install-gcc

Read this article about cross compiling GCC 4.3.x using GMP and MPFR sources http://forum.osdev.org/viewtopic.php?f=8&t=17140&sid=90710a995a4b37571df988e552e2eee5&start=15

Prerequisites to building GCC http://gcc.gnu.org/install/prerequisites.html

Using your toolchain

To use your toolchain you just built to build a kernel, add the path to the bin/ directory where you set the prefix of the toolchain to be to your PATH environment variable. For example, in my case:

export PATH=${PATH}:/opt/toolchain/mipsel-gdium-linux-gnu/bin

Then, to build a kernel, in your kernel source directory:

make ARCH=mips CROSS_COMPILE=mipsel-gdium-linux-gnu- vmlinux modules

HINT: Sometimes it's easier to just build the tar-pkg target if you're planning on installing many modules as a part of your kernel build. Then you can just extract the tar file in the root directory of your Gkey.

HINT: If you want to set kernel configuration options using menuconfig, or run oldconfig on an older config, use the following:

make ARCH=mips menuconfig

This tells menuconfig/oldconfig to use the Kconfig files in arch/mips rather than the default for your host system (likely i386).

Caution: To build the gdium 2.6.24.5 linux kernel, this patch( mfix-gs2f-kernel.patch) is needed to build binutils-head. Otherwise the as will complain about “unrecognized option `-mfix-gs2f-kernel'”.

Links to other LOONGSON linux kernel source code

gNewSense to MIPSEL source


Personal Tools