免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3128 | 回复: 1
打印 上一主题 下一主题

自己实验建立交叉编译工具链(ARM EABI based) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-27 16:17 |只看该作者 |倒序浏览
一、host准备工作
$ 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是相对独立的,或者说允许较大版本变化的,而gcc是最繁琐的,不同版本需要经过一定的微调(hack)才能通过整个编译。
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
三 源代码准备:
Create the proper directory.
untar all tar packages, apply these patches.
四 运行脚本
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对编译没什么影响
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
五 验证工具链
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
下载到板子上验证无误。
后记
从开始搞这个交叉工具链到目前完成,整整用了15个工作日。这里面有个主要的问题是EABI,我开始的时候并不知道怎么指定gcc的EABI,还以为4.1以上的gcc自动都是EABI,结果就是生成的内核能跑,而init进程(根文件系统的第一个进程)却运行不了。而最让我啼笑皆非的是 readelf,这绝对对我是误导的,例如:
一个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
看见Flags那行了吗?清清楚楚写的是GNU EABI,其实它是ABI(想起来台词:它看起来是一个电吹风,其实还是刮胡刀)
真正的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
        下载:
下载
       
脚本文件
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/60303/showart_2162288.html

论坛徽章:
0
2 [报告]
发表于 2013-08-22 00:27 |只看该作者
本帖最后由 paomu52 于 2013-09-03 00:22 编辑

兄弟 我现在也在制作交叉编译器(gcc 3.4.3 binutils-2.16.1 glibc-2.3.3)按照网上的做法编译成功了 也能用  但死活不能指定为
Flags:                             0x4000002, has entry point, Version4 EABI。
看了一下你的过程 不知道你制作glibc头文件的时候这一步make ARCH=arm zylonitep_alp_eabi_defconfig,是怎么来的?我的那个configs 目录下没有这个文件所以报错了,请明示谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP