制做mipsel 交叉工具链

 

1. 在 ~/code 下创建目录 cross-compile, 在 cross-compile 下创建setup, 保存下载的文件:

 ls ~/code/cross-compile/setup/
binutils-2.24.tar.bz2  gcc-4.6.4.tar.bz2  glibc-2.18.tar.bz2  glibc-linuxthreads-2.5.tar.bz2  linux-3.2.tar.bz2 

在 cross-compile 下创建 build目录,在 build下面创建 编译子目录 binutils  gcc  glibc,用来编译 binutils, gcc 和 glibc:
ls ~/code/cross-compile/build/
binutils  gcc  glibc

创建  src目录,用来存放解压的代码
创建 kernel 目录,保存 kernel 的代码
创建embedded-toolchain/tool-chain/目录,存放最后编译出来的工具链。
 ls ~/code/cross-compile/
build  embedded-toolchain  gmp-4.3.2.tar.bz2  mpc-0.8.1         mpfr-2.4.2          setup
doc    gmp-4.3.2           kernel             mpc-0.8.1.tar.gz  mpfr-2.4.2.tar.bz2  src
 html

#packages pathlinux

# ls -l /home/charles/code/cross-compile/setup/
total 191188
-rwxr--r-- 1 root root 26843686 Jun  6 19:15 binutils-2.22.tar.gz
-rwxr--r-- 1 root root 82216668 Jun  6 19:16 gcc-4.4.7.tar.gz
-rwxr--r-- 1 root root 21119201 Jun  6 19:14 glibc-2.12.1.tar.gz
-rwxr--r-- 1 root root   242445 Jun  6 19:15 glibc-linuxthreads-2.5.tar.bz2
-rwxr--r-- 1 root root   912156 Jun  8 09:09 glibc-ports-2.12.1.tar.gz
-rwxr--r-- 1 root root 64424138 Jun  6 19:15 linux-2.6.32.tar.bz2
drwxr-xr-x 5 1000 1000     4096 Oct  3  2006 linuxthreads

#prepare glibc pathc++

 
# cd /home/charles/code/cross-compile/src
# tar -xf ../src/glibc-2.12.1.tar.xz 
# tar -xjf ../src/glibc-linuxthreads-2.5.tar.bz2 -C glibc-2.12.1 
# tar -xf ../src/glibc-ports-2.12.1.tar.xz 
# mv glibc-ports-2.12.1 glibc-2.12.1/ports 

2. 编译 binutils:

cd src/
tar jxvf ../setup/binutils-2.24.tar.bz2

 cd  ..
cd build/binutils/
../../src/binutils-2.24/configure --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain

在 build/binutils下面生成makefile文件:

bfd  binutils  config.log  config.status  etc  gas  gprof  intl  ld  libiberty  Makefile  opcodes  serdep.tmp

执行  make, make install, 会安装到embedded-toolchain/tool-chain里。

ls embedded-toolchain/tool-chain/bin/
mipsel-linux-addr2line  mipsel-linux-c++filt  mipsel-linux-gcc        mipsel-linux-ld       mipsel-linux-objdump  mipsel-linux-strings
mipsel-linux-ar         mipsel-linux-cpp      mipsel-linux-gcc-4.6.4  mipsel-linux-ld.bfd   mipsel-linux-ranlib   mipsel-linux-strip
mipsel-linux-as         mipsel-linux-elfedit  mipsel-linux-gcov       mipsel-linux-nm       mipsel-linux-readelf
mipsel-linux-c++        mipsel-linux-g++      mipsel-linux-gprof      mipsel-linux-objcopy  mipsel-linux-size

3. 设置内核头文件

cd kernel/
tar jxvf ../setup/linux-3.2.tar.bz2  
cd linux-3.2/
make ARCH=mips CROSS_COMPILE=mipsel-linux- menuconfig
make ARCH=mips CROSS_COMPILE=mipsel-linux-

在 make menuconfig 的时候, machine 选择 MIPS malta board, CPU选择  MIPS32 release 2, Endianess Selection 选择 "little endian"
这一步确定出错,但只要生成了version.h 和 autoconf.h就达到了目的。
下面拷贝头文件:

先 cd 到 embedded-toolchain/tool-chain, 创建 include 目录:

cp -r ../../kernel/linux-3.2/include/linux include/
cp -r ../../kernel/linux-3.2/include/asm-generic include/
cp  -r ../../kernel/linux-3.2/arch/mips/include/asm include/

4. 创建初始编译器(bootstrap gcc)redis

[plain] view plain copybootstrap

 print?在CODE上查看代码片派生到个人代码片sass

  1. ../../src/gcc-4.6.4/configure  --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain --without-headers --enable-languages=c,c++ --disable-shared --disable-threads --disable-decimal-float --disable-libmudflap --disable-lipssp --with-float=soft  
../../src/gcc-4.4.7/configure  --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain --with-headers=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/include --enable-languages=c,c++ --disable-shared  --with-float=soft  --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1


make all-gcc -j10 -i -k
make install-gcc
make all-target-libgcc
make install-target-libgcc


 ls  ../../embedded-toolchain/tool-chain/bin/
mipsel-linux-addr2line  mipsel-linux-c++filt  mipsel-linux-gcc        mipsel-linux-ld       mipsel-linux-objdump  mipsel-linux-strings
mipsel-linux-ar         mipsel-linux-cpp      mipsel-linux-gcc-4.6.4  mipsel-linux-ld.bfd   mipsel-linux-ranlib   mipsel-linux-strip
mipsel-linux-as         mipsel-linux-elfedit  mipsel-linux-gcov       mipsel-linux-nm       mipsel-linux-readelf
mipsel-linux-c++        mipsel-linux-g++      mipsel-linux-gprof      mipsel-linux-objcopy  mipsel-linux-sizebash

# 如下添加libgcc_eh.a,libgcc_s.a到libgcc.a的软连接,防止编译C库时出错 app

#better
ln -vs libgcc.a `mipsel-linux-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'` 
ln -vs libgcc.a `mipsel-linux-gcc -print-libgcc-file-name | sed 's/libgcc/&_s/'` 

#or
ln -s /home/charles/code/cross-compile/embedded-toolchain/tool-chain/lib/gcc/mipsel-linux/4.4.7/libgcc.a /home/charles/code/cross-compile/embedded-toolchain/tool-chain/lib/gcc/mipsel-linux/4.4.7/libgcc_eh.a
ln -s /home/charles/code/cross-compile/embedded-toolchain/tool-chain/lib/gcc/mipsel-linux/4.4.7/libgcc.a /home/charles/code/cross-compile/embedded-toolchain/tool-chain/lib/gcc/mipsel-linux/4.4.7/libgcc_s.a


5. 编译 glibc

 cd src/
 tar  ../setup/glibc-2.18.tar.bz2
 tar jxvf ../setup/glibc-linuxthreads-2.5.tar.bz2  --directory=glibc-2.18

 cd ..
 cd  build/
 cd glibc工具

[plain] view plain copy测试

 print?在CODE上查看代码片派生到个人代码片

  1. CC=mipsel-linux-gcc AR=mipsel-linux-ar RANLIB=mipsel-linux-ranlib  ../../src/glibc-2.18/configure --host=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/mipsel-linux --enable-add-ons  --with-headers=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/mipsel-linux/include --with-fp=no  
# export PATH=$PATH:/home/charles/code/cross-compile/embedded-toolchain/tool-chain/bin
# export LD_LIBRARY_PATH=/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/mpc-0.8.1/lib

# CC=mipsel-linux-gcc AR=mipsel-linux-ar RANLIB=mipsel-linux-ranlib  ../../src/glibc-2.12.1/configure --host=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/mipsel-linux --enable-add-ons  --with-headers=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/include --with-fp=no  libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes


编译的时候报错
cannot compute suffix of object files: cannot compile
通过查看,发现是 mipsel-linux-gcc 没有添加到 PATH所致,执行:
export PATH=$PATH:/home/charles/code/cross-compile/embedded-toolchain/tool-chain/bin
而后,从新执行上面的配置命令,能够经过。
最后,执行  make, make install.

6. 编译完整的gcc
 

[plain] view plain copy

 print?在CODE上查看代码片派生到个人代码片

  1. ../../src/gcc-4.6.4/configure --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain --disable-multilib --disable-libssp  --disable-nls --disable-libstdcxx-pch --with-arch=mips32r2  --with-mips-plt --with-float=soft --with-ppl=/usr/local --disable-libgomp --enable-poison-system-directories --enable-symvers=gnu --enable-long-long --enable-threads --enable-languages=c,c++ --enable-shared --enable-lto --enable-__cxa_atexit --with-gnu-as --with-gnu-ld  
# cd /home/charles/code/cross-compile/build/gcc-2

# ../../src/gcc-4.4.7/configure --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain  --with-arch=mips32r2  --with-mips-plt --with-float=soft --with-ppl=/usr/local --disable-libgomp --enable-poison-system-directories --enable-symvers=gnu --enable-long-long --enable-threads --enable-languages=c,c++ --enable-shared --enable-lto --enable-__cxa_atexit --with-gnu-as --with-gnu-ld  --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1

而后 , 执行:

make all-gcc -j10 -i -k

make install-gcc

须要注意的问题:

1)最后一步编译  gcc 的时候,若是直接执行  make 会报错,正确的方法是  make all-gcc

2)由于 对gcc作了  配置 --with-float=soft, 在编译 glibc的时候也要作相应的配置: with-fp=no(不使用hardware float),不然生成的gcc 编译文件的时候,会报找不到文件gnu/stubs-o32_soft.h 的错误.

最后能够查看一下 生成的 gcc信息:

 

[plain] view plain copy

 print?在CODE上查看代码片派生到个人代码片

  1. $ mipsel-linux-gcc -v  
  2. Using built-in specs.  
  3. COLLECT_GCC=./mipsel-linux-gcc  
  4. COLLECT_LTO_WRAPPER=/home/charles/code/cross-compile/embedded-toolchain/tool-chain/libexec/gcc/mipsel-linux/4.6.4/lto-wrapper  
  5. Target: mipsel-linux  
  6. Configured with: ../../src/gcc-4.6.4/configure --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain --without-headers --enable-languages=c,c++ --disable-shared --disable-threads --disable-decimal-float --disable-libmudflap --disable-lipssp --with-float=soft : (reconfigured) ../../src/gcc-4.6.4/configure --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain --disable-multilib --disable-libssp --disable-nls --disable-libstdcxx-pch --with-arch=mips32r2 --with-mips-plt --with-float=soft --with-ppl=/usr/local --disable-libgomp --enable-poison-system-directories --enable-symvers=gnu --enable-long-long --enable-threads --enable-languages=c,c++ --enable-shared --enable-lto --enable-__cxa_atexit --with-gnu-as --with-gnu-ld  
  7. Thread model: posix  
  8. gcc version 4.6.4 (GCC)   


7.编译  gdb

 

这个比较简单,下载代码gdb-7.6.2.tar.bz2, 解压后,配置以下:

 

[plain] view plain copy

 print?在CODE上查看代码片派生到个人代码片

  1. ../../src/gdb-7.6.2/configure --build=i686-pc-linux-gnu  --target=mipsel-linux --prefix=/home/charles/code/cross-compile/embedded-toolchain/tool-chain  

而后执行  make, make install 既能够了。

 

最后,能够用一个mips的镜像测试一下:

 

[plain] view plain copy

 print?在CODE上查看代码片派生到个人代码片

  1. ./mipsel-linux-gcc -g test.c -o test  
  2. charles@taotao :~/code/cross-compile/embedded-toolchain/tool-chain/bin$ file test  
  3. test: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), for GNU/Linux 2.6.16, with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped  
  4. charles@taotao :~/code/cross-compile/embedded-toolchain/tool-chain/bin$ ./mipsel-linux-gdb   
  5. GNU gdb (GDB) 7.6.2  
  6. Copyright (C) 2013 Free Software Foundation, Inc.  
  7. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>  
  8. This is free software: you are free to change and redistribute it.  
  9. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"  
  10. and "show warranty" for details.  
  11. This GDB was configured as "--host=i686-pc-linux-gnu --target=mipsel-linux".  
  12. For bug reporting instructions, please see:  
  13. <http://www.gnu.org/software/gdb/bugs/>.  
  14. (gdb) file test  
  15. Reading symbols from /home/charles/code/cross-compile/embedded-toolchain/tool-chain/bin/test...done.  
  16. (gdb) dis  
  17. disable      disassemble  disconnect   display        
  18. (gdb) disassemble   
  19. No frame selected.  
  20. (gdb) disassemble main  
  21. Dump of assembler code for function main:  
  22.    0x00400700 <+0>:   addiu   sp,sp,-32  
  23.    0x00400704 <+4>:   sw  ra,28(sp)  
  24.    0x00400708 <+8>:   sw  s8,24(sp)  
  25.    0x0040070c <+12>:  move    s8,sp  
  26.    0x00400710 <+16>:  lui v0,0x40  
  27.    0x00400714 <+20>:  addiu   a0,v0,2288  
  28.    0x00400718 <+24>:  jal 0x400940 <puts@plt>  
  29.    0x0040071c <+28>:  nop  
  30.    0x00400720 <+32>:  move    sp,s8  
  31.    0x00400724 <+36>:  lw  ra,28(sp)  
  32.    0x00400728 <+40>:  lw  s8,24(sp)  
  33.    0x0040072c <+44>:  addiu   sp,sp,32  
  34.    0x00400730 <+48>:  jr  ra  
  35.    0x00400734 <+52>:  nop  

 

[Issue: The mipsel is not supported]

http://blog.csdn.net/fjhyy/article/details/18960899

[Issue: forced unwind support is required]

http://bbs.chinaunix.net/thread-3589766-1-1.html

 

[issue: many issues which install glibc]

http://blog.csdn.net/gubenpeiyuan/article/details/7891847

相关文章
相关标签/搜索