本文转载自:http://eric-gao.iteye.com/blog/2160622

制作arm-linux交叉编译工具链一般通过crosstool工具或者crosstool-NG,前者使用方便,但是制作会受到一些限制,使用crosstool最多只能编译gcc4.1.1、glibc2.x的版本,无法编译版本高于2.6.29的linux内核。crosstool-NG是新的用来建立交叉编译工具链的工具,它是crosstool的替代者。crosstool-NG有更好的定制性,并且一直保持着更新,对新版本的编译工具链的支持比较好,当然也带来了一些麻烦,它并不是下载下来就可以使用的,必须先配置安装。我们这里选用crosstool-NG来制作编译工具链。

本文使用的系统是Ubuntu Kylin(3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux),建议都使用Ubuntu系统,安装软件比较方便。

一、安装crosstool-NG

1、建立arm-linux-tools目录,并进入该目录

  1. $ mkdir arm-linux-tools
  2. $ cd arm-linux-tools

2、获取crosstool-NG的源码

  1. $ wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.20.0.tar.bz2

3、解压crosstool-NG的源码

  1. $ tar xvjf crosstool-ng-1.20.0.tar.bz2

考虑到后续将要使用到的各种目录,在这里先建立好后续所需的目录。

  1. $ mkdir crosstool-build crosstool-install src

4、配置并进行依赖检测

  1. $ cd crosstool-ng-1.20.0
  2. $ ./configure --prefix /home/eric/arm-linux-tools/crosstool-install/

在配置之前,需要确保以下软件已经安装

1)gperf

2)bison

3)flex

4)texinfo

5)gawk

6)libtool

7)automake

8)libncurses5-dev

9)g++

在进行配置时,会进行依赖检测,如果存在包缺失的现象,安装好之后再执行配置即可。

成功配置之后会自动创建我们需要的Makefile文件。

5、编译并安装

  1. $ make
  2. $ make install

6、配置环境变量

  1. $ export PATH=$PATH:/home/eric/arm-linux-tools/crosstool-install/bin/

7、检查crosstool-NG是否安装成功

  1. $ ct-ng -v

二、配置交叉编译工具链

在crosstool-NG中有很多已经做好的默认配置(位于crosstool-ng-1.20.0/samples目录下),这里只需要进行修改就可以了。因为是制作arm-linux的交叉编译工具链,所以选择arm-unknown-linux-gnueabi进行配置。

1、将arm-unknown-linux-gnueabi文件夹复制到crosstool-build目录下

  1. $ cd samples
  2. $ cp -r arm-unknown-linux-gnueabi/ ../../crosstool-build/

2、将默认配置文件拷贝到crosstool-build目录下并改名为.config

  1. $ cd ~/arm-linux-tools/crosstool-build
  2. $ cp arm-unknown-linux-gnueabi/crosstool.config .config

3、执行ct-ng menuconfig进入配置界面进行配置

  1. $ ct-ng menuconfig

配置界面如下图所示:

(1)设定源码包路径和交叉编译器的安装路径

1)源码包路径:设置Paths and misc options下的Local tarballs directory为/home/eric/arm-linux-tools/src

2)交叉编译器的安装路径:设置Paths and misc options下的Prefix directory为/home/eric/arm-linux-tools/x-tools/${CT_TARGET}

(2)修改交叉编译器针对的架构

1)设置Target options下的Architecture level为armv4t

2)设置Target options下的Emit assembly for CPU为arm9tdmi

3)设置Target options下的Tune for CPU为arm920t

以上这几个参数是如何得出来的,可以参考gcc的man手册。你可以在下载的gcc-4.9.1.tar.bz2解压后的文件夹中找到(gcc-4.9.1/gcc/doc/gcc.1)

执行以下命令打开gcc.1

  1. $ man ./gcc.1

你可以在其中看到下面这段:

  1. ......
  2. ARM Options
  3. ......
  4. -march=name
  5. This specifies the name of the target ARM architecture.  GCC uses
  6. this name to determine what kind of instructions it can emit when
  7. generating assembly code.  This option can be used in conjunction
  8. with or instead of the -mcpu= option.  Permissible names are:
  9. armv2, armv2a, armv3, armv3m, armv4, armv4t, armv5, armv5t, armv5e,
  10. armv5te, armv6, armv6j, armv6t2, armv6z, armv6zk, armv6-m, armv7,
  11. armv7-a, armv7-r, armv7-m, armv7e-m, armv7ve, armv8-a, armv8-a+crc,
  12. iwmmxt, iwmmxt2, ep9312.
  13. -mtune=name
  14. This option specifies the name of the target ARM processor for
  15. which GCC should tune the performance of the code.  For some ARM
  16. implementations better performance can be obtained by using this
  17. option.  Permissible names are: arm2, arm250, arm3, arm6, arm60,
  18. arm600, arm610, arm620, arm7, arm7m, arm7d, arm7dm, arm7di,
  19. arm7dmi, arm70, arm700, arm700i, arm710, arm710c, arm7100, arm720,
  20. arm7500, arm7500fe, arm7tdmi, arm7tdmi-s, arm710t, arm720t,
  21. arm740t, strongarm, strongarm110, strongarm1100, strongarm1110,
  22. arm8, arm810, arm9, arm9e, arm920, arm920t, arm922t, arm946e-s,
  23. arm966e-s, arm968e-s, arm926ej-s, arm940t, arm9tdmi, arm10tdmi,
  24. arm1020t, arm1026ej-s, arm10e, arm1020e, arm1022e, arm1136j-s,
  25. arm1136jf-s, mpcore, mpcorenovfp, arm1156t2-s, arm1156t2f-s,
  26. arm1176jz-s, arm1176jzf-s, cortex-a5, cortex-a7, cortex-a8,
  27. cortex-a9, cortex-a12, cortex-a15, cortex-a53, cortex-a57,
  28. cortex-r4, cortex-r4f, cortex-r5, cortex-r7, cortex-m4, cortex-m3,
  29. cortex-m1, cortex-m0, cortex-m0plus, marvell-pj4, xscale, iwmmxt,
  30. iwmmxt2, ep9312, fa526, fa626, fa606te, fa626te, fmp626, fa726te.
  31. Additionally, this option can specify that GCC should tune the
  32. performance of the code for a big.LITTLE system.  Permissible names
  33. are: cortex-a15.cortex-a7, cortex-a57.cortex-a53.
  34. -mcpu=name
  35. This specifies the name of the target ARM processor.  GCC uses this
  36. name to derive the name of the target ARM architecture (as if
  37. specified by -march) and the ARM processor type for which to tune
  38. for performance (as if specified by -mtune).  Where this option is
  39. used in conjunction with -march or -mtune, those options take
  40. precedence over the appropriate part of this option.
  41. Permissible names for this option are the same as those for -mtune.
  42. -mcpu=generic-arch is also permissible, and is equivalent to
  43. -march=arch -mtune=generic-arch.  See -mtune for more information.
  44. -mcpu=native causes the compiler to auto-detect the CPU of the
  45. build computer.  At present, this feature is only supported on
  46. Linux, and not all architectures are recognized.  If the auto-
  47. detect is unsuccessful the option has no effect.
  48. ......

-march=name对应Architecture level

-mtune=name对应Tune for CPU

-mcpu=name对应Emit assembly for CPU

(3)设置编译时的并行进程数

1)设置Paths and misc options下的Number of parallel jobs为4

这个数值不宜过大,应该为CPU核心数量的两倍。

(4)设置编译器前缀

1)设置Toolchain options下的Tuple's vendor string为S3C2440,这样生成的编译器的前缀就是arm-S3C2440-linux-gnueabi-

4、安装termcap

  1. $ cd /tmp
  2. $ wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
  3. $ tar xvzf termcap-1.3.1.tar.gz
  4. $ cd termcap-1.3.1
  5. $ ./configure --prefix=/usr
  6. $ make
  7. $ make install

5、编译

在crosstool-build目录下执行以下命令进行编译

  1. $ ct-ng build.4

整个编译过程时间比较长,crosstool-ng会自动下载相应的包和内核文件,然后解压、配置、编译、链接,但有个别包在自动下载过程中会出错,例如duma_2_5_15和expat-2.1.0,需要手动下载这两个包放入Local tarballs directory指定的目录(这里为/home/eric/arm-linux-tools/src),然后再重新执行编译即可。

编译过程中,在安装到cross-gdb时,出现configure: error: expat is missing or unusable的错误,安装libexpat1-dev即可。

编译过程中,出现g++: Internal error: Killed (program cc1plus)的错误,尝试着将可用内存加大。

如下图所示,代表安装成功了。

6、配置环境变量

  1. $ echo "PATH=$PATH:/home/eric/arm-linux-tools/x-tools/arm-S3C2440-linux-gnueabi/bin" >> ~/.bashrc
  2. $ source ~/.bashrc

7、确认安装完成

  1. $ arm-S3C2440-linux-gnueabi-gcc -v

8、编译成功后的交叉编译器路径

(1)编译器路径:/home/eric/arm-linux-tools/x-tools/arm-S3C2440-linux-gnueabi/bin

(2)库文件路径:/home/eric/arm-linux-tools/x-tools/arm-S3C2440-linux-gnueabi/arm-S3C2440-linux-gnueabi/lib

三、编译测试

1、写一个简单的C程序:Hello, World

  1. #include <stdio.h>
  2. int main() {
  3. printf("Hello, World\n");
  4. return 0;
  5. }

2、编译

  1. $ arm-S3C2440-linux-gnueabi-gcc -o hello hello.c

3、上传至目标板并执行

  1. $ chmod +x ./hello
  2. $ ./hello

如上图所示,创建的交叉编译链可以成功编译成目标板能够识别的指令。

关于crosstool-ng的详细介绍和使用,请参考:http://www.crifan.com/files/doc/docbook/crosstool_ng/release/htmls/index.html

需要的依赖包下载:http://download.csdn.net/detail/jsntghf/8198753

编译后的交叉编译工具链下载:http://download.csdn.net/detail/jsntghf/8206693

arm-linux交叉编译工具链的制作(基于S3C2440)【转】的更多相关文章

  1. Linux下获取arm的交叉编译工具链

    转载请注明文章:Linux下获取arm的交叉编译工具链 出处:多客博图 这里介绍,Linux下获取arm的交叉编译工具链,比如arm-linux-gnueabihf-gcc.arm-linux-gne ...

  2. 64位的ubuntu14.04 LTS安装 Linux交叉编译工具链及32位“ia32-libs”依赖库

    ubuntu又迎来了其新一代的长期支持版本 14.04 LTS,其带来了许多令人期待的新特新,遂决定进行升级. 装好了64位版本及安装 Linux交叉编译工具链 运行GCC,${CROSS_COMPI ...

  3. 构建嵌入式Linux交叉编译工具链

    开源交叉编译工具链制作方法汇总: 1) 使用crosstool/crosstool-ng生成 2) 使用buildroot生成 ARM交叉编译工具链说明: 1) arm-linux-gcc是一个集合命 ...

  4. Linux交叉编译工具链和模块编译

    所有的工具: aarch64-poky-linux-addr2line aarch64-poky-linux-c++filt aarch64-poky-linux-g++ aarch64-poky-l ...

  5. arm嵌入式交叉编译工具链

    1.arm-linux-gcc 常用的参数:-o[制定输出文件名] -c[只到编译停止,不连接] -g[键入调试信息] -xO[优化级别] -w/W(警告等级) arm-linux-gcc -o de ...

  6. Linux ARM交叉编译工具链制作过程【转】

    本文转载自:http://www.cnblogs.com/Charles-Zhang-Blog/archive/2013/02/21/2920999.html 一.下载源文件 源代码文件及其版本与下载 ...

  7. 【转】ARM交叉编译工具链

    原文网址:http://www.veryarm.com/cross-tools 为什么要用交叉编译器? 交叉编译通俗地讲就是在一种平台上编译出能运行在体系结构不同的另一种平台上的程序,比如在PC平台( ...

  8. ARM交叉编译工具链分类说明

    转载整理自:http://www.veryarm.com/cross-tools 从授权上,ARM交叉编译工具链分为免费授权版和付费授权版. 免费版目前有三大主流工具商提供,第一是GNU(提供源码,自 ...

  9. ARM交叉编译工具链

    交叉编译工具链是一个由编译器.连接器和解释器组成的综合开发环境,交叉编译工具链主要由binutils.gcc和glibc三个部分组成. 免费版目前有三大主流工具商提供,第一是GNU(提供源码,自行编译 ...

随机推荐

  1. JS 实现全屏预览 F11功能

    老是不通过,没办法,只能是重新发布了,反正我就是杠上了,大大小小写过很多前端特效,当然也经常在网上copy或者修改人家的代码,我觉得也挺好的,为什么?!因为我想这样,你能怎么办,打我?少废话,直接上代 ...

  2. 11-看图理解数据结构与算法系列(B树的删除)

    删除操作 删除操作比较复杂,主要是因为删除的项可能在叶子节点上也可能在非叶子节点上,而且删除后可能导致不符合B树的规定,这里暂且称之为导致B树不平衡,于是要进行一些合并.左旋.右旋等操作,使之符合B树 ...

  3. maven项目运行tomcat7-maven-plugin:run时出现Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.util.Scanner(xjl456852原创)

    使用tomcat7-maven-plugin插件运行web项目时, 出现下面错误: [WARNING] Error injecting: org.sonatype.plexus.build.incre ...

  4. Git--使用须知123

    详细的篇幅以后补充 安装篇: 设置篇: 由于我们大多数是windows程序员,那么,在使用git的过程前需要做一些设置项. 1.换行符自动转换. 查看:git config --global --li ...

  5. 史上最全Java多线程面试题及答案

    多线程有什么用? 线程和进程的区别是什么? Java实现线程有哪几种方式? 启动线程方法start()和run()有什么区别? 怎么终止一个线程?如何优雅地终止线程? 一个线程的生命周期有哪几种状态? ...

  6. java中装箱与拆箱

    转载自:https://www.cnblogs.com/dolphin0520/p/3780005.html 自动装箱和拆箱问题是Java中一个老生常谈的问题了,今天我们就来一些看一下装箱和拆箱中的若 ...

  7. noip模拟赛 数颜色

    分析:高级数据结构学傻了.....一眼看上去觉得是莫队,发现带修改,于是分块,由于写的常数很大,只有70分. 正解很简单,记录下颜色为c的每只兔子的位置,每次二分找这个区间有多少只这种颜色的兔子就可以 ...

  8. Windows系统下查看已共享的文件夹的方法

    电脑使用时间比较长,共享过好几次文件夹,现在想取消共享,但共享文件夹的路径隐藏得太深,要怎么样才能快速找到共享文件夹的实际路径呢?” “其实现在单位常见的方法都是用网上邻居的共享文件夹,共享的文件夹也 ...

  9. php文件上传判断类型

    上传文件对象在$_FILES['Filedata']对象中,临时路径是tmp_name,判断是上传文件是否为真实图片方法很多,我用的是这个: if( !@getimagesize( $_FILES[' ...

  10. springmvc 中model中放入枚举类型

    我们直接看样例: Map<String, String> mallMap = new HashMap<String, String>(); mallMap.put(MallSt ...