[[mips_cross_compiler]]

This is an old revision of the document!


Commercial Version

There is a commercial free version available from Mentor Graphics.

Sourcery CodeBench Lite Edition

Build from source

What we need:

From a bare ubuntu 12.04 LTS you need to add the following packages:

sudo apt-get install build-essential m4

Here is the shell script for building the cross compiler chain. Handmade stuff so you need to adapt. The script will build to a place in your home directory. So first add this place to your PATH variable.

build_mips.sh
#!/bin/bash -ev
# -e => exit on error
# -v => verbose output
 
# YOU MUST APPEND THAT to your .profile file
# export PATH=$HOME/site/bin:$PATH
 
# Mips Cross Compiler
 
# Base directory
mkdir -p mips
# src directory
mkdir -p mips/src
# build directory
mkdir -p mips/build
# original archives
mkdir -p mips/orig
 
# Set the destination directory
export MYMIPS=$HOME/site
 
# Versions
GMPVERSION=4.3.2
PPLVERSION="0.12.1"
BINUTILSVERSION="2.23.2"
MPFRVERSION="2.4.2"
MPCVERSION="1.0.1"
ISLVERSION="0.11.1"
CLOOGVERSION="0.18.0"
GCCVERSION="4.8.0"
NEWLIBVERSION="1.20.0"
GDBVERSION="7.5.1"
 
# Get the archives
cd mips/orig 
if [ ! -e "gmp-4.3.2.tar.bz2" ] ; then
  wget http://ftp.halifax.rwth-aachen.de/gnu/gmp/gmp-4.3.2.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "gmp-4.3.2" ] ; then
tar -xjvf ../orig/gmp-4.3.2.tar.bz2
fi 
 
# Build
cd ../build
mkdir -p gmp
cd gmp
if [ ! -e "config.status" ] ; then	
../../src/gmp-4.3.2/configure --prefix=$MYMIPS --enable-cxx
fi
if [ ! -e "${MYMIPS}/lib/libgmp.a" ] ; then
make
make install
fi
cd ../../..
 
 
# Get the archives
cd mips/orig 
if [ ! -e "ppl-${PPLVERSION}.tar.bz2" ] ; then
  wget ftp://ftp.cs.unipr.it/pub/ppl/releases/${PPLVERSION}/ppl-${PPLVERSION}.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "ppl-${PPLVERSION}" ] ; then
tar -xjvf ../orig/ppl-${PPLVERSION}.tar.bz2
fi 
 
cd ../build
mkdir -p ppl
cd ppl
if [ ! -e "config.status" ] ; then
../../src/ppl-${PPLVERSION}/configure --prefix=$MYMIPS --with-gmp=$MYMIPS --with-sysroot=$MYMIPS
fi
if [ ! -e "${MYMIPS}/lib/libppl.a" ] ; then
make 
make install
fi
cd ../../..
 
########################################
# Binutils
########################################
 
# Get the archives
cd mips/orig 
if [ ! -e "binutils-${BINUTILSVERSION}.tar.bz2" ] ; then
  wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVERSION}.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "binutils-${BINUTILSVERSION}" ] ; then
tar -xvjf ../orig/binutils-${BINUTILSVERSION}.tar.bz2
fi 
 
cd ../build
mkdir -p binutils
cd binutils
if [ ! -e "config.status" ] ; then
../../src/binutils-${BINUTILSVERSION}/configure --target=mipsel-none-elf \
--prefix=$MYMIPS \
--with-ppl=$MYMIPS  
fi
 
if [ ! -e "${MYMIPS}/bin/mipsel-none-elf-ld" ] ; then
make
make install
fi
cd ../../..
 
######################################
# MPFR library
#######################################
 
# Get the archives
cd mips/orig 
if [ ! -e "mpfr-${MPFRVERSION}.tar.bz2" ] ; then
  wget http://ftp.halifax.rwth-aachen.de/gnu/mpfr/mpfr-${MPFRVERSION}.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "mpfr-${MPFRVERSION}" ] ; then
tar -xvjf ../orig/mpfr-${MPFRVERSION}.tar.bz2
fi
 
cd ../build
mkdir -p mpfr
cd mpfr
if [ ! -e "config.status" ] ; then
../../src/mpfr-${MPFRVERSION}/configure --prefix=$MYMIPS --with-gmp=$MYMIPS 
fi
 
if [ ! -e "${MYMIPS}/lib/libmpfr.a" ] ; then
make
make install
fi
cd ../../.. 
 
######################################
# MPC library
#######################################
 
# Get the archives
cd mips/orig 
if [ ! -e "mpc-${MPCVERSION}.tar.gz" ] ; then
  wget http://ftp.halifax.rwth-aachen.de/gnu/mpc/mpc-${MPCVERSION}.tar.gz
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "mpc-${MPCVERSION}" ] ; then
tar -xvzf ../orig/mpc-${MPCVERSION}.tar.gz
fi
 
cd ../build
mkdir -p mpc
cd mpc
if [ ! -e "config.status" ] ; then
../../src/mpc-${MPCVERSION}/configure --prefix=$MYMIPS --with-gmp=$MYMIPS --with-mpfr=$MYMIPS
fi
 
if [ ! -e "${MYMIPS}/lib/libmpc.a" ] ; then
make
make install
fi
cd ../../.. 
 
 
 
##############
# ISL
##############
 
# Get the archives
cd mips/orig 
if [ ! -e "isl-${ISLVERSION}.tar.bz2" ] ; then
  wget  ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-${ISLVERSION}.tar.bz2
fi
 
 
# Unpack to source directory
cd ../src
if [ ! -d "isl-${ISLVERSION}" ] ; then
tar -xvjf ../orig/isl-${ISLVERSION}.tar.bz2
fi
 
cd ../build
mkdir -p isl
cd isl
if [ ! -e "config.status" ] ; then
../../src/isl-${ISLVERSION}/configure --prefix=$MYMIPS --with-gmp-prefix=$MYMIPS 
fi
 
if [ ! -e "${MYMIPS}/lib/libisl.a" ] ; then
make
make install
fi
cd ../../.. 
 
##############
# CLOOG
##############
 
# Get the archives
cd mips/orig 
if [ ! -e "cloog-${CLOOGVERSION}.tar.gz" ] ; then
  wget  ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-${CLOOGVERSION}.tar.gz
fi
 
 
# Unpack to source directory
cd ../src
if [ ! -d "cloog-${CLOOGVERSION}" ] ; then
tar -xvzf ../orig/cloog-${CLOOGVERSION}.tar.gz
fi
 
cd ../build
mkdir -p cloog
cd cloog
if [ ! -e "config.status" ] ; then
../../src/cloog-${CLOOGVERSION}/configure --prefix=$MYMIPS --with-gmp-prefix=$MYMIPS --with-isl=s
ystem --with-isl-prefix=$MYMIPS
fi
 
if [ ! -e "${MYMIPS}/lib/libcloog-isl.a" ] ; then
make
make install
fi
cd ../../.. 
 
########################################
# newlib
########################################
 
# Get the archives
cd mips/orig
 
if [ ! -e "newlib-${NEWLIBVERSION}.tar.gz" ] ; then
  wget ftp://sourceware.org/pub/newlib/newlib-${NEWLIBVERSION}.tar.gz
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "newlib-${NEWLIBVERSION}" ] ; then
tar -xvzf ../orig/newlib-${NEWLIBVERSION}.tar.gz
fi 
 
cd ../..
 
########################################
# gcc first stage
########################################
 
# Get the archives
cd mips/orig 
if [ ! -e "gcc-${GCCVERSION}.tar.bz2" ] ; then
  wget http://ftp.halifax.rwth-aachen.de/gnu/gcc/gcc-${GCCVERSION}/gcc-${GCCVERSION}.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "gcc-${GCCVERSION}" ] ; then
tar -xvjf ../orig/gcc-${GCCVERSION}.tar.bz2
fi 
 
cd ../build
mkdir -p gcc-stage1
cd gcc-stage1
if [ ! -e "config.status" ] ; then
LDFLAGS="-Wl,-rpath,$MYMIPS/lib" \
../../src/gcc-${GCCVERSION}/configure --target=mipsel-none-elf \
--prefix=$MYMIPS \
--with-gmp=$MYMIPS \
--with-mpfr=$MYMIPS \
--with-mpc=$MYMIPS \
--with-isl=$MYMIPS \
--with-newlib --without-headers \
--disable-shared --disable-threads --disable-libssp \
--disable-libgomp --disable-libmudflap \
--enable-languages="c"  
fi
 
if [ ! -e "${MYMIPS}/bin/mipsel-none-elf-gcc" ] ; then
make all-gcc
make install-gcc
fi
cd ../../..
 
########################################
# newlib
########################################
 
# Build
cd mips/build
mkdir -p newlib
cd newlib
if [ ! -e "config.status" ] ; then
../../src/newlib-${NEWLIBVERSION}/configure --prefix=$MYMIPS --target=mipsel-none-elf 
fi
 
if [ ! -e "${MYMIPS}/mipsel-none-elf/lib/libc.a" ] ; then
make
make install
fi
cd ../../.. 
 
########################################
# gcc second stage
########################################
 
cd mips/build
mkdir -p gcc-stage2
cd gcc-stage2
if [ ! -e "config.status" ] ; then
LDFLAGS="-Wl,-rpath,$MYMIPS/lib" \
../../src/gcc-${GCCVERSION}/configure --target=mipsel-none-elf \
--prefix=$MYMIPS \
--with-gmp=$MYMIPS \
--with-mpfr=$MYMIPS \
--with-mpc=$MYMIPS \
--with-isl=$MYMIPS \
--with-newlib  \
--disable-shared --disable-threads --disable-libssp \
--disable-libgomp --disable-libmudflap \
--enable-languages="c,c++"  
fi
 
if [ ! -e "${MYMIPS}/bin/mipsel-none-elf-g++" ] ; then
make all
make install
fi
cd ../../..
 
 
########################################
# GDB
########################################
 
# Get the archives
cd mips/orig 
if [ ! -e "gdb-${GDBVERSION}.tar.bz2" ] ; then
  wget http://ftp.halifax.rwth-aachen.de/gnu/gdb/gdb-${GDBVERSION}.tar.bz2
fi
 
# Unpack to source directory
cd ../src
if [ ! -d "gdb-${GDBVERSION}" ] ; then
tar -xvjf ../orig/gdb-${GDBVERSION}.tar.bz2
fi 
 
cd ../build
mkdir -p gdb
cd gdb
if [ ! -e "config.status" ] ; then
../../src/gdb-${GDBVERSION}/configure --target=mipsel-none-elf  \
--enable-sim-stdio \
--prefix=$MYMIPS 
fi
 
if [ ! -e "${MYMIPS}/bin/mipsel-none-elf-gdb" ] ; then
make
make install
fi
cd ../../..

Compile and Run

Compile to Assembler for viewing

mipsel-none-elf-gcc -S fir.c

The output is fir.s which is the assembler code.

Compile and link ready for simulation with instruction set simulator

mipsel-none-elf-gcc -o fir -Tidt.ld fir.c

Run the code

mipsel-none-elf-run fir

Analyze

Produce an annoted source code

gcc -fprofile-arcs -ftest-coverage -o fir fir.c

./fir

gcov fir.c

Run with instruction tracing in the simulator

mipsel-none-elf-run –trace-insn=on –trace-file trace fir

  • mips_cross_compiler.1367868100.txt.gz
  • Last modified: 2013/05/06 21:21
  • by beckmanf