mips-elf-gcc交叉編譯環境的建立

 

/**************************************************************************************

 

       mips-elf的交叉編譯環境源自網絡中的一片文章,但我找不到了出處。同時也經過了我的

一些修改,最終我在slackware 12.0的Linux中成功的配置出了這個交叉編譯環境。至於在

其他版本的linux中我相信也是應該可以成功編譯的,不過我會盡快在其他的linux中進行

驗證的,以方便大家參考。對於不足之處還請指正!!

 

**************************************************************************************/

 

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章