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

转载于:https://www.cnblogs.com/bcxx_qin/archive/2009/08/25/1553429.html

驱动器 D 中的卷是 LINUX 卷的序列号是 4471-561B D:\桌面\mips交叉编译环境 的目录 2009-10-22 20:27 <DIR> . 2009-10-22 20:27 <DIR> .. 2009-10-22 20:09 27,425,338 gcc-3.4.3.tar.bz2 2009-10-22 20:08 7,421,782 binutils-2.10.91.0.2.tar.bz2 2009-10-22 20:08 242,445 glibc-linuxthreads-2.5.tar.bz2 2009-10-22 20:10 20,544,628 glibc-2.5.tar.gz 2009-10-22 20:20 1,720 elf-machine-rela-mips.dpatch 2009-10-22 20:26 4,727 建立基于linux的MIPS交叉编译环境 .txt 6 个文件 55,640,640 字节 2 个目录 6,793,084,928 可用字节 三、构建过程 1、准备环境 目标平台: mipsel-linux(即little endian,x86也是little endian的,不懂的话自己到网上查资料吧) 安装目录: /usr/local/crossdev 源代码安装目录: /usr/local/src 注:没有的目录请自行建立。 2、准备MIPS环境的头文件 我们是在i386下编译的,但要使用MIPS的头文件定义才能正确编译MIPS交叉编译工具。这些头文件都在kernel源程序中。 cd /usr/local/src/ tar xzvf linux-2.4.2.tar.gz cd linux/ make ARCH=mips menuconfig 在"CPU selection"中, 选中"(R3000) CPU type",也可以选你实际的MIPS平台的CPU类型 在"General setup"中, 选中"Generate little endian code" make dep mkdir -p /usr/local/crossdev/mipsel-linux/include cp -r /usr/local/src/linux/include/asm-mips /usr/local/crossdev/mipsel-linux/include/asm cp -r /usr/local/src/linux/include/linux /usr/local/crossdev/mipsel-linux/include/ 3、编译binutils cd /usr/local/src/ tar xzvf binutils-2.11.90.0.31.tar.gz cd binutils-2.11.90.0.31/ ./configure --target=mipsel-linux --prefix=/usr/local/crossdev make make install export PATH=/usr/local/crossdev/bin:$PATH 4、编译自举的(bootstrap)gcc 因为这时还没有MIPS的glibc库可以使用,只能编译一个最简单的gcc,用这个gcc编译出glibc后就可以再编译一个完成的gcc了。 cd /usr/local/src/ tar xzvf gcc-3.0.2.tar.gz cd gcc-3.0.2/ ./configure --target=mipsel-linux --prefix=/usr/local/crossdev --enable-languages=c --with-newlib --disable-shared make make install 注:以上编译安装的工具已经可以直接编译MIPS的kernel(make zImage)了。 5、编译glibc 现在可以使用刚才建立的binutils和gcc来编译MIPS的glibc了。 cd /usr/local/src/ tar xzvf glibc-2.2.3.tar.gz cd glibc-2.2.3/ tar xzvf ../glibc-linuxthreads-2.2.3.tar.gz patch -p1 < ../glibc-2.2.3-mips-base-addr-got.diff CC=mipsel-linux-gcc AR=mipsel-linux-ar RANLIB=mipsel-linux-ranlib ./configure --host=mipsel-linux --prefix=/usr/local/crossdev/mipsel-linux --enable-add-ons=linuxthreads make make install 6、重新编译完整的gcc cd /usr/local/src/ rm -rf gcc-3.0.2/ tar xzvf gcc-3.0.2.tar.gz cd gcc-3.0.2/ ./configure --target=mipsel-linux --prefix=/usr/local/crossdev --enable-languages=c,c++ make make install 以上就构建好了一套自己的MIPS交叉编译环境,目录在/usr/local/crossdev下,你可以把它打包拷贝到其它i386的Linux系统下也能使用。 要使用其来交叉编译时请先加上PATH环境变量:export PATH=/usr/local/crossdev/bin:$PATH
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值