Linux Toolchain
Here is a simple way to get started with the Linux open source toolchain for MIPS. This is referred to as target mipsel-linux-gnu. The C library is from egibc.
We provide a prebuilt binary package that you can download and use.
A source package and command file is provided with which you can build your own custom toolchain. This package can also be modified and various components exchanged for newer/older versions.
Components
The toolchain is built with the following components:
If you want to build your own toolchain or, to configure it differently you can follow the instructions on this page. When you build your own toolchain you can also substitute different versions of the above components. All instructions assume the Bash shell.
Using The Pre-Built Toolchain
You can download the prebuilt package, unpack it, set your path to it’s top level bin directory and begin to use it. If you unpack the package to a folder different from “/opt“, you will have to manually point to the sysroot folder using “–sysroot” command line option on each gcc invocation.
1. Download this tar file: Mips_linux_toolchain_bin-1.1.tar.bz2
2. Unpack the tar file to the /opt folder:
cd /opt
tar vfxj Mips_linux_toolchain_bin-1.1.tar.bz2
3. Add the bin folder to the path:
export PATH=/opt/mips_linux_toolchain/bin:$PATH
Running QEMU standalone and with gdb
Build a simple hello world:
mips-linux-gnu-gcc -g hello.c -o hello -static
Run with QEMU:
qemu-mips hello
Run with qemu under the control of gdb
qemu-mips -g 1234 hello &
mips-linux-gnu-gdb hello
target remote :1234
break main
step
step
step
kill
quit
y
Building a Toolchain from Source
Various components must be installed on your computer before proceeding, if they are not already there. http://gcc.gnu.org/install/prerequisites.html
In general you will receive the proper warning if you are missing some component but not always so it’s good to read through the list.
1. Download this tar file: Mips_linux_toolchain_src-1.1.tar.bz2
2. Unpack the tar file:
tar vfxj Mips_toolchain_src-1.1.tar.bz2
3. Run the build script (DIR is a folder where you want to install the toolchain):
./build-mips-sde-elf.sh --prefix=DIR
Build Options
To get a full list of build options run the build script with help command: ./build-mips-linux-gnu.sh help.
Usage: build-mips-linux-gnu.sh [OPTIONS] COMMANDS
COMMANDS
buildall run all building stages from unpack to check
download check packages and download missed ones
cleanup remove source, build and aux dirs
help print this help message
unpack unpack packages
buildgmp build GMP library
buildmpfr build MPFR library
buildmpc build MPC library
buildbinutils build Binutils
buildgcc1 build GCC phase I
installheaders install Linux headers
buildeglibc1 build eglibc headers and preliminary objects
buildgcc2 build GCC phase II
buildeglibc2 build eglibc libraries
buildgcc3 build GCC phase III
buildlibgcc build libgcc
buildexpat build expat
buildgdb build GDB
buildqemu build QEMU
check run set of simple tests
OPTIONS
-h, --help print this help message
-p, --prefix=DIR use DIR as an installation prefix
-d, --download=DIR lookup packages tarballs in the DIR
-s, --source=DIR use DIR to unpack packages tarballs
-b, --build=DIR use DIR as a build directory
-j, --jobs=NUM run NUM make jobs simultaneously
ENVIRONMENT
You can override default packages versions using the following environment
variables. For example 'GMP_VER=5.5.5 build-mips-linux-gnu.sh'.
GMP_VER gmp library version
MPC_VER mpc library version
MPFR_VER mpfr library version
BINUTILS_VER binutils version
GCC_VER gcc version
LINUX_VER linux kernel
EGLIBC_VER eglibc library version
EXPAT_VER expat library version
GDB_VER gdb version
QEMU_VER qemu version
By default, the build script searches packages in the ./dl folder and creates the following auxiliary folders:
./bld/
./install/
./src/
You should point to the installation folder using either –prefix command line option or PREFIX environment variable:
./build-mips-linux-gnu.sh --prefix=DIR
export PREFXI=DIR
./build-mips-linux-gnu.sh
If you want to use different version of components, you can override default settings using environment variables. For example, the following command builds the toolchain using gcc 4.6.1 and gdb 7.3.1:
GCC_VER=4.6.1 \
GDB_VER=7.3.1 \
./build-mips-linux-gnu.sh --prefix=DIR
Default component’s versions are:
GMP_VER=4.3.2
MPC_VER=0.9
MPFR_VER=3.0.1
BINUTILS_VER=2.21
GCC_VER=4.4.6
LINUX_VER=2.6.32.27
EGLIBC_VER=2_14
EXPAT_VER=2.0.1
GDB_VER=7.2
QEMU_VER=0.15.0