码迷,mamicode.com
首页 > 系统相关 > 详细

ARM-Linux交叉工具链制作

时间:2015-07-06 14:19:28      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:linux   arm   交叉编译环境搭建   

1. 首先从官方网站上下载crosstool-ng的源码包 http://ymorin.is-a-geek.org/download/crosstool-ng/crosstool-ng-1.11.1.tar.bz2

2. 将此源码包解压缩并编译安装

tar jxvf crosstool-ng-1.11.1.tar.bz2

 cd crosstool-ng--1.11.1

 ./configure

 make

 sudo make install

注意:运行configure文件会提示一系列的工具没有安装,安装就是了,例如bison,flex,makeinfo(需要安装texinfo),automake(需要先安装autoconf),libtool,ncurses,libncurses-devel,安装方法:mount /dev/cdrom /mnt/cds,挂载到cds目录,然后在Packages目录下查找相关的软件,利用命令:rpm –ivh ****安装即可。安装成功后,运行configure文件的结果如下:

Checking for ‘grep‘... /bin/grep

Checking whether ‘/bin/grep‘ supports -E... yes

Checking for ‘sed‘... /bin/sed

Checking whether ‘/bin/sed‘ supports -i and -e... yes

Checking for ‘bash‘... /bin/bash

Checking for ‘cut‘... /usr/bin/cut

Checking for ‘install‘... /usr/bin/install

Checking for ‘make‘... /usr/bin/make

Checking for ‘gcc‘... /usr/bin/gcc

Checking for ‘awk‘... /usr/bin/awk

Checking for ‘bison‘... /usr/bin/bison

Checking for ‘flex‘... /usr/bin/flex

Checking for ‘makeinfo‘... /usr/bin/makeinfo

Checking for ‘automake‘... /usr/bin/automake

Checking for ‘libtool‘... /usr/bin/libtool

Checking for ‘stat‘... /usr/bin/stat

Checking for ‘curl‘... /usr/bin/curl

Checking for ‘cvs‘... /usr/bin/cvs

Checking for ‘patch‘... /usr/bin/patch

Checking for ‘tar‘... /bin/tar

Checking for ‘gzip‘... /usr/bin/gzip

Checking for ‘bzip2‘... /usr/bin/bzip2

Checking for ‘lzma‘... /usr/bin/lzma

Checking for ‘readlink‘... /usr/bin/readlink

Checking for ‘objcopy‘... /usr/bin/objcopy

Checking for ‘objdump‘... /usr/bin/objdump

Checking for ‘readelf‘... /usr/bin/readelf

Checking for ‘patch‘... /usr/bin/patch

Checking for ‘ncurses/ncurses.h‘... yes

Checking for ‘libncursesw.so‘... yes

Computing version string... 1.11.1

Building up Makefile... done

 

crosstool-NG configured as follows:

  PREFIX=‘/usr/local‘

  BINDIR=‘/usr/local/bin‘

  LIBDIR=‘/usr/local/lib/ct-ng-1.11.1‘

  DOCDIR=‘/usr/local/share/doc/ct-ng-1.11.1‘

  MANDIR=‘/usr/local/share/man‘

 

Now run:

  make

  make install

 

键入make:结果如下

SED    ‘ct-ng‘

  SED    ‘scripts/crosstool-NG.sh‘

  SED    ‘scripts/saveSample.sh‘

  SED    ‘scripts/showTuple.sh‘

  GEN    ‘paths.mk‘

  SED    ‘docs/ct-ng.1‘

  GZIP   ‘docs/ct-ng.1.gz‘

键入 make install:运行结果如下

INST    ‘ct-ng‘

  RMDIR   ‘/usr/local/lib/ct-ng-1.11.1/‘

  MKDIR   ‘/usr/local/lib/ct-ng-1.11.1/‘

  INSTDIR ‘config/‘

  INSTDIR ‘contrib/‘

  INSTDIR ‘kconfig/‘

  INSTDIR ‘patches/‘

  INSTDIR ‘scripts/‘

  INST    ‘steps.mk‘

  INST    ‘paths.mk‘

  INSTDIR ‘samples/‘

  MKDIR   ‘/usr/local/share/doc/ct-ng-1.11.1/‘

  INST    ‘docs/*.txt‘

  INST    ‘ct-ng.1.gz‘

 

For auto-completion, do not forget to install ‘ct-ng.comp‘ into

your bash completion directory (usually /etc/bash_completion.d)

 

当上述过程执行完毕后,cn-ng命令就可以用了。

3.配置自己的交叉工具链

crosstool-ng可以配置各种平台的交叉编译器,也可以构建符合自己实用条件的个性编译器。下面以ARM平台为例,制作具有一定通用性的交叉编译器。这里我们从一个现成的编译器配置开始,用例子里的arm-unknown-linux-gnueabi作为配置的基础,然后来做一个交叉编译器。

将crosstool-ng源码包中samples/arm-unknown-linux-gnueabi/下的crosstool.config拷贝到源码包主目录下,在源码包主目录下执行:

cp samples/arm-unknown-linux-gnueabi/crosstool.config .config

然后执行:ct-ng menuconfig 进入配置菜单,这里稍作修改:

Paths and misc options  --->

    ......

    (${HOME}/src)   Local tarballs directory  # 指定制作编译器所需要的源码包的下载存放,可以修改成任意位置,请注意权限。现在指定到~/src下。

    ......

    (/opt/${CT_TARGET}) Prefix directory     # 制作好的编译器所放置的目录

Target options  --->

    Target Architecture (arm)  ---> # 注意看这项是不是ARM平台

    ......

    Floating point: (software)  ---> # 对于很多ARM架构CPU来说是不支持硬浮点运算的,所以选择软件方式有更好的兼容性

    ......

    [*] Use EABI                            # 是否实用EABI方式,对某些指令采用异常的方式来处理(如除法指令),建议选中

Toolchain options  --->

     .....

     (tonghuix) Tuple‘s vendor string  # 这里可以修改成你自己的个性化名称,最后会生成形如arm-yourname-linux-gnueabi这样的编译器

    

      当修改好后就可以编译了。

4.自动下载和编译

注意,在下载的过程中,有些软件包可能无法下载,这个时候,可以自己手动现下载到指定的文件夹(跟上一节的配置有关),一个小技巧就是可以查看下当前的crosstool版本需要哪些版本的软件包,将其下载放入指定的文件夹内即可。

安装成功后的结果如下:

[INFO ]  Performing some trivial sanity checks

[INFO ]  Build started 20150625.114507

[INFO ]  Building environment variables

[EXTRA]  Preparing working directories

[EXTRA]  Installing user-supplied crosstool-NG configuration

[EXTRA]  =================================================================

[EXTRA]  Dumping internal crosstool-NG configuration

[EXTRA]    Building a toolchain for:

[EXTRA]      build  = x86_64-unknown-linux-gnu

[EXTRA]      host   = x86_64-unknown-linux-gnu

[EXTRA]      target = arm-zk-linux-gnueabi

[EXTRA]  Dumping internal crosstool-NG configuration: done in 0.09s (at 00:04)

[INFO ]  =================================================================

[INFO ]  Retrieving needed toolchain components‘ tarballs

[INFO ]  Retrieving needed toolchain components‘ tarballs: done in 0.20s (at 00:04)

[INFO ]  =================================================================

[INFO ]  Extracting and patching toolchain components

[INFO ]  Extracting and patching toolchain components: done in 7.50s (at 00:12)

[INFO ]  =================================================================

[INFO ]  Installing GMP

[EXTRA]    Configuring GMP

[EXTRA]    Building GMP

[EXTRA]    Installing GMP

[INFO ]  Installing GMP: done in 84.65s (at 01:36)

[INFO ]  =================================================================

[INFO ]  Installing MPFR

[EXTRA]    Configuring MPFR

[EXTRA]    Building MPFR

[EXTRA]    Installing MPFR

[INFO ]  Installing MPFR: done in 22.99s (at 01:59)

[INFO ]  =================================================================

[INFO ]  Installing PPL

[EXTRA]    Configuring PPL

[EXTRA]    Building PPL

[EXTRA]    Installing PPL

[INFO ]  Installing PPL: done in 257.60s (at 06:17)

[INFO ]  =================================================================

[INFO ]  Installing CLooG/ppl

[EXTRA]    Configuring CLooG/ppl

[EXTRA]    Building CLooG/ppl

[EXTRA]    Installing CLooG/ppl

[INFO ]  Installing CLooG/ppl: done in 5.68s (at 06:23)

[INFO ]  =================================================================

[INFO ]  Installing binutils

[EXTRA]    Configuring binutils

[EXTRA]    Building binutils

[EXTRA]    Installing binutils

[INFO ]  Installing binutils: done in 70.85s (at 07:33)

[INFO ]  =================================================================

[INFO ]  Installing static core C compiler

[EXTRA]    Configuring static core C compiler

[EXTRA]    Building static core C compiler

[EXTRA]    Installing static core C compiler

[INFO ]  Installing static core C compiler: done in 162.04s (at 10:16)

[INFO ]  =================================================================

[INFO ]  Installing kernel headers

[EXTRA]    Installing kernel headers

[EXTRA]    Checking installed headers

[INFO ]  Installing kernel headers: done in 4.85s (at 10:20)

[INFO ]  =================================================================

[INFO ]  Installing C library headers & start files

[EXTRA]    Configuring C library

[EXTRA]    Installing C library headers

[EXTRA]    Installing C library start files

[INFO ]  Installing C library headers & start files: done in 42.90s (at 11:03)

[INFO ]  =================================================================

[INFO ]  Installing shared core C compiler

[EXTRA]    Configuring shared core C compiler

[EXTRA]    Building shared core C compiler

[EXTRA]    Installing shared core C compiler

[INFO ]  Installing shared core C compiler: done in 189.29s (at 14:13)

[INFO ]  =================================================================

[INFO ]  Installing C library

[EXTRA]    Configuring C library

[EXTRA]    Building C library

[EXTRA]    Installing C library

[27:05] |

[INFO ]  Installing C library: done in 779.85s (at 27:12)

[INFO ]  =================================================================

[INFO ]  Installing final compiler

[EXTRA]    Configuring final compiler

[EXTRA]    Building final compiler

[28:42] \

 [EXTRA]    Installing final compiler

[INFO ]  Installing final compiler: done in 546.82s (at 36:19)

[INFO ]  =================================================================

[INFO ]  Installing libelf for the target

[EXTRA]    Configuring libelf

[EXTRA]    Building libelf

[EXTRA]    Installing libelf

[INFO ]  Installing libelf for the target: done in 5.61s (at 36:25)

[INFO ]  =================================================================

[INFO ]  Installing binutils for target

[EXTRA]    Configuring binutils for target

[EXTRA]    Building binutils‘ libraries (libiberty bfd) for target

[EXTRA]    Installing binutils‘ libraries (libiberty bfd) for target

[INFO ]  Installing binutils for target: done in 112.11s (at 38:17)

[INFO ]  =================================================================

[INFO ]  Installing dmalloc

[EXTRA]    Configuring dmalloc

[EXTRA]    Building dmalloc

[EXTRA]    Installing dmalloc

[INFO ]  Installing dmalloc: done in 8.71s (at 38:26)

[INFO ]  =================================================================

[INFO ]  Installing D.U.M.A.

[EXTRA]    Copying sources

[EXTRA]    Building libraries ‘libduma.a libduma.so.0.0.0‘

[EXTRA]    Installing libraries ‘libduma.a libduma.so.0.0.0‘

[EXTRA]    Installing shared library link

[EXTRA]    Installing wrapper script

[INFO ]  Installing D.U.M.A.: done in 2.81s (at 38:29)

[INFO ]  =================================================================

[INFO ]  Installing cross-gdb

[EXTRA]    Configuring cross-gdb

[EXTRA]    Building cross-gdb

[EXTRA]    Installing cross-gdb

[INFO ]  Installing cross-gdb: done in 173.96s (at 41:23)

[INFO ]  =================================================================

[INFO ]  Installing native gdb

[EXTRA]    Building static target ncurses

[EXTRA]    Building static target expat

[EXTRA]    Configuring native gdb

[EXTRA]    Building native gdb

[EXTRA]    Installing native gdb

[EXTRA]    Cleaning up ncurses

[INFO ]  Installing native gdb: done in 301.57s (at 46:24)

[INFO ]  =================================================================

[INFO ]  Installing gdbserver

[EXTRA]    Configuring gdbserver

[EXTRA]    Building gdbserver

[EXTRA]    Installing gdbserver

[INFO ]  Installing gdbserver: done in 8.61s (at 46:33)

[INFO ]  =================================================================

[INFO ]  Installing ltrace

[EXTRA]    Copying sources to build dir

[EXTRA]    Configuring ltrace

[EXTRA]    Building ltrace

[EXTRA]    Installing ltrace

[INFO ]  Installing ltrace: done in 4.36s (at 46:37)

[INFO ]  =================================================================

[INFO ]  Installing strace

[EXTRA]    Configuring strace

[EXTRA]    Building strace

[EXTRA]    Installing strace

[INFO ]  Installing strace: done in 16.56s (at 46:54)

[INFO ]  =================================================================

[INFO ]  Cleaning-up the toolchain‘s directory

[INFO ]    Stripping all toolchain executables

[EXTRA]    Installing the populate helper

[EXTRA]    Installing a cross-ldd helper

[EXTRA]    Creating toolchain aliases

[EXTRA]    Removing access to the build system tools

[INFO ]  Cleaning-up the toolchain‘s directory: done in 4.10s (at 46:58)

[INFO ]  Build completed at 20150625.123205

[INFO ]  (elapsed: 46:58.12)

[INFO ]  Finishing installation (may take a few seconds)...

 

 

 

 

 

5.安装交叉编译器并测试

注意:这里我的编译器所在位置为${home}/x-tool/arm-zk-linux-gnueabi/bin,由ct-ng menuconfig可以看出如下:

 

进入编译器所在目录:/root/x-tools/arm-zk-linux-gnueabi/bin

执行如下命令:./arm-zk-linux-gnueabi-gcc-4.4.4 –v

输入结果如下:

Using built-in specs.

Target: arm-zk-linux-gnueabi

Configured with: /usr/src/crosstool-ng-1.11.1/.build/src/gcc-4.4.4/configure --build=x86_64-build_unknown-linux-gnu --host=x86_64-build_unknown-linux-gnu --target=arm-zk-linux-gnueabi --prefix=/root/x-tools/arm-zk-linux-gnueabi --with-sysroot=/root/x-tools/arm-zk-linux-gnueabi/arm-zk-linux-gnueabi/sysroot --enable-languages=c,c++,fortran --disable-multilib --with-float=soft --with-pkgversion=crosstool-NG-1.11.1 --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --with-gmp=/usr/src/crosstool-ng-1.11.1/.build/arm-zk-linux-gnueabi/build/static --with-mpfr=/usr/src/crosstool-ng-1.11.1/.build/arm-zk-linux-gnueabi/build/static --with-ppl=/usr/src/crosstool-ng-1.11.1/.build/arm-zk-linux-gnueabi/build/static --with-cloog=/usr/src/crosstool-ng-1.11.1/.build/arm-zk-linux-gnueabi/build/static --with-host-libstdcxx=‘-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm‘ --enable-threads=posix --enable-target-optspace --with-local-prefix=/root/x-tools/arm-zk-linux-gnueabi/arm-zk-linux-gnueabi/sysroot --disable-nls --enable-symvers=gnu --enable-c99 --enable-long-long

Thread model: posix

gcc version 4.4.4 (crosstool-NG-1.11.1)

表明交叉工具安装成功了。。。。。

下面把交叉编译器所在的目录添加到系统PATH变量中,修改~/.bashrc文件,在其中添加:

export PATH=$PATH:/root/x-tools/arm-zk-linux-gnueabi/bin

为了使得这个PATH生效,我们可以执行一下~/.bashrc文件:source ~/.bashrc;

这样就可以直接在命令行下使用arm-zk-linux-gcc命令了。

6.标准化安装交叉编译器

我们在使用交叉编译器的时候一般是采用arm-zk-linux-gnueabi这样的命令的,但是很多标准Makefile需要实用标准的交叉编译器的名称,一般这个名称是arm-linux-gcc这样的。

cd /root/x-tools/arm-zk-linux-gnueabi/bin     //注意已经要进入安装目录

新建一个脚本link.sh,建立一些软链接

#!/bin/sh

PREFIX=arm-zk-linux-gnueabi-

AFTFIX=arm-linux-

ln -s ${PREFIX}gcc ${AFTFIX}gcc

ln -s ${PREFIX}addr2line ${AFTFIX}addr2line

ln -s  ${PREFIX}gdbtui ${AFTFIX}gdbtui

ln -s  ${PREFIX}ar ${AFTFIX}ar

ln -s  ${PREFIX}as ${AFTFIX}as

ln -s  ${PREFIX}c++ ${AFTFIX}c++

ln -s  ${PREFIX}c++filt ${AFTFIX}c++filt

ln -s  ${PREFIX}cpp ${AFTFIX}cpp

ln -s  ${PREFIX}g++ ${AFTFIX}g++

ln -s  ${PREFIX}gccbug ${AFTFIX}gccbug

ln -s  ${PREFIX}gcj ${AFTFIX}gcj

ln -s  ${PREFIX}gcov ${AFTFIX}gcov

ln -s  ${PREFIX}gdb ${AFTFIX}gdb

ln -s  ${PREFIX}gfortran ${AFTFIX}gfortran

ln -s  ${PREFIX}gprof ${AFTFIX}gprof

ln -s  ${PREFIX}jcf-dump ${AFTFIX}jcf-dump

ln -s  ${PREFIX}ld ${AFTFIX}ld

ln -s  ${PREFIX}ldd ${AFTFIX}ldd

ln -s  ${PREFIX}nm ${AFTFIX}nm

ln -s  ${PREFIX}objcopy ${AFTFIX}objcopy

ln -s  ${PREFIX}objdump ${AFTFIX}objdump

ln -s  ${PREFIX}populate ${AFTFIX}populate

ln -s  ${PREFIX}ranlib ${AFTFIX}ranlib

ln -s  ${PREFIX}readelf ${AFTFIX}readelf

ln -s  ${PREFIX}run ${AFTFIX}run

ln -s  ${PREFIX}size ${AFTFIX}size

ln -s  ${PREFIX}strings ${AFTFIX}strings

ln -s  ${PREFIX}strip ${AFTFIX}strip

 

然后执行 sh link.sh。就可以使用arm-linux-gcc这样的命令了。

大功告成啦啦啦

版权声明:本文为博主原创文章,未经博主允许不得转载。

ARM-Linux交叉工具链制作

标签:linux   arm   交叉编译环境搭建   

原文地址:http://blog.csdn.net/zkpingguo/article/details/46772797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!