言归正传,昨天想将Linux2.6.22移植到s3c2410开发板,用GCC 3.3.2编译内核时出错,我想应该是GCC版本太低了,我以前在编译2.6.19时也出现过错误,看来要自己建立交叉编译环境了。怕麻烦,找了个编译脚本crosstool ( http://www.kegel.com/crosstool/),版本依旧是0.42,看来好久没更新了,不知道是GCC没更新还是crosstool的作者懒了。下面是作者写的crosstool-howto文档的一段: Quick StartDownload and unpack. For instance: wget http://kegel.com/crosstool/crosstool-0.42.tar.gz tar -xzvf crosstool-0.42.tar.gz cd crosstool-0.42 Then look at the demo scripts; there's one for each supported CPU type. For instance, demo-i686.sh is an example of how to build a toolchain that targets the i686 processor. It sets three important variables: TARBALLS_DIR=$HOME/downloads # where it will save source tarballs RESULT_TOP=/opt/crosstool # where it will install the tools GCC_LANGUAGES="c,c++,java,f77" # which languages it will make compilers for It then builds gcc-3.4.0 and glibc-2.3.2 for i686 with the line eval `cat i686.dat gcc-3.4.0-glibc-2.3.2.dat` sh all.sh --notest Edit the script if you want to change any of these settings or versions. Then (as root) create the directory /opt/crosstool and make it writable by you, and finally (as yourself) run the demo script, e.g. sudo mkdir /opt/crosstool sudo chown $USER /opt/crosstool sh demo-i686.sh When it finishes, you can run the new compiler as /opt/crosstool/gcc-3.4.0-glibc-2.3.2/i686-unknown-linux-gnu/bin/i686-unknown-linux-gnu-gcc. (You might want to put /opt/crosstool/gcc-3.4.0-glibc-2.3.2/i686-unknown-linux-gnu/bin on your PATH; then you can run the compiler as i686-unknown-linux-gnu-gcc.) 我还真弄了好久!问题关键就是USER的权限问题,因为解压crosstool用的都是root账号,结果USER在crosstool目录没建立目录的权限,最后才知道chown +R参数可以递归修改目录拥有者的账号,我笨啊,用小r,弄了半天没弄出来。 接着就是源码包,crosstool可以用脚本自己下载gcc,glibc等相应版本的源码吧,不过那速度……,还真慢,我下了好几个钟,建议还是自己手动下载比较快,放在 /$HOME/downloads 目录下,这个目录可以修改的,下面是网上找的一篇详细介绍。
ARM Linux 交叉编译 工具链 制作攻略 0、制作之前确保你的机子上有如下几个工具:bison flex build-essential。 build-essential主要是用于提供GCC、GLIBC等必要的编译资源,一般做开发的人员机子上应该都会有的。如果没有,对于UBUNTU用户:sudo apt-get install build-essential bison flex,其它用户自己看着办,呵呵! 1、从http://kegel.com/crosstool处下载crosstool-0.43.tar.gz并解开存于$HOME下。 假如你想要arm9tdmi上的工具链(其它工具链方法相同),进入crosstool-0.43目录,用文本编辑器打开demo-arm9tdmi.sh,内容如下: #!/bin/sh set -ex # Really, you should do the mkdir before running this, #eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest echo Done. //上面表示你要选工具链的版本号!"#"起注释功能!我们可以选择一行! 我把RESULT_TOP=/opt/crosstool改成RESULT_TOP=$HOME/toolchains,并在HOME目录下建立downloads 和toolchains两个目录,分别用于存放源码压缩包和将要生成的工具链。 打开crosstool-0.43目录下的arm9tdmi.dat文件,内容如下: KERNELCONFIG=`pwd`/arm.config 这个文件一般用于设置一些变量,一般不用改,用默认即可! 打开crosstool-0.43目录下的gcc-4.0.2-glibc-2.3.5-tls.dat文件,内容如下: BINUTILS_DIR=binutils-2.16.1 然后你就可以到网上去下载上面红色标记的几个源码包,注意对应的版本号,下载后存放在downloads目录下。注意,不需要解压!!你甚至可以去掉LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0这一行(当然也就中需要下载这个包了)!你可以到中国的镜像站点去下载这些包: http://mirrors.shlug.org/ http://www.cn.kernel.org/pub/linux http://www.cn.kernel.org/pub/software ftp://ftp.cn.kernel.org/pub/linux ftp://ftp.cn.kernel.org/pub/software http://ep09.pld-linux.org/~mmazur/linux-libc-headers/ NOW,IT'S OK! 2、进入crosstool-0.43目录,输入./demo-arm9tdmi.sh,然后经过几个小时的编译,就可以在你的toolchains目录中看到你想要的工具链,头文件,库文件等东东了!你可以把工具链所在目录加到环境变量PATH中即可使用工具链了! 注意:crosstool-0.43目录下的PATCH目录中有各个工具链的补丁,如果在编译过程中有错误,可以在crosstool-0.43目录下build目录中的解压后的源文件中打上补丁(我没打补丁也编译成功了,呵呵)。另外,如果不想每次编译时都有浪费时间的解压过程,可以在eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5-tls.dat` sh all.sh --notest 末尾处加--nounpack表示不解压(当然前提是你已经自行解压源码包到了对应的目录/build/gcc-4.0.2-glibc-2.3.5-tls/arm-9tdmi-linux-gnu里了,也可以在这时给其打补丁). |