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
../../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测试
# 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
# 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
7.编译 gdb
这个比较简单,下载代码gdb-7.6.2.tar.bz2, 解压后,配置以下:
[plain] view plain copy
而后执行 make, make install 既能够了。
最后,能够用一个mips的镜像测试一下:
[plain] view plain copy
[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