Very Simple Guide for Building Cross Compilers Tips

The following is steps to build cross compilers. So far, I tried only for PowerPC and MIPS.

Basically, all you have to do is to follow the following 9 steps.

  1. Download sources
  2. Set environment variables
  3. Build binutils
  4. Build bootstrap gcc
  5. Build newlib
  6. Build gcc again with newlib
  7. GDB with PSIM
  8. Compile your code
  9. Run

1. What do you need?

First, you have to obtain the following source codes

2. Set environment variables

First, choose your taget such as powerpc-eabi, powerpc-elf, mips-elf, and so on

For bash simply type

% export TARGET=powerpc-eabi
% export PREFIX=/usr/local/$TARGET
% export PATH=$PATH:$PREFIX/bin

3. Build binutils

% tar xjfv binutils-2.17.tar.bz2
% mkdir build-binutils
% cd build-binutils
% ../binutils-2.17/configure --target=$TARGET --prefix=$PREFIX
% make all
% make install

4. Build bootstrap GCC

% tar xjfv gcc-4.1.1.tar.bz2
% mkdir build-gcc
% cd build-gcc
% ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib  --with-gnu-as --with-gnu-ld
% make all-gcc
% make install-gcc

--with-gnu-as --with-gnu-ld prevents native assembler on certain architectures. (for others, these do not have any effects)

5. Build newlib

Newlib provides standard C library for embedded systems

% tar xzfv newlib-1.14.0.tar.gz 
% mkdir build-newlib
% cd build-newlib
% ../newlib-1.14.0/configure --target=$TARGET --prefix=$PREFIX
% make all
% make install

6. Build GCC again with newlib

% cd build-gcc
% ../gcc-4.1.1/configure --target=$TARGET --prefix=$PREFIX --with-newlib --with-gnu-as --with-gnu-ld --disable-shared --disable-libssp
% make all
% make install

7. GDB with PSIM

% tar xjfv gdb-6.3.tar.bz2  
% mkdir build-gdb
% cd build-gdb
% ../gdb-6.3/configure --target=$TARGET --prefix=$PREFIX --enable-sim-powerpc
--enable-sim-stdio
% make all
% make install

Congratulations! You build your tool chain

8. Compile your code

Now, it's time to compile your code.

% powerpc-eabi-gcc -mcpu=405 hello.c -o hello -msim
% mips-elf-gcc -Tidt.ld -mips4 hello.c -o hello

-T option specifies libraries that include start code.

To Compile with specific Memory map

% powerpc-eabi-gcc -Wl,-Ttext,0x4000,-Tdata,0xf000 hello.c -msim
(-Wl,-Ttext,0x4000,-Tdata,0x10000)

9. Run

% powerpc-eabi-run hello
% mips-elf-run hello

Home

Copyright © 2007 Munehiro Nakazato. All rights reserved.