ELF (Bare Metal)

Here is a simple way to get started with the open source ELF (bare metal) toolchain for MIPS. This is referred to as target mips-sde-elf.

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:

binutilshttp://www.gnu.org/software/binutils
gcchttp://gcc.gnu.org
gdbhttp://www.gnu.org/software/gdb
gmphttp://gmplib.org
mpchttp://www.multiprecision.org
mpfrhttp://www.mpfr.org
newlibhttp://sourceware.org/newlib

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.

1. Download this tar file: Mips_toolchain-4.4.6-bin.tar.bz2
2. Unpack the tar file:

tar vfxj Mips_toolchain-4.4.6-bin.tar.bz2

3. Add the bin folder to the path:

export PATH=`pwd`/bin:$PATH

 

Running under emulator and gdb

The build script compiles simple hello world program, runs it and debugs it to check that the toolchain built successfully. You can do it by yourself.

Create linker script:

sed 's/"elf32-littlemips", "elf32-bigmips", "elf32-littlemips"/"elf32-tradlittlemips", "elf32-tradbigmips", "elf32-tradlittlemips"/' \
./src/newlib-1.19.0/libgloss/mips/idt32.ld > sde32.ld

 

Build a simple hello world:

mips-sde-elf-gcc -T./sde32.ld hello.c -o hello -g

 

Run with emulator:

mips-sde-elf-run hello

 

Run under the control of gdb

mips-sde-elf-gdb hello
break main
target sim
load
run
next
next
next
next
quit

 

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_toolchain-4.4.6.tar.bz2
2. Unpack the tarball:

tar vfxj Mips_toolchain-4.4.6.tar.bz2

3. Set PREFIX to where you want to install the toolchain.
4. Run the build script:

./build-mips-sde-elf.sh

 

Substituting Components

The installation source tar file is the following structure:

build-mips-sde-elf.sh
dl/
binutils-2.21.tar.bz2  gmp-4.3.2.tar.bz2       newlib-1.19.0.tar.gz
gcc-4.4.6.tar.bz2      mpc-0.9.tar.gz
gdb-7.2.tar.bz2        mpfr-3.0.1.tar.bz2

 

Additional subdirectories are created for the build:

bld/
install/
src/

 

You can put different version of those components in the dl subdirectory as long as you make the change to the beginning of build-mips-linux-gnu.sh where the version numbers for each component are defined. You will also need to make a change to the “tar” command that unpacks that component if you substitute a different packed kind, i.e gz vs bz2.

gmp_base="gmp-4.3.2"
mpc_base="mpc-0.9"
mpfr_base="mpfr-3.0.1"
binutils_base="binutils-2.21"
gcc_base="gcc-4.4.6"
newlib_base="newlib-1.19.0"
gdb_base="gdb-7.2"