用crosstool-ng建立arm交叉编译工具链

转载:http://blog.csdn.net/shallen320/article/details/6591888

用crosstool-ng建立arm交叉编译工具链

22人阅读 评论(0) 收藏 举报


Crosstool-NG是一个多用途工具链编译工具,配置灵活性很强。支持多架构,多部件(glibc/uClibc...)和版本。Crosstool-ng同样提供debugging实体(DUMA,strace...)和生成工具(sstrip...)

crosstool-ng编译的交叉工具链可以编译最新的u-bootlinux内核,文件系统等,非常方便。


1.下载最新版本crosstool-ng安装包:

http://ymorin.is-a-geek.org/download/crosstool-ng/

及补丁:

http://ymorin.is-a-geek.org/download/crosstool-ng/01-fixes/

解压缩,建立工作目录,安装目录:

我的解压缩目录:~/crosstool-ng-1.7.1/

工作目录:~/crosstool-ng_build/

安装目录:~/crosstool-ng_install/



2.sudoapt-get install命令安装以下必备软件包

libncurses5-dev
bison
flex
texinfo
automake
libtool
patch
gcj
cvs
cvsd
gawk
ubuntu10.04gawk已经是最新)



3.打补丁:

cd crosstool-ng-1.7.1

patch -p1 < <补丁文件地址>

例如:

patch -p1 <000-scripts_finish_do_not_try_to_symlink_if_sed_expr_is_a_no-op.patch

patch -p1 <001-libc_uClibc_fix_snapshots.patch

patch -p1 <002-configure_fix_--mandir.patch



./configure --prefix=/home/hu/crosstool-ng_install配置安装目录



4.安装

make

make install

设环境变量:

exportPATH="${PATH}:/home/hu/crosstool-ng_install/bin"

至此安装已经完成,之后需要配置交叉编译工具链



6.配置

crosstool-ng-1.7.1/samples/arm-unknown-linux-gnueabi目录下两个文件拷贝到crosstool-ng_build

重命名:

cd crosstool-ng_build

cp ./crosstool.config .config

进入配置界面

ct-ng menuconfig



Paths and misc options --->

Local tarballs directory保存源码包的路径,若路径不存在,则不保存源码包

Prefix directory 交叉编译器的安装路径

这两项根据需要自行设置



Target options --->

*** Target optimisations***
(armv4t) Architecture level
(arm920t) Emit assembly forCPU
(arm9tdmi) Tune for CPU



以上这几个参数是如何得出的可以参考gccman手册,下载gcc-4.3.2.tar.bz2后解压,手册位置是gcc-4.3.2/gcc/doc/gcc.1。打开方式:

man./gcc.1


在其中可以找到:

......
ARMOptions
......
-mcpu=name (Emit assembly for CPU)
Thisspecifies the name of the target ARM processor. GCC uses this
nameto determine what kind of instructions it can emit whengener‐
ating assembly code. Permissible names are: arm2,arm250, arm3,
arm6, arm60, arm600, arm610, arm620, arm7, arm7m,arm7d, arm7dm,
arm7di, arm7dmi, arm70, arm700, arm700i, arm710,arm710c, arm7100,
arm7500, arm7500fe, arm7tdmi, arm7tdmi-s,arm8, strongarm, stron‐
garm110, strongarm1100, arm8, arm810,arm9, arm9e, arm920, arm920t,
arm922t, arm946e-s, arm966e-s,arm968e-s, arm926ej-s, arm940t,
arm9tdmi, arm10tdmi, arm1020t,arm1026ej-s, arm10e, arm1020e,
arm1022e, arm1136j-s,arm1136jf-s, mpcore, mpcorenovfp,
arm1156t2-s, arm1176jz-s,arm1176jzf-s, cortex-a8, cortex-r4, cor‐
tex-m3, xscale,iwmmxt, ep9312.

-mtune=name (Tune for CPU)
This optionis very similar to the -mcpu= option, except that
instead ofspecifying the actual target processor type, and hence
restrictingwhich instructions can be used, it specifies that GCC
shouldtune the performance of the code as if the target were of
thetype specified in this option, but still choosing the instruc‐
tions that it will generate based on the cpu specified by a-mcpu=
option. For some ARM implementations better performancecan be
obtained by using this option.

-march=name(Architecture level)
This specifies the name of the targetARM architecture. GCC uses
this name to determine what kind ofinstructions it can emit when
generating assembly code. Thisoption can be used in conjunction
with or instead of the-mcpu= option. Permissible names are:
armv2, armv2a, armv3,armv3m, armv4, armv4t, armv5, armv5t,
armv5te, armv6, armv6j,armv6t2, armv6z, armv6zk, armv7, armv7-a,
armv7-r, armv7-m,iwmmxt, ep9312.

......


Pathsand misc options --->增加编译并行进程数,增加运行效率,加快编译

***Build behavior ***
(4) Number ofparallel jobs

这个数应为cpu数量的两倍,双核cpu4


7.开始编译:

crosstool-ng_build目录中:

ct-ngbuild

若出错则写出绝对路径,我的是:

/home/hu/crosstool-ng_install/bin/ct-ngbuild

开始漫长的等待。

整个build过程需要消耗大量硬盘空间。为了能顺利build通过,请至少预留5G空间。


开始时会下载各个需要的源码包,放在menuconfig设定的Localtarballsdirectory里面。一方面为了加快速度,另一方面由于编译器下载的源码包经常不完整,会出现解压缩错误的情况,强烈建议自行手动下载所需源码包。


我编译时需要的源码包有:

binutils-2.19.1.tar.bz2
glibc-2.9.tar.gz
dmalloc-5.5.2.tgz
glibc-ports-2.9.tar.bz2
mpfr-2.4.2.tar.bz2
duma_2_5_15.tar.gz
gmp-4.3.1.tar.bz2
ncurses-5.7.tar.gz
ecj-latest.jar
这个自动下载会出错,只能手动下载
libelf-0.8.12.tar.gz
sstrip.c
gcc-4.3.2.tar.bz2
linux-2.6.33.2.tar.bz2
strace-4.5.19.tar.bz2
gdb-6.8.tar.bz2
ltrace_0.5.3.orig.tar.gz


源码包下载完成后就开始解压缩,编译


8.编译错误与处理方法:

如果编译出错,可以打开build.log文件查看出错原因.

我碰到的错误有:


  1. 文件解压缩错误,这时在build.log里会提示filecorrupet.需要重新手动下载源码包,放到tarballs目录里。这个错误常见于解压缩自动下载的源码包,所以还是建议手动下载。

重新下载源码包后,还需要删除部分解压缩的文件,才能重新编译。部分解压缩文件的位置会给出提示。

  1. 建立内核头文件错误。这个需要具体查看build.log文件具体分析,实在不行可以换内核版本解决。

  2. make过程中指令elif无法识别,这个时候需要安装相应的软件包。搜索一下就能找出解决办法。

  3. 碰到其他的错误的话可以搜索一下错误代码,看看别人是怎么解决的,一般都能找到解决办法



build90分钟才把交叉编译器build好,build好的编译器位于menuconfig设定的Prefixdirectory目录中。


9.交叉工具链的使用:


首先建立交叉工具链所在目录的环境变量。

exportPATH="${PATH}:/home/hu/x-tools/arm-unknown-linux-gnueabi/bin"

使用这种方法时,若另开一个终端,则需重新输入。

还有一个解决办法,编辑~/.profile文件,最后加入

PATH=”/home/hu/x-tools/arm-unknown-linux-gnueabi/bin:$PATH”


其次,在编译前,要将待编译软件包的Makefile中环境变量CROSS_COMPILE的值设为arm-unknown-linux-gnueabi-



10.参考博客:

http://www.cublog.cn/u1/34474/showart_2198589.html

http://blog.csdn.net/HumorRat/archive/2010/05/21/5615298.aspx



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值