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 [2014/02/14 23:49] – added test section beckmanfmips_cross_compiler [2014/06/04 17:52] (current) – simple project added beckmanf
Line 78: Line 78:
 # -e => exit on error # -e => exit on error
 # -v => verbose output # -v => verbose output
- 
-# YOU MUST APPEND THAT 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
  
 <code> <code>
-mipsel-none-elf-run --trace-insn=on --trace-file trace fir+mipsel-none-elf-gcc -Tidt.ld -o hello hello.c 
 +mipsel-none-elf-run --trace-insn=on --trace-file trace hello
 </code> </code>
  
Line 493: Line 536:
 make check-gcc RUNTESTFLAGS=--target_board=mips-sim make check-gcc RUNTESTFLAGS=--target_board=mips-sim
 </code> </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 ===== ===== Open OCD =====
  
 [[dt_openocd]] [[dt_openocd]]
- 
  
  
  
  
  • mips_cross_compiler.1392418146.txt.gz
  • Last modified: 2014/02/14 23:49
  • by beckmanf