您的位置:首页 > 运维架构 > Linux

ARM-Linux交叉编译工具链搭建之LFS

2012-04-06 23:19 477 查看
    i.过程概括

    1.下载源文件、补丁和建立编译的目录

    2.建立内核头文件

    3.建立二进制工具(binutils)

    4.建立初始编译器(bootstrap gcc)

    5.建立c库(glibc)

    6.建立全套编译器(full gcc)

 

<准备工作>
    ii.源码版本选择:

    选择你所需的glibc版本,然后查看该版本中的INSTALL说明,根据要求下载相应的

    gcc版本和 binutils版本

              binutils-2.22、gcc-4.7.0、gmp-5.0.2、mpfr-3.1.0、glibc-2.12.2、glibc-linuxthreads-2.5、glibc-ports-2.12.1、gdb-7.4、linux-2.6.39

    源码依赖关系:

              gcc:

                  mpc:(可使用系统自带的库)

                       gmp:mpfr(可使用系统自带的库)

    下载地址:ftp://ftp.gnu.org/gnu/、ftp://ftp.kernel.org/pub/linux/kernel

    中科大:http://oss.ustc.edu.cn/

      iii.主机环境

    建立源码目录和编译目录,导出相关变量:TARGET、PREFIX、TARGET_PREFIX、PATH      

    #!/bin/sh

    #exportit.sh

    #exportenvironments for cross-tool-chain

    exportARMDIR=/home/peter/workspace/arm

    exportTARGET=arm-none-linux-gnueabi

    exportHOST_PC=i686-pc-linux-gnu

    exportHOST_ARM=arm

    exportPREFIX=${ARMDIR}/cross-chains/

    exportTARGET_PREFIX=${ARMDIR}/cross-chains/arm-linux

    exportPATH=${PREFIX}/bin:${PATH}

    exportSRC=${ARMDIR}/src

    exportBUILD=${ARMDIR}/build

    mkdir-p $SRC $BUILD $PREFIX

    cd$BUILD && mkdir binutils bgcc gcc glibc gdb gdbserver

    脚本执行方式:source exportit.sh

    iii.解压src目录下的压缩包

    #!/bin/sh

    #extract_here.sh

    echo"start extrating files from the tar balls..."

    mkdirtars

    files=$(ls)

    forFILE in $files

    do

    set- `echo "$FILE"|awk -F. '{print $NF}'`

    case"$1" in

 

    bz2)

    tar-jxvf  $FILE;;

    gz)

    tar-zxvf  $FILE;;

    xz)

    tar-Jxvf $FILE;;

    *)

    ;;

    esac

    done

    mv*.bz2 tars/;mv *.gz tars/;mv *.xz tars/ 

    在src路径下运行extract_here.sh,解压完成后压缩包被移至tars目录下

 
<开始编译>
    i.binutils

    cd$BUILD/ binutils

    $SRC/binutils-2.22/configure  --target=$TARGET  --prefix=$PREFIX \

    [otheroptions]

    make&& make install

--------------------------------------------------------------------------------------------------------------------------------------------------

      #other options

      --disable-nls (native language support)

      --disable-multilib (support both 32bitsand 64 bits?)

      --enable-shared

 

    ii.bootstrapgcc

    cd$SRC/

    #mpfr---multiple-precisionfloating-point computations with correct rounding

    #gmp---MultiplePrecision Arithmetic Library

    mvgmp*   gcc-4.7.0/gmp;mvmpfr*  gcc-4.7.0/mpfr;mv linuxthread*gcc-4.7.0/

    cd$BUILD/bgcc

    $SRC/gcc-4.7.0/configure  --target=$TARGET  --prefix=$PREFIX --disable-threads \

    --disable-shared--enable-languages=c –with-newlib

    [otheroptions]

    makeliball-gcc

    makeinstall

    makeall-target-libgcc

    makeinstall-target-libgcc

    #make&& make install

    #otheroptions

---------------------------------------------------------------------------------------------------------------------

--build=$HOST  --host=$HOST --without-headers--with-newlib  --with-float=soft--with-cpu=arm920t --with-tune=arm9tdmi--with-gnu-as --with-gnu-ld --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libffi

reference fromhttp://gcc.gnu.org/install/configure.html

------------------------------------------------------------------------------------------------------------------------------------------------

 

    #maybeyou need to edit  gcc/config/t-linux

    #vigcc/config/t-linux  or user -with-newlib

    #TARGET_LIBGCC2_CFLAGS= -fPIC -Dinhibit_libc
-D_gthr_posix_h

    #rememberto recover it before you build the full-gcc

 

    iii.installkernel headers

    cd$SRC/linux-3.2

    cp  arch/arm/configs/s3c2410_defconfig  .config

    makeARCH=arm CROSS_COMPILE=${TARGET}- menuconfig

    makeARCH=arm CROSS_COMPILE=${TARGET}-

    makeinclude/linux/version.h

    mkdir$TARGET_PREFIX/include

    cp-r include/linux  $TARGET_PREFIX/include/

    cp-r arch/arm/include/asm $TARGET_PREFIX/include/asm-arm

    cp-r include/asm/* $TARGET_PREFIX/include/asm-arm/

    cp-r include/asm-generic $TARGET_PREFIX/include/

   

    iv.glibc

    cd$SRC

    mvglibc-ports*  glibc-2.14/ports

    mvlinuxthreads* glibc-2.14/

    CC=${TARGET}-gccAR=${TARGET}-ar RANLIB=${TARGET}-randlib

    cd$BUILD/glibc-2.14

    $SRC/glibc-2.14/configure--build=${HOST_PC} \

    --host=${TARGET}  --prefix=$TARGET_PREFIX \

    --enable-add-ons--with-headers=$TARGET_PREFIX/include  \

    libc_cv_forced_unwind=yeslibc_cv_c_cleanup=yes

    [other options]

    make&& make install

    #other options

      -----------------------------------------------------------------------------------------------------

      support nptl features

      cat > config.cache << EOF

      libc_cv_forced_unwind=yes

      libc_cv_c_cleanup=yes 

      libc_cv_arm_tls=yes

      libc_cv_gnu99_inline=yes

      EOF

     

     --with-binutils=$SRC/binutils-2.14/bin

      --cache-file=config.cache  \

     --with-tls\

     --with-__thread\

     --enable-sim\

     --enable-nptl\

     --enable-kernel=2.6.29\

     --disable-profile\

     --without-gd  \

     --without-cvs  \

    #errorlist

      ------------------------------------------------------------------------------------------------------

@/bin/sh: cannotcreate /home/mini/arm/build-tools/build-glibc/posix/config-name.h.new:

      mkdir -p $BUILD/glibc/posix

@glibc-2.14/ports/sysdeps/unix/sysv/linux/arm/sigrestorer.S

      ENTRY(__default_sa_restorer)

      +END(__default_sa_restorer)

      ENTRY(__default_rt_sa_restorer)

      +END(__default_rt_sa_restorer)

@glibc-2.14/sysdeps/unix/syscall-template.S 

      +define PSEUDO(name, syscall_name, args)\

      +.text;

      +ENTRY (name);

     +DO_CALL(syscall_name, args);

      +cmn r0, $4096;    

@glibc-2.13/sysdeps/ieee754/dbl-64/s_fma.c、s_fmaf.c

      +#define FE_TOWARDZERO 0xc00000

      +#define FE_INEXACT 16

@sysdeps/ieee754/dbl-64/s_fma.c、s_fmaf.c

      +# define F_GETPIPE_SZ     1032   /* Set pipe page size array.*/

@ports/sysdeps/arm/dl-machine.h

      +#define DEFAULT_STACK_PERMS(PF_R|PF_W|PF_X)

@glibc-2.13/nptl/allocatestack.c

@glibc-2.14/elf/dl-load.c、dl-tls.c

      +#define TLS_DTV_UNALLOCATED    ((void *) -1l)

     

*help!

Glibc-2.15 configureerror

checking whether touse .ctors/.dtors header and trailer... configure: error: missing __attribute__((constructor)) support??

    ------------------------------------------------------------------------------------------------------

    v.full-gcc

    ln -vs libgcc.a `arm-linux-gcc-print-libgcc-file-name | sed 's/libgcc/&_eh/'`

    $SRC/gcc-4.7.0/configure--target=$TARGET --prefix=$PREFIX \

    --with-headers=$PREFIX/include--enable-languages=c,c++ --enable-shared \

      [other options]

    make&& make install

    #options

---------------------------------------------------------------------------------------------------------------
    --with-float=soft\  --with-cpu=arm920t \  --with-tune=arm9tdmi\  --enable-languages=c,c++\

      --enable-threads=posix \  --enable-c99 \  --enable-long-long\  --enable-shared \  

      --enable-__cxa_atexit \  --enable-nls \  --disable-libgomp

    ---------------------------------------------------------------------------------------------------------------

 

    vi.gdb

    $SRC/gdb-7.4/configure--target=$TARGET --prefix=$PREFIX

    make&& make install

   

    vii.gdbserver

    $SRC/gdb-7.4/gdb/gdbserver/configure--target=$TARGET --prefix=$PREFIX

    make&& make install

<工具打包>
    cd$TARGET_PREFIX

    #stripto be smaller

    #strip./$TARGET/bin/*

    #strip./bin/$TARGET-*

    #striplibexec/gcc/$TARGET/4.7.0/*

    tar-Jcvf $TARGET-tools-4.7.0_201204.tar.xz$TARGET lib/gcc/$TARGET libexec/gcc/$TARGET bin/$TARGET-* $HOST_PC/$TARGET

<工具测试>
-------------------------------------------------------------------------------------------------------------------

vi hello.c

#include <stdio.h>

int main(void)

{

    printf("itworks!");

    return 0;

}

-------------------------------------------------------------------------------------------------------------------

$TARGET-gcc -print-search-dirs

$TARGET-gcc hello.c -o hello –static

file hello

now you can run it on your embed linuxsystem

 

参考资料:

http://www.rosoo.net/a/201203/15788.html

http://bbs.chinaunix.net/thread-3589766-1-1.html

http://hi.baidu.com/busybox/blog/item/fcd8693f52d3bad97d1e71d7.html

http://bbs.ednchina.com/BLOG_ARTICLE_145992.HTM

http://www.360doc.com/content/09/0515/23/26398_3519654.shtml

待读资料

http://blog.csdn.net/turui/article/details/6596093
https://www.ibm.com/developerworks/cn/linux/l-embcmpl/

 http://cross-lfs.org/view/clfs-embedded/arm/index.html

 http://hi.baidu.com/mynana/blog/item/479eb25183ec2210377abee0.html

 

快速搭ARM-Linux建交叉编译环境的方法

 

一、buildroot

http://buildroot.uclibc.org/downloads/buildroot.html

tar -jxvf buildroot-xxx.tar.bz2

cd buildroot-xxx

make menuconfig

说明:

1.安装过程自动下载源码包,要保证网速

2.下载文件位于dl中,生成文件位于output/host中

3.使用的是uclibs

 

二、eldk

http://www.denx.de/wiki/view/ELDK-5   

注意:下载后文件路径如下

eldk/

 

|-- install.sh

 

`-- targets

 

   `-- armv4t

 

        |--core-image-minimal-generic-armv4t.tar.gz

 

        |-- core-image-qte-sdk-generic-armv4t.tar.gz

 

        |--eldk-eglibc-i686-arm-toolchain-qte-5.1.tar.bz2

 

        `-- target.conf

管理员权限,根据需要执行以下命令之一

./install.sh -s qte -r"minimal qte-sdk" armv4t

 

./install.sh -s qte -r"minimal" armv4t

 

./install.sh -s qte -r"qte-sdk" armv4t

 

./install.sh -s qte -r – armv4t

 

三、直接下载他人发布的

http://ftp.arm.linux.org.uk/pub/armlinux/toolchain/

http://opensrc.sec.samsung.com/download.html

http://www.handhelds.org/download/projects/toolchain/

.http://linux.omap.com/pub/toolchain/

http://ftp.snapgear.org:9981/pub/snapgear/tools/arm-linux/
http://www.uclinux.org/pub/uClinux/arm-elf-tools/

http://www.w-ww.org/~rmoravcik/sbc2410/toolchains/arm-linux-gcc-4.1.2-moko.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息