建立arm-linux交叉工具链 crosstool-ng
测试环境:ubuntu 10.4,10.10,11.4,11.10均无压力。
最近被这个arm-linux交叉编译器搞了5天,都快被崩溃了。终于成功了,好开心,于是再做一遍,没问题,在这里记录以下流程:
1.确定好自己机子于开发板
tool:crosstool-ng1.93
host:ubuntu 10.04.3.LTS
target:S3Carm9
(前3天我一直用fedora来安装,最后真的不行了,于是换成ubutu,现在知道编译过程与主机上的GCC版本和GDB版本以及BINUTILS版本其实是没有关系的。它提示你ld is too old ,是因为你下载的工具的版本不对,清自己核对自己下载的版本跟下面提到的vim .config里面的规定。)
2.
$sudo passwd -l (设置root密码
set the unix password:
reset the unix password:
scuess!
(切换到root用户下,安装相关工具。以下所有操作都在root用户下,以后编译前请su -l ,切换到root下面才编译)
3.下载这些工具包,通常有error的时候,很多是因为下面安装包不完全,如果下面安装包有找不到的,那么可能你的ubutu版本对不上,或者你的ubutu版本出现了点小错误(我有一天晚上就是因为cvsd找不到,然后不管了,照样安装,导致10多分钟后才提示gcc编译不过,然后从新下载)
apt-get install bison flex texinfo automake libtool cvs patch
apt-get install libncurses5*
apt-get install aria2 curl gcj g++ subversion cvsd gawk
apt-get install glibc*
4.下载安装用到的工具包:(请千万要下完整!特别是那个gcc,我之前的gcc原来下了一半然后中断了,只有26M,就直接拿来用了,一直找不到问题所在,后来多次查看log,才知道原来一直是gcc编译错误,于是从新下载gcc)
binutils-2.19.1.tar.bz2 | dmalloc-5.5.2.tgz
duma_2_5_15.tar.gz | expat-2.0.1.tar.gz
gcc-4.3.2.tar.bz2 | gdb-6.8.tar.bz2
glibc-2.9.tar.bz2 | glibc-ports-2.9.tar.bz2
gmp-4.3.2.tar.bz2 | libelf-0.8.13.tar.gz
linux-2.6.33.7.tar.bz2 | mpfr-2.4.2.tar.bz2
ncurses-5.7.tar.gz | Sstrip.c
strace-4.5.19.tar.bz2
一定要全部下载好,要不然以后的编译过程中,速度很慢还存在潜在的危险,说不定哪个包自动下载不下来,编译错误,那连原因也找不到。(我就试过这样)
5.处理一个小问题,具体我也不清楚。见大神网站:
http://hi.baidu.com/caicry/blog/item/f306db639c4281680c33fa1b.html
cd /usr/bin
mv mawk mawk.bak
ln -s gawk mawk
cd /home
6.安装crosstool-ng,安装完之后 ct【tab】【tab】后会出现ct-ng,那么你安装成功了!恭喜第一步过了!
mkdir crosstool-ng
cd crosstool-ng
mkdir src
mv /(下载工具包的目录) /home/crossrool-ng/src 这里千万不要变成/home/crossrool-ng/src/ (将上面下载的源码工具包全部复制到 src目录的下)
tar -jzvf crosstool-ng-1.9.3.tar.bz2
cd crosstool-ng-1.9.3
./configure --prefix=/opt/crosstool-ng
make
make install
make clean
echo "PATH=$PATH:/opt/crosstool-ng/bin" >> ~/.bashrc
source ~/.bashrc
打开一个terminal:
$ echo "PATH=$PATH:/opt/crosstool-ng/bin" >> ~/.bashrc 为后面调用ct-ng命令增加环境变量,让当前用户和超级用户都拥有权限
$ source ~/.bashrc下班了,明天继续写。
7.更改编译事项:
cd /home/crosstool-ng
mkdir crosstool-ng-1.9.3_build 编译时的输出目录
cd crosstool-ng-1.9.3_build/
cp /opt/crosstool-ng/lib/ct-ng-1.9.3/samples/arm-unknown-linux-gnueabi/crosstool.config .config
ct-ng menuconfig 一定要在上面建立的crosstool-ng-1.9.3_build目录下运行
改写下面的路径,按照上面的定义,最后的结果如下
Paths and misc options --->
(/home/crosstool-ng/src) Local tarballs directory 保存源码包路径
(/opt/crosstool-ng/${CT_TARGET}) Prefix directory 交叉编译器的安装路径
Target options --->
*** Target optimisations ***
(armv4t) Architecture level
(arm9tdmi) Emit assembly for CPU
(arm920t) Tune for CPU
C compiler --->
*** Additional supported languages:***
取消下面两个语言的选择
[*] C++
[ ] Fortran
[ ] Java
Paths and misc options --->
*** Build behavior ***
(4) Number of parallel jobs
如果是双核的话,不是在虚拟机下运行的,就填4.在虚拟机下,开2就行了,开4也没用。弄不好整死机了
保存退出,按enter,我按了个Y键,发觉编译出错,然后从新 ct-ng menuconfig,发觉刚才的都没有保存
8.不过还是建议检查一下你下载的linuxKERNEL版本于crosstool-ng初始化的版本是否一致:
vim .config
/KERNEL
不一致则修改修改
CT_KERNEL_VERSION=2.6.32.17
CT_KERNEL_V_2_6_32_17=y
CT_LIBC_GLIBC_MIN_KERNEL=2.6.32.17
:wq保存退出
9.开始编译
.ct-ng build.4(bulid后面有个点,不要忘了。意思为4线程编译。一切正确配置的话,那么要等上30分钟或者1个小时)
这里要注意一下的就是,我一开始在fedora下面看到Extracting 'linux-2.6.33.7'好久,然后就ctrl+d中断程序了,后来才知道,自己设置的src地址错误,然后系统自动下载,让系统自动下载的慢的不行,而且前面显示的时间对不上,以为自己编译错误,然后在那里搞了很久。其实如果这里你src地址没有错,那么前面的时间基本上于系统时间匹配,而且很快一串这样的:
[INFO ] Extracting and patching toolchain components
[EXTRA] Extracting 'linux-2.6.33.7'
[EXTRA] Patching 'linux-2.6.33.7'
[EXTRA] Extracting 'gmp-4.3.2'
[EXTRA] Patching 'gmp-4.3.2'
[EXTRA] Extracting 'mpfr-2.4.2'
[EXTRA] Patching 'mpfr-2.4.2'
[EXTRA] Extracting 'libelf-0.8.13'
[EXTRA] Patching 'libelf-0.8.13'
[EXTRA] Extracting 'binutils-2.19.1'
[EXTRA] Patching 'binutils-2.19.1'
[EXTRA] Extracting 'gcc-4.3.2'
[EXTRA] Patching 'gcc-4.3.2'
[EXTRA] Extracting 'glibc-2.9'
[EXTRA] Patching 'glibc-2.9'
[EXTRA] Extracting 'glibc-ports-2.9'
[EXTRA] Patching 'glibc-ports-2.9'
[EXTRA] Extracting 'dmalloc-5.5.2'
[EXTRA] Patching 'dmalloc-5.5.2'
[EXTRA] Extracting 'duma_2_5_15'
[EXTRA] Patching 'duma-2_5_15'
[EXTRA] Extracting 'gdb-6.8'
[EXTRA] Patching 'gdb-6.8'
[EXTRA] Extracting 'ncurses-5.7'
[EXTRA] Patching 'ncurses-5.7'
[EXTRA] Extracting 'expat-2.0.1'
[EXTRA] Patching 'expat-2.0.1'
[EXTRA] Extracting 'ltrace-0.5.3'
[EXTRA] Patching 'ltrace-0.5.3'
[EXTRA] Extracting 'strace-4.5.19'
[EXTRA] Patching 'strace-4.5.19'
10.最后设置默认路径,方便以后编译的时候不用从新安排路径:
echo "PATH=$PATH:/opt/crosstool-ng/arm-unknown-linux-gnueabi/bin" >> ~/.bashrc //root家目录下的.bashrc
source ~/.bashrc立即生效
arm[tab][tab]之后,你会发现好多
arm-unknown-linux-gnueabi-addr2line
arm-unknown-linux-gnueabi-ar
arm-unknown-linux-gnueabi-as
arm-unknown-linux-gnueabi-c++
arm-unknown-linux-gnueabi-cc
arm-unknown-linux-gnueabi-c++filt
more---
11.恭喜你,你交叉工具链制作成功了。好开心阿。搞了我5天了。一直被一些小小的问题卡主。如果还是不行的童鞋们,请不要着急与放弃。出错的原因有以下几大类:
001:apt-get install 的软件包安装不完整(如果还是安装不了我上面的包,请从新安装你的ubutu,我之前又一次因为ubutu安装不全,直接编译,error)
002:你下载的工具包错误或者版本不对(请仔细核对你的工具包与版本,记得看一下vim .config,地址上面有)
003:在编译的时候,会出现[EXTRA] Extracting 'linux-2.6.33.7',然后很久不动(那么你的src地址错误,请退出,从新检查ct-ng menuconfig)
004:有时候发觉自己没错,但是编译不过,那么请你删除/home/crosstool-ng/ /opt/crosstool-ng/,然后从新在编译一遍,很有可能你的地址或者其他分配错误,或者命令行打错了,我自己就曾经试过几遍。
12.最后一步个人认为比较重要,把系统备份起来咯。详细请参考我的另外一篇文章
http://blog.csdn.net/chen_zhongming/article/details/6683444
参考资料:
http://blog.chinaunix.net/space.php?uid=20543672&do=blog&cuid=2198589
http://home.eeworld.com.cn/my/space.php?uid=67366&do=blog&id=43600
http://hi.baidu.com/caicry/blog/item/f306db639c4281680c33fa1b.html
最后附上我的成功编译过程:(如果你跟我有很大差别,那么很可能你错了,除了顺序)
#.ct-ng build.4
[INFO ] Performing some trivial sanity checks
[INFO ] Build started 20110812.205501
[INFO ] Building environment variables
[EXTRA] Preparing working directories
[EXTRA] Installing user-supplied crosstool-NG configuration
[EXTRA] =================================================================
[EXTRA] Dumping internal crosstool-NG configuration
[EXTRA] Building a toolchain for:
[EXTRA] build = i686-pc-linux-gnu
[EXTRA] host = i686-pc-linux-gnu
[EXTRA] target = arm-unknown-linux-gnueabi
[EXTRA] Dumping internal crosstool-NG configuration: done in 0.10s (at 00:02)
[INFO ] =================================================================
[INFO ] Retrieving needed toolchain components' tarballs
[INFO ] Retrieving needed toolchain components' tarballs: done in 0.36s (at 00:03)
[INFO ] =================================================================
[INFO ] Extracting and patching toolchain components
[EXTRA] Extracting 'linux-2.6.33.7'
[EXTRA] Patching 'linux-2.6.33.7'
[EXTRA] Extracting 'gmp-4.3.2'
[EXTRA] Patching 'gmp-4.3.2'
[EXTRA] Extracting 'mpfr-2.4.2'
[EXTRA] Patching 'mpfr-2.4.2'
[EXTRA] Extracting 'libelf-0.8.13'
[EXTRA] Patching 'libelf-0.8.13'
[EXTRA] Extracting 'binutils-2.19.1'
[EXTRA] Patching 'binutils-2.19.1'
[EXTRA] Extracting 'gcc-4.3.2'
[EXTRA] Patching 'gcc-4.3.2'
[EXTRA] Extracting 'glibc-2.9'
[EXTRA] Patching 'glibc-2.9'
[EXTRA] Extracting 'glibc-ports-2.9'
[EXTRA] Patching 'glibc-ports-2.9'
[EXTRA] Extracting 'dmalloc-5.5.2'
[EXTRA] Patching 'dmalloc-5.5.2'
[EXTRA] Extracting 'duma_2_5_15'
[EXTRA] Patching 'duma-2_5_15'
[EXTRA] Extracting 'gdb-6.8'
[EXTRA] Patching 'gdb-6.8'
[EXTRA] Extracting 'ncurses-5.7'
[EXTRA] Patching 'ncurses-5.7'
[EXTRA] Extracting 'expat-2.0.1'
[EXTRA] Patching 'expat-2.0.1'
[EXTRA] Extracting 'ltrace-0.5.3'
[EXTRA] Patching 'ltrace-0.5.3'
[EXTRA] Extracting 'strace-4.5.19'
[EXTRA] Patching 'strace-4.5.19'
[INFO ] Extracting and patching toolchain components: done in 95.34s (at 01:38)
[INFO ] =================================================================
[INFO ] Installing kernel headers
[EXTRA] Installing kernel headers
[EXTRA] Checking installed headers
[INFO ] Installing kernel headers: done in 9.36s (at 01:48)
[INFO ] =================================================================
[INFO ] Installing GMP
[EXTRA] Configuring GMP
[EXTRA] Building GMP
[EXTRA] Installing GMP
[INFO ] Installing GMP: done in 73.43s (at 03:01)
[INFO ] =================================================================
[INFO ] Installing MPFR
[EXTRA] Configuring MPFR
[EXTRA] Building MPFR
[EXTRA] Installing MPFR
[INFO ] Installing MPFR: done in 21.41s (at 03:23)
[INFO ] =================================================================
[INFO ] Installing binutils
[EXTRA] Configuring binutils
[EXTRA] Building binutils
[EXTRA] Installing binutils
[INFO ] Installing binutils: done in 45.94s (at 04:08)
[INFO ] =================================================================
[INFO ] Installing static core C compiler
[EXTRA] Configuring static core C compiler
[EXTRA] Building static core C compiler
[EXTRA] Installing static core C compiler
[INFO ] Installing static core C compiler: done in 106.12s (at 05:55)
[INFO ] =================================================================
[INFO ] Installing C library headers
[EXTRA] Configuring C library
[EXTRA] Installing C library headers
[INFO ] Installing C library headers: done in 29.85s (at 06:24)
[INFO ] =================================================================
[INFO ] Installing C library start files
[EXTRA] Configuring C library
[WARN ] Removing "-pipe" for use with glibc>=2.6
[EXTRA] Building C library start files
[EXTRA] Installing C library start files
[INFO ] Installing C library start files: done in 22.55s (at 06:47)
[INFO ] =================================================================
[INFO ] Installing shared core C compiler
[EXTRA] Configuring shared core C compiler
[EXTRA] Building shared core C compiler
[EXTRA] Installing shared core C compiler
[INFO ] Installing shared core C compiler: done in 176.48s (at 09:44)
[INFO ] =================================================================
[INFO ] Installing C library
[EXTRA] Configuring C library
[WARN ] Removing "-pipe" for use with glibc>=2.6
[EXTRA] Building C library
[EXTRA] Installing C library
[EXTRA] Fixing C library linker scripts
[INFO ] Installing C library: done in 570.99s (at 19:15)
[INFO ] =================================================================
[INFO ] Installing final compiler
[EXTRA] Configuring final compiler
[EXTRA] Building final compiler
[EXTRA] Installing final compiler
[INFO ] Installing final compiler: done in 231.01s (at 23:06)
[INFO ] =================================================================
[INFO ] Installing libelf for the target
[EXTRA] Configuring libelf
[EXTRA] Building libelf
[EXTRA] Installing libelf
[INFO ] Installing libelf for the target: done in 8.13s (at 23:14)
[INFO ] =================================================================
[INFO ] Installing binutils for target
[EXTRA] Configuring binutils for target
[EXTRA] Building binutils' libraries (libiberty bfd) for target
[EXTRA] Installing binutils' libraries (libiberty bfd) for target
[INFO ] Installing binutils for target: done in 74.03s (at 24:28)
[INFO ] =================================================================
[INFO ] Installing dmalloc
[EXTRA] Configuring dmalloc
[EXTRA] Building dmalloc
[EXTRA] Installing dmalloc
[INFO ] Installing dmalloc: done in 13.41s (at 24:41)
[INFO ] =================================================================
[INFO ] Installing D.U.M.A.
[EXTRA] Copying sources
[EXTRA] Building libraries 'libduma.a libduma.so.0.0.0'
[EXTRA] Installing libraries 'libduma.a libduma.so.0.0.0'
[EXTRA] Installing shared library link
[EXTRA] Installing wrapper script
[INFO ] Installing D.U.M.A.: done in 1.44s (at 24:43)
[INFO ] =================================================================
[INFO ] Installing cross-gdb
[EXTRA] Configuring cross-gdb
[EXTRA] Building cross-gdb
[EXTRA] Installing cross-gdb
[INFO ] Installing cross-gdb: done in 139.72s (at 27:02)
[INFO ] =================================================================
[INFO ] Installing native gdb
[EXTRA] Building static target ncurses
[EXTRA] Building static target expat
[EXTRA] Configuring native gdb
[EXTRA] Building native gdb
[EXTRA] Installing native gdb
[EXTRA] Cleaning up ncurses
[INFO ] Installing native gdb: done in 251.87s (at 31:14)
[INFO ] =================================================================
[INFO ] Installing gdbserver
[EXTRA] Configuring gdbserver
[EXTRA] Building gdbserver
[EXTRA] Installing gdbserver
[INFO ] Installing gdbserver: done in 10.12s (at 31:25)
[INFO ] =================================================================
[INFO ] Installing ltrace
[EXTRA] Copying sources to build dir
[EXTRA] Configuring ltrace
[EXTRA] Building ltrace
[EXTRA] Installing ltrace
[INFO ] Installing ltrace: done in 4.48s (at 31:29)
[INFO ] =================================================================
[INFO ] Installing strace
[EXTRA] Configuring strace
[EXTRA] Building strace
[EXTRA] Installing strace
[INFO ] Installing strace: done in 20.45s (at 31:49)
[INFO ] =================================================================
[INFO ] Cleaning-up the toolchain's directory
[INFO ] Stripping all toolchain executables
[EXTRA] Installing the populate helper
[EXTRA] Installing a cross-ldd helper
[EXTRA] Creating toolchain aliases
[EXTRA] Removing access to the build system tools
[INFO ] Cleaning-up the toolchain's directory: done in 0.83s (at 31:50)
[INFO ] Build completed at 20110812.212650
[INFO ] (elapsed: 31:49.67)
[INFO ] Finishing installation (may take a few seconds)...
[31:50] /