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/05/07 08:56] – moved instructions from virtual_cae beckmanfmips_cross_compiler [2014/06/04 17:52] (current) – simple project added beckmanf
Line 18: Line 18:
  
 <code> <code>
-sudo apt-get install build-essential m4 texinfo libncurses5-dev+sudo apt-get install build-essential m4 texinfo libncurses5-dev bzip2
 </code> </code>
  
Line 78: 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 93: 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 http://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 133: 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 196: Line 202:
 cd mips/orig  cd mips/orig 
 if [ ! -e "mpfr-${MPFRVERSION}.tar.bz2" ] ; then if [ ! -e "mpfr-${MPFRVERSION}.tar.bz2" ] ; then
-  wget http://ftp.halifax.rwth-aachen.de/gnu/mpfr/mpfr-${MPFRVERSION}.tar.bz2+  wget ftp://ftp.halifax.rwth-aachen.de/gnu/mpfr/mpfr-${MPFRVERSION}.tar.bz2
 fi fi
  
Line 225: Line 231:
 cd mips/orig  cd mips/orig 
 if [ ! -e "mpc-${MPCVERSION}.tar.gz" ] ; then if [ ! -e "mpc-${MPCVERSION}.tar.gz" ] ; then
-  wget http://ftp.halifax.rwth-aachen.de/gnu/mpc/mpc-${MPCVERSION}.tar.gz+  wget ftp://ftp.halifax.rwth-aachen.de/gnu/mpc/mpc-${MPCVERSION}.tar.gz
 fi fi
  
Line 300: Line 306:
 cd cloog cd cloog
 if [ ! -e "config.status" ] ; then if [ ! -e "config.status" ] ; then
-../../src/cloog-${CLOOGVERSION}/configure --prefix=$MYMIPS \Ìý+../../src/cloog-${CLOOGVERSION}/configure --prefix=$MYMIPS --with-gmp-prefix=$MYMIPS --with-isl=system --with-isl-prefix=$MYMIPS
---with-gmp-prefix=$MYMIPS \Ìý+
---with-isl=system \Ìý+
---with-isl-prefix=$MYMIPS+
 fi fi
  
Line 311: Line 314:
 fi fi
 cd ../../..  cd ../../.. 
 +
  
 ######################################## ########################################
Line 338: Line 342:
 cd mips/orig  cd mips/orig 
 if [ ! -e "gcc-${GCCVERSION}.tar.bz2" ] ; then if [ ! -e "gcc-${GCCVERSION}.tar.bz2" ] ; then
-  wget http://ftp.halifax.rwth-aachen.de/gnu/gcc/gcc-${GCCVERSION}/gcc-${GCCVERSION}.tar.bz2+  wget ftp://ftp.halifax.rwth-aachen.de/gnu/gcc/gcc-${GCCVERSION}/gcc-${GCCVERSION}.tar.bz2
 fi fi
  
Line 423: Line 427:
 cd mips/orig  cd mips/orig 
 if [ ! -e "gdb-${GDBVERSION}.tar.bz2" ] ; then if [ ! -e "gdb-${GDBVERSION}.tar.bz2" ] ; then
-  wget http://ftp.halifax.rwth-aachen.de/gnu/gdb/gdb-${GDBVERSION}.tar.bz2+  wget ftp://ftp.halifax.rwth-aachen.de/gnu/gdb/gdb-${GDBVERSION}.tar.bz2
 fi fi
  
Line 437: 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 446: 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.1367909760.txt.gz
  • Last modified: 2013/05/07 08:56
  • by beckmanf