嵌入式linux 交叉编译环境的建立——详细介绍222

来源:百度文库 编辑:神马文学网 时间:2024/04/28 23:02:48
arm-linux-gcc 3.4.4
arm-linux-gcc 3.4.4
1. Linux下工作用户及环境
Linux version 2.6.9-22.EL (bhcompile@porky.build.redhat.com) (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1 Mon Sep 19 18:20:28 EDT 2005
2. 设置环境变量,准备源码及相关补丁
2.1 设置环境变量
[xxxx@ ~]$ vi ~/.bashrc
export PATH=$PATH:/usr/local/arm/3.4.4/bin
【注意】如果你已经安装过arm-linux-gcc,并且已经加入了环境变量中,将其从环境中去掉保证root用户和xxxx用户环境中没有arm-linux-gcc
[xxxx@ ~]$ mkdir ctools
将准备好的源码及补丁存放在文件夹ctools中。
2.2 准备源码包
2.2.1 binutils  名称:binutils-2.16.tar.gz
下载地址:http://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.gz
2.2.2 gcc  名称: gcc-3.4.4.tar.bz2
下载地址:http://ftp.gnu.org/gnu/gcc/gcc-3.4.4/gcc-3.4.4.tar.bz2
2.2.3 glibc  名称: glibc-2.3.5.tar.gz和glibc-linuxthreads-2.3.5.tar.gz
下载地址:http://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.gz
http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.gz
2.2.4 linux kernel  名称: linux-2.6.14.1.tar.bz2
下载地址:http://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.1.tar.bz2
2.2.5 gdb  名称: gdb-6.4.tar.gz
下载地址:http://ftp.gnu.org/pub/gnu/gdb/gdb-6.4.tar.gz
2.3 准备补丁
2.3.1 ioperm.c.diff
作用: 打修正ioperm()函数
下载地址:http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff
2.3.2 flow.c.diff
作用: 修改gcc一处bug
下载地址:http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flow.c.diff?cvsroot=gcc&only_with_tag=csl-arm-branch&r1=1.563.4.2&r2=1.563.4.32.3.3 t-linux.diff
作用: 该补丁用于产生crti.o和crtn.o文件.
下载地址:http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff
2.4 编译GNU binutils
[xxxx@ ~]$ cd ctools
[xxxx@ ctools]$ mkdir BUILD
[xxxx@ ctools]$ tree -L 1
|-- BUILD
|-- binutils-2.16
|-- binutils-2.16.tar.gz
|-- flow.c.diff
|-- gcc-3.4.4
|-- gcc-3.4.4.tar.bz2
|-- gdb-6.4.tar.gz
|-- glibc-2.3.5
|-- glibc-2.3.5.tar.gz
|-- glibc-linuxthreads-2.3.5.tar.gz
|-- ioperm.c.diff
|-- linux-2.6.14.1.tar.bz2
`-- t-linux.diff
[xxxx@ ctools]$ tar zxvf binutils-2.16.tar.gz
[xxxx@ ctools]$ mkdir -p BUILD/binutils-2.16
[xxxx@ ctools]$ cd BUILD/binutils-2.16
[xxxx@ binutils-2.16]$ ../../binutils-2.16/configure --prefix=/usr/local/arm/3.4.4 --target=arm-linux --with-sysroot=/usr/local/arm/3.4.4/sysroot
[xxxx@ binutils-2.16]$ make
[xxxx@ binutils-2.16]$ su -m
[root@ binutils-2.16]# make install
[root@ binutils-2.16]# exit
[xxxx@ binutils-2.16]$
2.5 准备内核头文件
2.5.1 使用当前平台的gcc编译内核头文件
[xxxx@ binutils-2.16]$ cd ../../
[xxxx@ ctools]$
[xxxx@ ctools]$ tar jxvf ../btools/tchain3.4.4/linux-2.6.14.1.tar.bz2
[xxxx@ ctools]$ cd linux-2.6.14.1/
[xxxx@ linux-2.6.14.1]$ cp arch/arm/configs/smdk2410_defconfig  .config
选择了一个配置文件smdk2410_defconfig,你可以根据你的需要选择
[xxxx@ linux-2.6.14.1]$ make ARCH=arm menuconfig
System Type  --->
ARM system type (Samsung S3C2410)  --->
S3C24XX Implementations  --->
[ ] Simtec Electronics ANUBIS
[ ] Simtec Electronics BAST (EB2410ITX)
[ ] IPAQ H1940
[ ] Acer N30
[*] SMDK2410/A9M2410
[ ] SMDK2440
[ ] Thorcom VR1000
[ ] HP iPAQ rx3715
[ ] NexVision OTOM Board
[ ] NexVision NEXCODER 2440 Light Board
--- S3C2410 Boot
--- S3C2410 Setup
[ ] S3C2410 DMA support
(0) S3C2410 UART to use for low-level messages
--- Processor Type
--- Processor Features
[*] Support Thumb user binaries
[ ] Disable I-Cache
[ ] Disable D-Cache
[ ]   Force write through D-cache
退出时
Do you wish to save your new kernel configuration?
< Yes >      <  No  >
选择Yes
[xxxx@ linux-2.6.14.1]$ make
2.5.2 复制内核头文件
[xxxx@ linux-2.6.14.1]$ su -m
[root@ linux-2.6.14.1]# mkdir -p /usr/local/arm/3.4.4/sysroot/usr/include
[root@ linux-2.6.14.1]# cp -a include/linux /usr/local/arm/3.4.4/sysroot/usr/include/linux
[root@ linux-2.6.14.1]# cp -a include/asm-arm /usr/local/arm/3.4.4/sysroot/usr/include/asm
[root@ linux-2.6.14.1]# cp -a include/asm-generic /usr/local/arm/3.4.4/sysroot/usr/include/asm-generic
[root@ linux-2.6.14.1]# exit
[xxxx@ linux-2.6.14.1]$
2.6 编译glibc头文件
[xxxx@ linux-2.6.14.1]$ cd ../
[xxxx@ ctools]$ tar zxvf glibc-2.3.5.tar.gz
[xxxx@ ctools]$ patch -d glibc-2.3.5 -p1 < ioperm.c.diff
[xxxx@ ctools]$ cd glibc-2.3.5
[xxxx@ glibc-2.3.5]$ tar zxvf  ../glibc-linuxthreads-2.3.5.tar.gz
[xxxx@ glibc-2.3.5]$ cd ..
[xxxx@ ctools]$ mkdir -p BUILD/glibc-2.3.5-headers
[xxxx@ ctools]$ cd BUILD/glibc-2.3.5-headers/
[xxxx@ glibc-2.3.5-headers]$ ../../glibc-2.3.5/configure --prefix=/usr --host=arm-linux --enable-add-ons=linuxthreads --with-headers=/usr/local/arm/3.4.4/sysroot/usr/include
[xxxx@ glibc-2.3.5-headers]$ su -m
[root@ glibc-2.3.5-headers]# make cross-compiling=yes install_root=/usr/local/arm/3.4.4/sysroot install-headers
[root@ glibc-2.3.5-headers]# touch /usr/local/arm/3.4.4/sysroot/usr/include/gnu/stubs.h
[root@ glibc-2.3.5-headers]# touch /usr/local/arm/3.4.4/sysroot/usr/include/bits/stdio_lim.h
[root@ glibc-2.3.5-headers]# exit
[xxxx@ glibc-2.3.5-headers]$
2.7 编译gcc 第一阶段
[xxxx@ glibc-2.3.5-headers]$ cd ../../
[xxxx@ ctools]$ tar jxvf gcc-3.4.4.tar.bz2
[xxxx@ ctools]$ patch -d gcc-3.4.4 -p1 < flow.c.diff
[xxxx@ ctools]$ patch -d gcc-3.4.4 -p1 < t-linux.diff
[xxxx@ ctools]$ mkdir -p BUILD/gcc-3.4.4-stage1
[xxxx@ ctools]$ cd BUILD/gcc-3.4.4-stage1/
[xxxx@ gcc-3.4.4-stage1]$ ../../gcc-3.4.4/configure --prefix=/usr/local/arm/3.4.4 --target=arm-linux --enable-languages=c --with-sysroot=/usr/local/arm/3.4.4/sysroot
【注意】不能加上--disable-shared
[xxxx@ gcc-3.4.4-stage1]$ make all-gcc
[xxxx@ gcc-3.4.4-stage1]$ su -m
[root@ gcc-3.4.4-stage1]# make install-gcc
[root@ gcc-3.4.4-stage1]# exit
[xxxx@ gcc-3.4.4-stage1]$
2.8 编译完整的glibc
[xxxx@ gcc-3.4.4-stage1]$ cd ../../
[xxxx@ ctools]$ mkdir -p BUILD/glibc-2.3.5
[xxxx@ ctools]$ cd BUILD/glibc-2.3.5
[xxxx@ glibc-2.3.5]$ BUILD_CC=gcc CC=arm-linux-gcc AR=arm-linux-ar RANLIB=arm-linux-ranlib AS=arm-linux-as LD=arm-linux-ld ../../glibc-2.3.5/configure --prefix=/usr --build=i386-redhat-linux --host=arm-unknown-linux-gnu --target=arm-unknown-linux-gnu --without-__thread --enable-add-ons=linuxthreads --with-headers=/usr/local/arm/3.4.4/sysroot/usr/include
【说明】
--prefix:            指定安装路径。
--target:           指定目标平台。
--host:              指定当前平台。
--build:             指定编译平台。
--with-sysroot:      用于指定编译所需要的头文件,及链接库。
--enable-add-ons:    加入其它的库,如线程库等。
--enable-languages:  指定gcc所支持的语言。
[xxxx@ glibc-2.3.5]$ make
[xxxx@ glibc-2.3.5]$ su -m
[root@ glibc-2.3.5]# make install_root=/usr/local/arm/3.4.4/sysroot install
[root@ glibc-2.3.5]# exit
[xxxx@ glibc-2.3.5]$
2.9 编译完整的gcc
[xxxx@ glibc-2.3.5]$ cd ../../
[xxxx@ ctools]$ mkdir -p BUILD/gcc-3.4.4
[xxxx@ ctools]$ cd BUILD/gcc-3.4.4
[xxxx@ gcc-3.4.4]$../../gcc-3.4.4/configure --prefix=/usr/local/arm/3.4.4 --target= arm-linux --with-sysroot=/usr/local/arm/3.4.4/sysroot --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --with-softfloat-support=internal --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
[xxxx@ gcc-3.4.4]$ make
[xxxx@ gcc-3.4.4]$ su -m
[root@ gcc-3.4.4]# make install
[root@ gcc-3.4.4]# exit
[xxxx@ gcc-3.4.4]$
[xxxx@ gcc-3.4.4]$ arm-linux-gcc -v
Reading specs from /usr/local/arm/3.4.4/lib/gcc/arm-linux/3.4.4/specsConfigured with: ../../gcc-3.4.4/configure --prefix=/usr/local/arm/3.4.4 --target=arm-linux --with-sysroot=/usr/local/arm/3.4.4/sysroot --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --with-softfloat-support=internal --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.4
[xxxx@ gcc-3.4.4]$ cd /usr/local/arm/3.4.4/
[xxxx@ 3.4.4]$ tree -L 1
|-- arm-linux
|-- bin
|-- include
|-- info
|-- lib
|-- libexec
|-- man
|-- share
`-- sysroot
[xxxx@ 3.4.4]$ du -sh
193M    .
[xxxx@ 3.4.4]$ ls bin/
arm-linux-addr2line  arm-linux-c++filt  arm-linux-gcc-3.4.4  arm-linux-nm       arm-linux-readelf
arm-linux-ar         arm-linux-cpp      arm-linux-gccbug     arm-linux-objcopy  arm-linux-size
arm-linux-as         arm-linux-g++      arm-linux-gcov       arm-linux-objdump  arm-linux-strings
arm-linux-c++        arm-linux-gcc      arm-linux-ld         arm-linux-ranlib   arm-linux-strip
2.11 编译主机上运行的gdb
[xxxx@ 3.4.4]$ cd ~/ctools/
[xxxx@ ctools]$ tar zxvf gdb-6.4.tar.gz
[xxxx@ ctools]$ mkdir -p BUILD/gdb-6.4-host
[xxxx@ ctools]$ cd  BUILD/gdb-6.4-host
[xxxx@ gdb-6.4-host]$ export CC=gcc
[xxxx@ gdb-6.4-host]$ ../../gdb-6.4/configure --target=arm-linux
[xxxx@ gdb-6.4-host]$ make
[xxxx@ gdb-6.4-host]$ file gdb/gdb
gdb/gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), for GNU/Linux 2.2.0, not stripped
2.12建立目标平台上运行的gdbserver
[xxxx@ 3.4.4]$ cd ../../
[xxxx@ ctools]$ mkdir -p BUILD/ gdbserver-6.4
[xxxx@ ctools]$ cd  BUILD/gdbserver-6.4
[xxxx@ gdbserver-6.4]$ export CC=/usr/local/arm/3.4.4/bin/arm-linux-gcc
[xxxx@ gdbserver-6.4]$ ../../gdb-6.4/gdb/gdbserver/configure --host=arm-linux
[xxxx@ gdbserver-6.4]$ make
[xxxx@ gdbserver-6.4]$ file gdbserver
gdbserver: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
3. GNU交叉工具链的下载
工具链的官方下载地址:http://www.arm.linux.org.uk/
可以从该站点下载2.95.3, 3.0以及3.2工具链:
ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/cross-2.95.3.tar.bz2
ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/cross-3.0.tar.bz2
ftp://ftp.handhelds.org/projects/toolchain/arm-linux-gcc-3.3.2.tar.bz2
ftp://ftp.handhelds.org/projects/toolchain/arm-linux-gcc-3.4.1.tar.bz2
http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/gcc-3.4.4.tar.bz2
http://blog.chinaunix.net/u2/70592/article_87727.html