[[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
Last revision Both sides next revision
mips_cross_compiler [2013/04/09 10:18]
beckmanf build shellscript added
mips_cross_compiler [2014/02/16 17:57]
beckmanf [MIPS Cross Compiler build] - used HOME variable
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 THAT 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=+../​../​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>​ 
 + 
 +===== Open OCD ===== 
 + 
 +[[dt_openocd]] 
 + 
  
  
  • mips_cross_compiler.txt
  • Last modified: 2014/06/04 17:52
  • by beckmanf