- 論壇徽章:
- 0
|
一、host準(zhǔn)備工作
$ sudo apt-get install build-essential
$ sudo apt-get install automake
$ sudo apt-get install bison flex
$ sudo apt-get install texinfo
$ sudo apt-get install gwak
二、下載源碼包
在gcc+glibc+bintuils+kernel的組合中,binuitls和kernel是相對(duì)獨(dú)立的,或者說(shuō)允許較大版本變化的,而gcc是最繁瑣的,不同版本需要經(jīng)過(guò)一定的微調(diào)(hack)才能通過(guò)整個(gè)編譯。
here is the tar package of the source code:
binutils-2.19.1.tar.bz2
gcc-4.3.3.tar.bz2
glibc-2.11.tar.bz2
glibc-ports-2.11.tar.bz2
linux-2.6.21.tar.bz2
mpfr-2.4.1.tar.gz
gmp-4.2.4.tar.bz2
There is the patch:
-rw-r--r-- 1 rambo rambo 570641 2010-01-25 10:15 binutils-2.19.1-branch_update-5.patch
-rw-r--r-- 1 rambo rambo 3649 2010-01-25 10:16 binutils-2.19.1-posix-1.patch
-rw-r--r-- 1 rambo rambo 367968 2010-01-18 14:10 gcc-4.3.3-branch_update-5.patch
-rw-r--r-- 1 rambo rambo 14268 2010-01-18 14:10 gcc-4.3.3-posix-1.patch
-rw-r--r-- 1 rambo rambo 1446 2010-01-25 10:08 gcc_eh.patch.cross
-rw-r--r-- 1 rambo rambo 11058 2010-01-26 17:49 gmp-4.2.4-branch_update-1.patch
-rw-r--r-- 1 rambo rambo 6770 2010-01-26 17:57 mpfr-2.4.1-branch_update-2.patch
三 源代碼準(zhǔn)備:
Create the proper directory.
untar all tar packages, apply these patches.
四 運(yùn)行腳本
Shell file:
#!/bin/sh
export proot=/home/rambo/embedded
export prefix=/home/rambo/embedded/cross-tools
export target=arm-none-linux-gnueabi
export PATH=$prefix/tools/bin:$PATH
export host=i686-cross-linux-gnu
#上面i486和i686對(duì)編譯沒(méi)什么影響
export linux_tar=linux-2.6.21
export binutils_tar=binutils-2.19.1
export gcc_tar=gcc-4.3.3
export glibc_tar=glibc-2.11
#assume something:all source&patch have been ready.
#build bintuils
cd $proot/tar/build
mkdir binutils
cd binutils
AR=ar AS=as ../../src/$binutils_tar/configure --build=$host --host=$host --target=$target --prefix=$prefix/tools --with-sysroot=$prefix --disable-nls --enable-shared --disable-multilib --disable-werror
make all
make install
#install the linux kernel headers
cd $proot/tar/src
cd $linux_tar
mkdir -p $prefix/usr/include
make mrproper
make ARCH=arm zylonitep_alp_eabi_defconfig
make ARCH=arm headers_check
make ARCH=arm INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* ${prefix}/usr/include
find ${prefix}/usr/include -name .install -or -name ..install.cmd | xargs rm -fv
#Build gcc the first time
cd $proot/tar/build
mkdir gcc
cd gcc
AR=ar LDFLAGS="-Wl,-rpath,${prefix}/lib" \
../../src/$gcc_tar/configure \
--build=$host \
--host=$host \
--target=$target \
--prefix=$prefix/tools \
--enable-languages=c \
--disable-nls \
--disable-shared \
--disable-threads \
--disable-libmudflap \
--disable-libssp \
--disable-libgomp \
--disable-decimal-float \
--without-headers --with-newlib \
--with-sysroot=$prefix
make
make install
#Build glibc
cd $proot/tar/build
rm -Rf glibc
mkdir glibc
cd glibc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_arm_tls=yes" >> config.cache
BUILD_CC="gcc" CC=${target}-gcc AR=${target}-ar RANLIB=${target}-ranlib \
../../src/${glibc_tar}/configure \
--build=${host} \
--host=${target} \
--target=${target} \
--prefix=/usr \
--with-tls \
--disable-profile --enable-add-ons=ports,nptl \
--enable-kernel=2.6.0 --with-__thread \
--with-binutils=${prefix}/bin \
--with-headers=$prefix/usr/include \
--cache-file=config.cache
make all
make install install_root=$prefix
#Build gcc the second time
cd $proot/tar/build
rm -Rf gcc
mkdir gcc
cd gcc
../../src/$gcc_tar/configure \
--build=$host \
--host=$host \
--target=$target \
--prefix=$prefix/tools \
--enable-languages=c,c++ --enable-c99 \
--enable-threads=posix \
--enable-long-long \
--enable-shared \
--enable-__cxa_atexit \
--disable-multilib \
--disable-nls \
--with-sysroot=$prefix
make
make install
五 驗(yàn)證工具鏈
After cross-compile, the directory is here:
embedded/
|-- cross-tools
| |-- etc
| |-- lib
| |-- sbin
| |-- tools
| | |-- arm-none-linux-gnueabi
| | |-- bin
| | |-- i686-cross-linux-gnu
| | |-- include
| | |-- info
| | |-- lib
| | |-- libexec
| | |-- man
| | `-- share
| `-- usr
| |-- bin
| |-- include
| |-- lib
| |-- libexec
| |-- sbin
| `-- share
|-- tar
| |-- build
| | |-- binutils
| | |-- gcc
| | `-- glibc
| |-- patch
| `-- src
| |-- binutils-2.19.1
| |-- gcc-4.3.3
| |-- glibc-2.11
| `-- linux-2.6.21
`-- test
Using the cross gcc to compile a test app.
arm-none-linux-gnueabi-gcc -static main.c
下載到板子上驗(yàn)證無(wú)誤。
后記
從開(kāi)始搞這個(gè)交叉工具鏈到目前完成,整整用了15個(gè)工作日。這里面有個(gè)主要的問(wèn)題是EABI,我開(kāi)始的時(shí)候并不知道怎么指定gcc的EABI,還以為4.1以上的gcc自動(dòng)都是EABI,結(jié)果就是生成的內(nèi)核能跑,而init進(jìn)程(根文件系統(tǒng)的第一個(gè)進(jìn)程)卻運(yùn)行不了。而最讓我啼笑皆非的是 readelf,這絕對(duì)對(duì)我是誤導(dǎo)的,例如:
一個(gè)ABI的文件
#readelf -h aa
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x80f0
Start of program headers: 52 (bytes into file)
Start of section headers: 2361284 (bytes into file)
Flags: 0x2, has entry point, GNU EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 4
Size of section headers: 40 (bytes)
Number of section headers: 35
Section header string table index: 32
看見(jiàn)Flags那行了嗎?清清楚楚寫(xiě)的是GNU EABI,其實(shí)它是ABI(想起來(lái)臺(tái)詞:它看起來(lái)是一個(gè)電吹風(fēng),其實(shí)還是刮胡刀)
真正的EABI是這樣的
#readelf -h a.out
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8130
Start of program headers: 52 (bytes into file)
Start of section headers: 2460164 (bytes into file)
Flags: 0x4000002, has entry point, Version4 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 36
Section header string table index: 33
![]()
文件:tool_build.sh.zip
大小:1KB
下載:
下載
腳本文件
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u2/60303/showart_2162288.html |
|