织梦CMS - 轻松建站从此开始!

罗索

用crosstool创建交叉编译工具链

罗索客 发布于 2010-04-08 22:16 点击:次 
言归正传,昨天想将Linux2.6.22移植到s3c2410开发板,用GCC 3.3.2编译内核时出错,我想应该是GCC版本太低了,我以前在编译2.6.19时也出现过错误,看来要自己建立交叉编译环境了。
TAG:

言归正传,昨天想将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 Start

Download 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
# This script has one line for each known working toolchain
# for this architecture.                Uncomment the one you want.
# Generated by generate-demo.pl from buildlogs/all.dats.txt

set -ex
TARBALLS_DIR=$HOME/downloads  //该行表示你即将下载的工具源码压缩包的存放目录!
RESULT_TOP=/opt/crosstool //该行表示将要生成的工具链的存放目录,最好改到有写权限的目录!

export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++"      //该行表示将要生成的工具链支持的语言的种类!
export GCC_LANGUAGES

# Really, you should do the mkdir before running this,
# and chown /opt/crosstool to yourself so you don't need to run as root.
mkdir -p $RESULT_TOP

#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.2.3-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.3.6-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.2.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.5-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-3.4.5-glibc-2.3.6-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.2-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5.dat` sh all.sh --notest
eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.5-tls.dat` sh all.sh --notest   //我选择本行!!!
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.0.2-glibc-2.3.6-tls.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2.dat` sh all.sh --notest
#eval `cat arm9tdmi.dat gcc-4.1.0-glibc-2.3.2-tls.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
TARGET=arm-9tdmi-linux-gnu
GCC_EXTRA_CONFIG="--with-cpu=arm9tdmi --enable-cxx-flags=-mcpu=arm9tdmi"
TARGET_CFLAGS="-O"

这个文件一般用于设置一些变量,一般不用改,用默认即可!

打开crosstool-0.43目录下的gcc-4.0.2-glibc-2.3.5-tls.dat文件,内容如下:

BINUTILS_DIR=binutils-2.16.1
GCC_DIR=gcc-4.0.2
GLIBC_DIR=glibc-2.3.5
LINUX_DIR=linux-2.6.15.4
LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.5
GLIBC_EXTRA_CONFIG="$GLIBC_EXTRA_CONFIG --with-tls --with-__thread                --enable-kernel=2.4.18"

然后你就可以到网上去下载上面红色标记的几个源码包,注意对应的版本号,下载后存放在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里了,也可以在这时给其打补丁).

(chenzhuoyou)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201004/9039.html]
本文出处:百度博客 作者:chenzhuoyou
顶一下
(1)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容