嵌入式linux系统构建(1)

   

o binutils功能:
n 汇编语言(.s)>目标文件->可执行程序
n 查看二进制文件信息
o 组成:一组可执行程序
n asld
n objdumpreadelfar ……
o 支持多种目标机

 

o glibc功能:
n 提供语言和操作系统的标准库函数
o 组成:若干可执行程序 + 大量库
n lddiconvlocale……
n ISO CPOSIXUNIXGNU
o
绝大部分与目标机无关

制作开发工具

交叉工具链的建立:

建立工具链的第一步就是选择我们将要使用的组建版本

这包括:binutils ,gcc,glibc

binutils中:主要的工具有as汇编器,ld链接器,objdump显示目标文件内容有关信息,readelf 显示elf文件有关信息。

 

 

 

  as [option...] [asmfile...]

n 汇编器,可由gcc -c代替
o ld [options] file...
n 连接器,可由gcc代替

o
binutils提供许多二进制工具,没有binutils,gcc无法正常工作。
 
o objdump [option(s)] [file(s)]
n 反汇编各种格式的目标文件和可执行程序
o 常用选项:
n -d
o 只反汇编代码段
n -D
o 反汇编代码段和数据段
n -S
o 混合输出源代码和汇编代码,编译时必须加-g选项

 

通常由gcc调用,一般不直接使用

 

binutils中:主要的工具有as汇编器,ld链接器,objdump显示目标文件内容有关信息,readelf elf文件有关信息。

 

 

 

1 设置环境变量,准备源码及相关补丁
1.1 设置环境变量
[arm@localhost arm]#vi ~/.bashrc
export PREFIX=/usr/local/arm/3.4.4//指定安装目录
export TARGET=armlinux//指定目标
export SYSROOT=${PREFIX}/sysroot
export ARCH=arm  //目标板体系结构
export CROSS_COMPILE=${TARGET}export 
PATH=${PREFIX}/bin:$PATH //可执行文件路径
export SRC=/home/arm/dev_home/btools/tchain3.4.4

 

//以上的环境变量的设置也可以看看书,感觉书上说的比较正规 .P123

 

1.5 准备内核头文件
1.5.1 使用当前平台的gcc编译内核头文件
[arm@localhost tchain3.4.4]#cd ${KERNEL}
[arm@localhost kernel]#tar xvfz linux2.6.14.1.
tar.gz
[arm@localhost kernel]#cd linux2.6.14.1
[arm@localhost linux2.6.14.1]#make ARCH=arm menuconfig
[arm@localhost linux2.6.14.1]#make
1.5.2 复制内核头文件
[arm@localhost kernel]#su root
[root@localhost kernel]#mkdir p
${SYSROOT}/usr/include
[root@localhost kernel]#cp -a include/linux  ${SYSROOT}/usr/include/linux
[root@localhost kernel]#cp -a include/asmi386 ${SYSROOT}/usr/include/asm
[root@localhost kernel]#cp -a include/asmgeneric ${SYSROOT}/usr/include/asmgeneric
[root@localhost kernel]#exit
[arm@localhost kernel]#

 

以上是工具链所需要的include目录,并将内核头文件复制过去。

我的理解是:在建立目标文件之后,生成可执行文件中链接时,链接器ld就是在这个目录中,找要链接的库文件!

 

1.4 编译 GNU binutils
重新以arm用户登陆,让新设置的环境变量起作用.
[arm@localhost arm]#su arm
[arm@localhost arm]#cd ${SRC}
[arm@localhost tchain3.4.4]#tar xzvf binutils2.16.tar.gz
[arm@localhost tchain3.4.4]#mkdir -p BUILD/binutils2.16
[arm@localhost binutils2.16]#cd BUILD/binutils2.16
[arm@localhost binutils2.16]#../../binutils2.16/configure prefix=${PREFIX} target=${TARGET}withsysroot=${SYSROOT}
[arm@localhost binutils2.16]# make
[arm@localhost binutils2.16]# su root
[root@localhost binutils2.16]# make install
[root@localhost binutils2.16]# exit
[arm@localhost binutils2.16]#

 

1.configure 执行为每个工具程序产生适当的Makefile

2.make 编译binutils

3.make install 安装binutils

 

1.6 译编glibc头文件
[arm@localhost kernel]#cd ${SRC}
[arm@localhost chain3.4.4]#tar xvfz glibc2.3.5.tar.gz
[arm@localhost chain3.4.4]#patch dglibc2.3.5p1< ioperm.c.diff
[arm@localhost glibc2.3.5]#cd glibc-2.3.5
[arm@localhost glibc2.3.5]#tar xvfz /glibclinuxthreads2.3.5.tar.gz/glibc的附加包
[arm@localhost chain3.4.4]#cd ..
[arm@localhost chain3.4.4]#mkdir BUILD/glibc2.3.5headers
[arm@localhost chain3.4.4]#cd BUILD/glibc2.3.5headers
[arm@localhost glibc2.3.5headers]#../../glibc2.3.5/configure prefix=/usrhost=${TARGET} /enableaddons=
linuxthreads –withheaders=${SYSROOT}/usr/include
[arm@localhost glibc2.3.5headers]#su root
[root@localhost glibc2.3.5headers]#make cross-compiling=yes,install_root=${SYSROOT} install-headers
[root@localhost glibc2.3.5headers]#touch${SYSROOT}/usr/include/gnu/stubs.h
[root@localhost glibc2.3.5headers]#touch${SYSROOT}/usr/include/bits/stdio_lim.h
[root@localhost glibc2.3.5headers]#exit
[arm@localhost glibc2.3.5headers]#
注意: prefix=/usr :是gcc寻找库的搜索路径。

 

 因为我们没有将CC变量定义为既有的交叉编译器,所以我们必须把cross-compiling设置为yes,这样glibc的编译脚本才不会建立原生的链接库,最后是用 install-headers要求make安装头文件。

接下来,我们产生一个假的stubs.h(如上)文件,因为gcc在建立glibc时,需要这个文件(经交叉编译的glibc在安装期间可以产生该文件)。

下一步:我们可以建立引导程序Gcc编译器(如下步:)

 

 

引导编译器的设置:

与binutils相比,gcc套件只包含一个工具程序即:GNU编译器

1.7 编译gcc第一阶段
[arm@localhost glibc2.3.5headers]#cd ${SRC}
[arm@localhost chain3.4.4]#tar -xjvf gcc-3.4.4.tar.bz2
[arm@localhost chain3.4.4]#patch -d gcc-3.4.4p1< flow.c.diff
[arm@localhost chain3.4.4]#patch -d gcc-3.4.4p1< tlinux.diff
[arm@localhost chain3.4.4]#mkdir -p BUILD/gcc3.4.4stage1
[arm@localhost chain3.4.4]#cd BUILD/gcc-3.4.4stage1
[arm@localhost gcc3.4.4stage1]#../../gcc-3.4.4/configure prefix=${PREFIX}target=${TARGET} /enable-languages=c withsysroot=${SYSROOT}
注意:不能加上"disable-shared"
选项。
[arm@localhost gcc3.4.4stage1]#make all-gcc
[arm@localhost gcc3.4.4stage1]#su root
[root@localhost gcc3.4.4stage1]#make install-gcc
[root@localhost gcc3.4.4stage1]#exit
[arm@localhost gcc3.4.4stage1]#

 

1.8 编译完整的glibc
[arm@localhost gcc3.4.4stage1]#cd ${SRC}
[arm@localhost tchain3.4.4]#mkdir BUILD/glibc2.3.5
[arm@localhost tchain3.4.4]#cd BUILD/glibc2.3.5
[arm@localhost glibc2.3.5]#BUILD_CC=gcc CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar /RANLIB=${CROSS_COMPILE}ranlib AS=${CROSS_COMPILE}as LD=${CROSS_COMPILE}ld /../../glibc2.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=${SYSROOT}/usr/include
明:
prefix:
指定安装路径。
target:
指定目标平台。
host:
指定当前平台。
build:
指定编译平台。
with-sysroot:

用于指定编译所需要的头文件,及链接库。
enable-add-ons://“下载”附加包
加入其它的库,如线程库等。
enable-languages:
指定gcc所支持的语言。

--with-headers其告诉命令配置脚本,何处可以找到,我们前面设置的内核头文件!

[arm@localhost glibc2.3.5]#make
[arm@localhost glibc2.3.5]#su root
[root@localhost glibc2.3.5]#make install_root=${SYSROOT} install
[root@localhost glibc2.3.5]#exit
[arm@localhost glibc2.3.5]#

 

1.9 编译完整的gcc
[arm@localhost glibc2.3.5]#cd ${SRC}
[arm@localhost tchain3.4.4]#mkdir BUILD/gcc3.4.4
[arm@localhost tchain3.4.4]#cd BUILD/gcc3.4.4
[arm@localhost gcc3.4.4]#../../gcc3.4.4/configure prefix=${PREFIX} target=${TARGET} /enable-languages=c with-sysroot=${SYSROOT}
[arm@localhost gcc3.4.4]#make
[arm@localhost gcc3.4.4]#su root
[root@localhost gcc3.4.4]#make install
[root@localhost gcc3.4.4]#exit
[arm@localhost gcc3.4.4]#

 

ok! 交叉编译器搞定!

找个时间,自己动手实际做一做!!!!!

 

o
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值