[[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/09 10:18]
beckmanf build shellscript added
mips_cross_compiler [2014/06/04 17:52] (current)
beckmanf simple project added
Line 14: Line 14:
   * [[http://​www.gnu.org/​software/​gcc/​|GNU GCC]]   * [[http://​www.gnu.org/​software/​gcc/​|GNU GCC]]
   * and others...   * and others...
 +
 +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 Here is the shell script for building the cross compiler chain. Handmade
Line 23: Line 78:
 # -e => exit on error # -e => exit on error
 # -v => verbose output # -v => verbose output
- 
-# YOU MUST APPEND 91Âþ»­T to your .profile file 
-# export PATH=$HOME/​site/​bin:​$PATH 
  
 # Mips Cross Compiler # Mips Cross Compiler
Line 38: Line 90:
 mkdir -p mips/orig mkdir -p mips/orig
  
-# Set the destination ​directoryÌý+# Set the destinationÌý
-export MYMIPS=$HOME/​site+export MYMIPS=${HOME}/site
  
 # Versions # Versions
-GMPVERSION=4.3.2+GMPVERSION="4.3.2"
 PPLVERSION="​0.12.1"​ PPLVERSION="​0.12.1"​
-BINUTILSVERSION="​2.23.2"+BINUTILSVERSION="​2.24"
 MPFRVERSION="​2.4.2"​ MPFRVERSION="​2.4.2"​
-MPCVERSION="​1.0.1"Ìý+MPCVERSION="​1.0.2"Ìý
-ISLVERSION="​0.11.1"Ìý+ISLVERSION="​0.12.2"Ìý
-CLOOGVERSION="​0.18.0"Ìý+CLOOGVERSION="​0.18.1"Ìý
-GCCVERSION="​4.8.0"+GCCVERSION="​4.8.2"
 NEWLIBVERSION="​1.20.0"​ NEWLIBVERSION="​1.20.0"​
 GDBVERSION="​7.5.1"​ GDBVERSION="​7.5.1"​
 +
 +
 +########################################​
 +# Binutils
 +########################################​
  
 # Get the archives # Get the archives
 cd mips/​orig ​ cd mips/​orig ​
-if [ ! -e "gmp-4.3.2.tar.bz2"​ ] ; thenÌý+if [ ! -e "binutils-${BINUTILSVERSION}.tar.bz2"​ ] ; thenÌý
-  wget ftp://ftp.halifax.rwth-aachen.de/gnu/gmp/gmp-4.3.2.tar.bz2+  wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVERSION}.tar.bz2
 fi fi
  
 # Unpack to source directory # Unpack to source directory
 cd ../src cd ../src
-if [ ! -d "gmp-4.3.2" ] ; thenÌý+if [ ! -d "binutils-${BINUTILSVERSION}" ] ; thenÌý
-tar -xjvf ../orig/gmp-4.3.2.tar.bz2+tar -xvjf ../orig/binutils-${BINUTILSVERSION}.tar.bz2
 fi  fi 
  
-# Build 
 cd ../build cd ../build
-mkdir -p gmpÌý+mkdir -p binutilsÌý
-cd gmpÌý+cd binutilsÌý
-if [ ! -e "​config.status"​ ] ; then Ìý+if [ ! -e "​config.status"​ ] ; thenÌý
-../../src/gmp-4.3.2/configure --prefix=$MYMIPS ​--enable-cxx+../../src/binutils-${BINUTILSVERSION}/configure --target=mipsel-none-elf \Ìý
 +--prefix=$MYMIPS
 fi fi
-if [ ! -e "​${MYMIPS}/​lib/libgmp.a" ] ; then+Ìý
 +if [ ! -e "​${MYMIPS}/​bin/mipsel-none-elf-ld" ] ; then
 make make
 make install make install
Line 78: Line 136:
 cd ../../.. cd ../../..
  
 +########################################​
 +# GMP
 +########################################​
  
 # Get the archives # Get the archives
 cd mips/​orig ​ cd mips/​orig ​
-if [ ! -e "ppl-${PPLVERSION}.tar.bz2"​ ] ; thenÌý+if [ ! -e "gmp-${GMPVERSION}.tar.bz2"​ ] ; thenÌý
-  wget ftp://ftp.cs.unipr.it/pub/ppl/releases/​${PPLVERSION}/​ppl-${PPLVERSION}.tar.bz2+  wget ftp://ftp.halifax.rwth-aachen.de/gnu/gmp/gmp-4.3.2.tar.bz2
 fi fi
  
 # Unpack to source directory # Unpack to source directory
 cd ../src cd ../src
-if [ ! -d "ppl-${PPLVERSION}" ] ; thenÌý+if [ ! -d "gmp-${GMPVERSION}" ] ; thenÌý
-tar -xjvf ../orig/ppl-${PPLVERSION}.tar.bz2+tar -xjvf ../orig/gmp-${GMPVERSION}.tar.bz2
 fi  fi 
  
 +# Build
 cd ../build cd ../build
-mkdir -p pplÌý+mkdir -p gmpÌý
-cd pplÌý+cd gmpÌý
-if [ ! -e "​config.status"​ ] ; thenÌý+if [ ! -e "​config.status"​ ] ; then Ìý
-../../src/ppl-${PPLVERSION}/configure --prefix=$MYMIPS --with-gmp=$MYMIPS --with-sysroot=$MYMIPS+../../src/gmp-${GMPVERSION}/configure --prefix=$MYMIPS --enable-cxx
 fi fi
-if [ ! -e "​${MYMIPS}/​lib/​libppl.a" ] ; thenÌý+if [ ! -e "​${MYMIPS}/​lib/​libgmp.a" ] ; thenÌý
-make +make
 make install make install
 fi fi
 cd ../../.. cd ../../..
 +
  
 ########################################​ ########################################​
-Binutils+PPL
 ########################################​ ########################################​
  
 # Get the archives # Get the archives
-cd mips/orig Ìý+#cd mips/orig Ìý
-if [ ! -e "binutils-${BINUTILSVERSION}.tar.bz2"​ ] ; thenÌý+#if [ ! -e "ppl-${PPLVERSION}.tar.bz2"​ ] ; thenÌý
-  wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVERSION}.tar.bz2Ìý+ ​wget ​ftp://ftp.cs.unipr.it/pub/ppl/​releases/​${PPLVERSION}/ppl-${PPLVERSION}.tar.bz2Ìý
-fi+#fi
  
 # Unpack to source directory # Unpack to source directory
-cd ../srcÌý+#cd ../srcÌý
-if [ ! -d "binutils-${BINUTILSVERSION}" ] ; thenÌý+#if [ ! -d "ppl-${PPLVERSION}" ] ; thenÌý
-tar -xvjf ../orig/binutils-${BINUTILSVERSION}.tar.bz2Ìý+#tar -xjvf ../orig/ppl-${PPLVERSION}.tar.bz2Ìý
-fi +#fi 
  
-cd ../buildÌý+#cd ../buildÌý
-mkdir -p binutilsÌý+#mkdir -p pplÌý
-cd binutilsÌý+#cd pplÌý
-if [ ! -e "​config.status"​ ] ; thenÌý+#if [ ! -e "​config.status"​ ] ; thenÌý
-../../src/binutils-${BINUTILSVERSION}/configure --target=mipsel-none-elf \Ìý+#../../src/ppl-${PPLVERSION}/configure --prefix=$MYMIPS ​--with-gmp=$MYMIPS --with-sysroot=$MYMIPSÌý
---prefix=$MYMIPS ​\Ìý+#fiÌý
---with-ppl=$MYMIPS ​ Ìý+#if [ ! -e "​${MYMIPS}/​lib/​libppl.a"​ ] ; thenÌý
-fi+#make Ìý
 +#make installÌý
 +#fiÌý
 +#cd ../../..
  
-if [ ! -e "​${MYMIPS}/​bin/​mipsel-none-elf-ld"​ ] ; then 
-make 
-make install 
-fi 
-cd ../../.. 
  
 ######################################​ ######################################​
Line 245: Line 306:
 cd cloog cd cloog
 if [ ! -e "​config.status"​ ] ; then if [ ! -e "​config.status"​ ] ; then
-../​../​src/​cloog-${CLOOGVERSION}/​configure --prefix=$MYMIPS --with-gmp-prefix=$MYMIPS --with-isl=sÌý+../​../​src/​cloog-${CLOOGVERSION}/​configure --prefix=$MYMIPS --with-gmp-prefix=$MYMIPS --with-isl=system ​--with-isl-prefix=$MYMIPS
-ystem --with-isl-prefix=$MYMIPS+
 fi fi
  
Line 254: Line 314:
 fi fi
 cd ../​../​.. ​ cd ../​../​.. ​
 +
  
 ########################################​ ########################################​
Line 380: Line 441:
 if [ ! -e "​config.status"​ ] ; then if [ ! -e "​config.status"​ ] ; then
 ../​../​src/​gdb-${GDBVERSION}/​configure --target=mipsel-none-elf ​ \ ../​../​src/​gdb-${GDBVERSION}/​configure --target=mipsel-none-elf ​ \
 +--enable-sim-trace \
 --enable-sim-stdio \ --enable-sim-stdio \
 --prefix=$MYMIPS ​ --prefix=$MYMIPS ​
Line 389: Line 451:
 fi fi
 cd ../../.. cd ../../..
- 
  
 </​code>​ </​code>​
  
-=== Compile and Run ===+===== 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.1365495512.txt.gz
  • Last modified: 2013/04/09 10:18
  • by beckmanf