[[mips_cross_compiler]]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
mips_cross_compiler [2013/04/03 11:27]
beckmanf tracing
mips_cross_compiler [2014/06/04 17:52] (current)
beckmanf simple project added
Line 13: Line 13:
   * [[http://​www.gnu.org/​software/​binutils/​|GNU Binutils]]   * [[http://​www.gnu.org/​software/​binutils/​|GNU Binutils]]
   * [[http://​www.gnu.org/​software/​gcc/​|GNU GCC]]   * [[http://​www.gnu.org/​software/​gcc/​|GNU GCC]]
 +  * and others...
  
-=== Compile and Run ===+From a bare ubuntu 12.04 LTS you need to add the following packages:Ìý
 +Ìý
 +<​code>​Ìý
 +sudo apt-get install build-essential m4 texinfo libncurses5-dev bzip2Ìý
 +</​code>​Ìý
 +Ìý
 +Ìý
 +Copy the script "​build_mips.sh"​ from below to your home directory. Open a terminal window in ubuntu by starting dash and typing terminal. Ìý
 +The click terminal which opens the terminal. To change the current directory to your home directory typeÌý
 +Ìý
 +<​code>​Ìý
 +cdÌý
 +</​code>​Ìý
 +Ìý
 +To see the full path of the current directory:​Ìý
 +Ìý
 +<​code>​Ìý
 +pwdÌý
 +</​code>​Ìý
 +Ìý
 +List the directory contents with Ìý
 +Ìý
 +<​code>​Ìý
 +ls -laÌý
 +</​code>​Ìý
 +Ìý
 +Change the file attributes of "​build_mips.sh"​ to executable withÌý
 +Ìý
 +<​code>​Ìý
 +chmod a+x build_mips.shÌý
 +</​code>​Ìý
 +Ìý
 +Look into the bash script with Ìý
 +Ìý
 +<​code>​Ìý
 +less build_mips.shÌý
 +</​code>​Ìý
 +Ìý
 +Extend the search path by appending "​export PATH=$HOME/​site/​bin:​$PATH"​ to your .profile fileÌý
 +Ìý
 +Log out and login again to make the PATH variable active. Check your PATH variable withÌý
 +Ìý
 +<​code>​Ìý
 +echo $PATHÌý
 +</​code>​Ìý
 +Ìý
 +You should see the <​..>/​site/​bin as the first entry. Ìý
 +Ìý
 +Run the build script withÌý
 +Ìý
 +<​code>​Ìý
 +./​build_mips.shÌý
 +</​code>​Ìý
 +Ìý
 +Ìý
 +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. Ìý
 +Ìý
 +<code bash build_mips.sh>​Ìý
 +#!/bin/bash -evÌý
 +# -e => exit on errorÌý
 +# -v => verbose outputÌý
 +Ìý
 +# 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Ìý
 +export MYMIPS=${HOME}/​siteÌý
 +Ìý
 +# VersionsÌý
 +GMPVERSION="​4.3.2"​Ìý
 +PPLVERSION="​0.12.1"​Ìý
 +BINUTILSVERSION="​2.24"​Ìý
 +MPFRVERSION="​2.4.2"​Ìý
 +MPCVERSION="​1.0.2"​Ìý
 +ISLVERSION="​0.12.2"​Ìý
 +CLOOGVERSION="​0.18.1"​Ìý
 +GCCVERSION="​4.8.2"​Ìý
 +NEWLIBVERSION="​1.20.0"​Ìý
 +GDBVERSION="​7.5.1"​Ìý
 +Ìý
 +Ìý
 +########################################​Ìý
 +# 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Ìý
 +fiÌý
 +Ìý
 +if [ ! -e "​${MYMIPS}/​bin/​mipsel-none-elf-ld"​ ] ; thenÌý
 +makeÌý
 +make installÌý
 +fiÌý
 +cd ../../..Ìý
 +Ìý
 +########################################​Ìý
 +# GMPÌý
 +########################################​Ìý
 +Ìý
 +# Get the archivesÌý
 +cd mips/orig Ìý
 +if [ ! -e "​gmp-${GMPVERSION}.tar.bz2"​ ] ; thenÌý
 +  wget ftp://​ftp.halifax.rwth-aachen.de/​gnu/​gmp/​gmp-4.3.2.tar.bz2Ìý
 +fiÌý
 +Ìý
 +# Unpack to source directoryÌý
 +cd ../srcÌý
 +if [ ! -d "​gmp-${GMPVERSION}"​ ] ; thenÌý
 +tar -xjvf ../​orig/​gmp-${GMPVERSION}.tar.bz2Ìý
 +fi Ìý
 +Ìý
 +# BuildÌý
 +cd ../buildÌý
 +mkdir -p gmpÌý
 +cd gmpÌý
 +if [ ! -e "​config.status"​ ] ; then Ìý
 +../​../​src/​gmp-${GMPVERSION}/​configure --prefix=$MYMIPS --enable-cxxÌý
 +fiÌý
 +if [ ! -e "​${MYMIPS}/​lib/​libgmp.a"​ ] ; thenÌý
 +makeÌý
 +make installÌý
 +fiÌý
 +cd ../../..Ìý
 +Ìý
 +Ìý
 +########################################​Ìý
 +# PPLÌý
 +########################################​Ìý
 +Ìý
 +# 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 ../../..Ìý
 +Ìý
 +Ìý
 +######################################​Ìý
 +# MPFR libraryÌý
 +#######################################​Ìý
 +Ìý
 +# Get the archivesÌý
 +cd mips/orig Ìý
 +if [ ! -e "​mpfr-${MPFRVERSION}.tar.bz2"​ ] ; thenÌý
 +  wget ftp://​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 ftp://​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=system --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 ftp://​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 ftp://​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-trace \Ìý
 +--enable-sim-stdio \Ìý
 +--prefix=$MYMIPS Ìý
 +fiÌý
 +Ìý
 +if [ ! -e "​${MYMIPS}/​bin/​mipsel-none-elf-gdb"​ ] ; thenÌý
 +makeÌý
 +make installÌý
 +fiÌý
 +cd ../../..Ìý
 +Ìý
 +</​code>​Ìý
 +Ìý
 +===== Compile and Run an example =====Ìý
 +Ìý
 +Here is an example mini c code to test the compiler. Ìý
 +Ìý
 +<code c hello.c>​Ìý
 +/* Hello world */Ìý
 +#include <​stdio.h>​Ìý
 +Ìý
 +int myfunc(int a, int b){Ìý
 +  int k; Ìý
 +  k = a + b; Ìý
 +Ìý
 +  k += 7; Ìý
 +  k *= 6; Ìý
 +  return k; Ìý
 +}Ìý
 +Ìý
 +int main(){Ìý
 +  int i,​j,​m; ​ Ìý
 +  j = 3;Ìý
 +  m 2;Ìý
 +  Ìý
 +  for(i=0;​i<​5;​i++){Ìý
 +    m +myfunc(i,​j); ​ Ìý
 +    printf("​m is %d\n",​m);​Ìý
 +  }Ìý
 +  return 0;Ìý
 +}Ìý
 +</​code>​
  
 Compile to Assembler for viewing Compile to Assembler for viewing
  
-mipsel-none-elf-gcc -S fir.c+<​code>​Ìý
 +mipsel-none-elf-gcc -S hello.cÌý
 +</​code>​
  
-The output is fir.s which is the assembler code+The output ​assembler code is in hello.s. 
  
 Compile and link ready for simulation with instruction set simulator Compile and link ready for simulation with instruction set simulator
  
-mipsel-none-elf-gcc -o fir -Tidt.ld ​fir.c+<​code>​Ìý
 +mipsel-none-elf-gcc -o hello -Tidt.ld ​hello.cÌý
 +</​code>​
  
 Run the code Run the code
  
-mipsel-none-elf-run ​fir+<​code>​Ìý
 +mipsel-none-elf-run ​helloÌý
 +</​code>​
  
 === Analyze === === Analyze ===
  
-Produce an annoted source code +Produce an annoted source code showing how often lines are executed. ​
  
-gcc -fprofile-arcs -ftest-coverage -o fir fir.c+<​code>​Ìý
 +gcc -fprofile-arcs -ftest-coverage -o hello hello.cÌý
 +./helloÌý
 +gcov hello.cÌý
 +</​code>​
  
-./fir+This produces the file hello.c.gcov showing the annotated source file.  ​
  
-gcov fir.c +=== Tracing in instruction set simulator ===
  
 Run with instruction tracing in the simulator Run with instruction tracing in the simulator
  
-mipsel-none-elf-run --trace-insn=on --trace-file trace fir+<​code>​Ìý
 +mipsel-none-elf-gcc -Tidt.ld -o hello hello.cÌý
 +mipsel-none-elf-run --trace-insn=on --trace-file trace helloÌý
 +</​code>​Ìý
 +Ìý
 +===== Test the compiler =====Ìý
 +Ìý
 +<​code>​Ìý
 +sudo apt-get install dejagnuÌý
 +</​code>​Ìý
 +Ìý
 +<​code>​Ìý
 +cdÌý
 +cd mips/​build/​gcc-stage2Ìý
 +make check-gcc RUNTESTFLAGS=--target_board=mips-simÌý
 +</​code>​Ìý
 +Ìý
 +===== Install git and download a simple project ​ =====Ìý
 +Ìý
 +Install git and download a simple projectÌý
 +Ìý
 +<​code>​Ìý
 +sudo apt-get install gitÌý
 +cdÌý
 +mkdir projectsÌý
 +cd projectsÌý
 +git clone https://​git.etech.fh-augsburg.de/​friedrich.beckmann/​myfirst.gitÌý
 +</​code>​Ìý
 +Ìý
 +Now you have the simple project "​myfirst"​ in your directory. Ìý
 +Ìý
 +=== Try the MIPS Cross Compiler ===Ìý
 +Ìý
 +Change to the src directory and compile the code with the cross compiler. Ìý
 +Ìý
 +<​code>​Ìý
 +cd myfirstÌý
 +cd srcÌý
 +mipsel-none-elf-gcc -S hello.cÌý
 +less hello.sÌý
 +</​code>​Ìý
 +Ìý
 +Now you have the compiled assembler code "​hello.s"​. To compile to binary do: Ìý
 +Ìý
 +<​code>​Ìý
 +mipsel-none-elf-gcc -o hello -Tidt.ld hello.cÌý
 +</​code>​Ìý
 +Ìý
 +Now you have the binary "​hello"​. You can run the binary in the instruction set simulator withÌý
 +Ìý
 +<​code>​Ìý
 +mipsel-none-elf-run helloÌý
 +</​code>​Ìý
 +Ìý
 +This will run the binary with the mips instruction set simulator. You should see "Hello World"​. Ìý
 +Ìý
 +Ìý
 +Ìý
 +===== Open OCD =====Ìý
 +Ìý
 +[[dt_openocd]]Ìý
  
  
  
  • mips_cross_compiler.1364981243.txt.gz
  • Last modified: 2013/04/03 11:27
  • by beckmanf