zoukankan      html  css  js  c++  java
  • GNU 交叉工具链

    1   设置环境变量,准备源码及相关补丁

    1.1 设置环境变量

    [arm@localhost arm]#vi ~/.bashrc export PREFIX=/usr/local/arm/3.4.4 export TARGET=arm­linux

    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

    1. 2 准备源码包

    1.2.1  binuils

    名称:binutils­2.16.tar.gz

    下载地址:http://ftp.gnu.org/gnu/binutils/binutils­2.16.tar.gz

    1.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

    1.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

    1.2.4   linux kernel

    名称:linux­2.6.14.1.tar.gz

    下载地址: http://ftp.kernel.org/pub/linux/kernel/v2.6/linux­2.6.14.1.tar.gz

    1.3 准备补丁

    1.3.1  ioperm.c.diff

    作用:打修正 ioperm()函数.

    下载地址:http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff

    1.3.2 flow.c.diff

    作用:该补丁用于产生 crti.o 和 crtn.o 文件。

    下载地址: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.3

    1.3.3 t-linux.diff

    作用:修改 gcc 一处 bug

    下载地址:http://frank.harvard.edu/~coldwell/toolchain/t­linux.diff

    1.4   编译 GNU binutils

    重新以 arm 用户登陆,让新设置的环境变量起作用. [arm@localhost arm]#su arm

    [arm@localhost arm]#cd ${SRC}

    [arm@localhost tchain3.4.4]#tar xzvf binutils­2.16.tar.gz [arm@localhost tchain3.4.4]#mkdir ­p BUILD/binutils­2.16 [arm@localhost binutils­2.16]#cd BUILD/binutils­2.16

    [arm@localhost binutils­2.16]# ../../binutils­2.16/configure ­­prefix=${PREFIX} ­­target=${TARGET}

    ­­with­sysroot=${SYSROOT} [arm@localhost binutils­2.16]#make [arm@localhost binutils­2.16]#su root [root@localhost binutils­2.16]#make install [root@localhost binutils­2.16]#exit [arm@localhost binutils­2.16]#

    1.5 准备内核头文件

    1.5.1 使用当前平台的 gcc 编译内核头文件

    [arm@localhost tchain3.4.4]#cd ${KERNEL} [arm@localhost kernel]#tar xvfz linux­2.6.14.1.tar.gz [arm@localhost kernel]#cd linux­2.6.14.1

    [arm@localhost linux­2.6.14.1]#make ARCH=arm menuconfig [arm@localhost linux­2.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/asm­i386 ${SYSROOT}/usr/include/asm [root@localhost kernel]#cp ­a include/asm­generic ${SYSROOT}/usr/include/asm­generic [root@localhost kernel]#exit

    [arm@localhost kernel]#

    1.6   译编 glibc 头文件

    [arm@localhost kernel]#cd ${SRC}

    [arm@localhost chain3.4.4]#tar xvfz glibc­2.3.5.tar.gz [arm@localhost chain3.4.4]#patch ­d glibc­2.3.5 ­p1 < ioperm.c.diff [arm@localhost glibc­2.3.5]#cd glibc­2.3.5

    [arm@localhost glibc­2.3.5]#tar xvfz ../glibc­linuxthreads­2.3.5.tar.gz [arm@localhost chain3.4.4]#cd ..

    [arm@localhost chain3.4.4]#mkdir BUILD/glibc­2.3.5­headers [arm@localhost chain3.4.4]#cd BUILD/glibc­2.3.5­headers

    [arm@localhost glibc­2.3.5­headers]#../../glibc­2.3.5/configure ­­prefix=/usr ­­host=${TARGET}

    ­­enable­add­ons=linuxthreads –with­headers=${SYSROOT}/usr/include [arm@localhost glibc­2.3.5­headers]#su root

    [root@localhost glibc­2.3.5­headers]#make cross­compiling=yes install_root=${SYSROOT} install­headers [root@localhost glibc­2.3.5­headers]#touch ${SYSROOT}/usr/include/gnu/stubs.h

    [root@localhost glibc­2.3.5­headers]#touch ${SYSROOT}/usr/include/bits/stdio_lim.h [root@localhost glibc­2.3.5­headers]#exit

    [arm@localhost glibc­2.3.5­headers]#

    注意: ­­prefix=/usr :是 gcc 寻找库的搜索路径。

    1.7   编译 gcc 第一阶段

    [arm@localhost glibc­2.3.5­headers]#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.4 ­p1 < flow.c.diff [arm@localhost chain3.4.4]#patch ­d gcc­3.4.4 ­p1 < t­linux.diff [arm@localhost chain3.4.4]#mkdir ­p BUILD/gcc­3.4.4­stage1 [arm@localhost chain3.4.4]#cd BUILD/gcc­3.4.4­stage1

    [arm@localhost gcc­3.4.4­stage1]#../../gcc­3.4.4/configure ­­prefix=${PREFIX} ­­target=${TARGET}

    ­­enable­languages=c ­­with­sysroot=${SYSROOT}

    注意:不能加上"­­disable­shared"选项。 [arm@localhost gcc­3.4.4­stage1]#make all­gcc [arm@localhost gcc­3.4.4­stage1]#su root [root@localhost gcc­3.4.4­stage1]#make install­gcc [root@localhost gcc­3.4.4­stage1]#exit [arm@localhost gcc­3.4.4­stage1]#

    1.8   编译完整的 glibc

    [arm@localhost gcc­3.4.4­stage1] #cd ${SRC} [arm@localhost tchain3.4.4]#mkdir BUILD/glibc­2.3.5 [arm@localhost tchain3.4.4]#cd BUILD/glibc­2.3.5

    [arm@localhost glibc­2.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

    ../../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=${SYSROOT}/usr/include

    说明:

    ­­prefix:                            指定安装路径。

    ­­target:           指定目标平台。

    ­­host:                               指定当前平台。

    ­­build:                              指定编译平台。

    ­­with­sysroot:                 用于指定编译所需要的头文件,及链接库。

    ­­enable­add­ons:           加入其它的库,如线程库等。

    ­­enable­languages:       指定 gcc 所支持的语言。

    [arm@localhost glibc­2.3.5]#make [arm@localhost glibc­2.3.5]#su root

    [root@localhost glibc­2.3.5]#make install_root=${SYSROOT} install [root@localhost glibc­2.3.5]#exit

    [arm@localhost glibc­2.3.5]#

    1.9  编译完整的 gcc

    [arm@localhost glibc­2.3.5]#cd ${SRC} [arm@localhost tchain3.4.4]#mkdir BUILD/gcc­3.4.4 [arm@localhost tchain3.4.4]#cd BUILD/gcc­3.4.4

    [arm@localhost gcc­3.4.4]#../../gcc­3.4.4/configure ­­prefix=${PREFIX} ­­target=${TARGET}

    ­­enable­languages=c ­­with­sysroot=${SYSROOT} [arm@localhost gcc­3.4.4]#make

    [arm@localhost gcc­3.4.4]#su root [root@localhost gcc­3.4.4]#make install [root@localhost gcc­3.4.4]#exit [arm@localhost gcc­3.4.4]#

  • 相关阅读:
    逻辑即理性
    关于股市与经济的一点思考
    Objective-C Automatic Reference Counting (ARC)
    错误与异常
    Programming with Objective-C -- 属性的缺省实现
    视频容器格式与编码格式简介
    视频基础知识-封装格式和编码格式
    各种音视频编解码学习详解
    你的技术护城河是什么?--技术前沿代表了一个人的眼力和价值
    技术前沿--很多技术不了解细节也应该了解大概---知道能用来干什么--了解技术的价值
  • 原文地址:https://www.cnblogs.com/niezhongle/p/11088623.html
Copyright © 2011-2022 走看看