第一部分:crosstool-ng 制作交叉编译工具链 for s3c2440【转】

转自:https://blog.csdn.net/woshidahuaidan2011/article/details/51344312

第一部分  安装交叉编译工具链

使用crosstool-0.43制作交叉编译工具链,随着gcc版本的增高,正确的制作已不太可能,crosstool-0.43制之后不再有更新,因此这个选用的是nt-ng工具制作交叉编译工具链。

1nt-ng的安装

Crostool很多年不在维护了,下面尝试一下使用crosstool的下一代 crosstool-ng 具体使用说明见:

http://www.crifan.com/files/doc/docbook/crosstool_ng/release/html/crosstool_ng.html

下面写出我编译的过程:

首先下载源码包:http://crosstool-ng.org/download/crosstool-ng/

这里我能在的是最新版:crosstool-ng-1.20.0.tar.bz2

这里有点和crosstool不同的是,crosstool-ng需要首先安装然后在配置选着交叉编译链。

首先解压tar –xvf crosstool-ng-1.20.0.tar.bz2

进入其目录:cd crosstool-ng-1.20.0 创建built文件夹也就是最后交叉编译链的输目录

mkdir  -p  /work/tools/crosstool-ng-built

运行config :

 ./configure --prefix=/work/tools/crosstool-ng-1.20.0

出现:

checking forabsolute path to readelf... /usr/bin/readelf

checking forgperf... no

configure:error: missing required tool: gperf

安装:sudo apt-get install gperf

但是我的ubuntu系统提示(有的版本可能不会出现此问题):

book@book-desktop:~/mywork/files/crosstool-ng-1.20.0$sudo apt-get install gperf

Reading packagelists... Done

Buildingdependency tree      

Reading stateinformation... Done

The followingNEW packages will be installed:

  gperf

0 upgraded, 1 newlyinstalled, 0 to remove and 1374 not upgraded.

E: Could not getlock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)

E: Unable tolock the download directory

按照下列方式解决:http://blog.csdn.net/dengroj2009/article/details/4636456

 sudo rm/var/cache/apt/archives/lock 
 sudo rm /var/lib/dpkg/lock 

然后继续configure

然后提示有错误:

configure: error: missing required tool: bison

解决办法跟第一次一样

sudo apt-get install bison

然后继续configure 有提示错误:

configure: error: missing required tool: flex

   解决办法跟第上次一样,缺什么工具就安装什么工具。

sudo apt-get install flex

然后继续configure 有提示错误:

configure: error: missing required tool: makeinfo

解决办法跟第上次一样,缺什么工具就安装什么工具。

sudo apt-get install texinfo

然后继续configure 有提示错误

configure: error: could not find GNU awk

解决办法跟第上次一样,缺什么工具就安装什么工具。

     sudo apt-get install gawk

然后继续configure 有提示错误

checking for GNU libtool >= 1.5.26...no

configure: error: could not find GNUlibtool >= 1.5.26

解决办法跟第上次一样,缺什么工具就安装什么工具。

     sudo apt-get install libtool

然后继续configure 有提示错误

checking for GNU automake >= 1.10... no

configure: error: could not find GNUautomake >= 1.10

解决办法跟第上次一样,缺什么工具就安装什么工具。

sudo apt-get installautomake

然后继续configure 有提示错误

configure: error: could not find curses header, required for thekconfig frontends

解决办法跟第上次一样,缺什么工具就安装什么工具。

    sudo apt-getinstall libncurses5-dev

然后继续config: ./configure–prefix=/work/tools/ crosstool-ng-1.20.0

假如仍提示类似问题直接安装该工具就可以

最后生成makefile工具

然后:make 然后:make install

2、交叉编译工具链的安装

然后参考博客:http://www.cnblogs.com/leaven/archive/2010/10/12/1848439.html

最后会在安装目录下的bin/生成ct-ng

然后设置环境变量/work/tools/crosstool-ng-1.20.0或者软连接:

sudo ln -s/work/tools/crosstool-ng-1.20.0/bin/ct-ng /usr/local/bin/ct-ng

然后ct-ng  help 可以看到版本信息。

然后 ct-ng list samples可以查看基本信息。

然后进入安装目录的lib/samples/下

cd /work/tools/crosstool-ng-1.20.0/lib/ct-ng.1.20.0/samples

看到:

    arm-unknown-eabi是基于裸板跑的,也就是无操作系统

     arm-unknown-linux-gnueabi 是基于linux的

     arm-unknown-linux-uclibcgnueabi 这个应该能看出来了,是为uclinux用的。

     arm-cortex_a8-linux-gnueabi 从名字上看是为cortex-a8用的。相应的还有m3,a10等等

   这里选择 arm-unknown-linux-gnueabi

下面将arm-unknown-linux-gnueabi拷贝到/work/tools/crosstool-ng-built(没有可以新建立一个)

mkdir /work/tools/crosstool-ng-built/

cp arm-unknown-linux-gnueabi/*  /work/tools/crosstool-ng-built/

假如是A8需要拷贝arm-cortex_a8-linux-gnueabi

然后在/work/tools/crosstool-ng-built/会得到crosstool.config  reported.by

现在将crosstool.config改为.config

cd /work/tools/crosstool-ng-built/

mv crosstool.config .config 注意.config是隐藏文件假如查看需要ls –a

然后在/work/tools/crosstool-ng-built/目录下执行

ct-ng menuconfig(这里一定要在该目录下执行)

然后在:

Paths and miscoptions  --->
      (${HOME}/development/crosstool-ng/src)Local tarballs directory   保存源码包路径
     (${HOME}/development/x-tools/${CT_TARGET}) Prefixdirectory  交叉编译器的安装路径
    这两个请依据你的实际情况来修改,也可以不修改使用默认 这里我们修改安装路径

这里设定:

Target options这是重点要修改的地方。(以下配置均是基于已拷备过来的配置。

       Target Architecture(arm) 这个不用管,已经是arm了。

       Default instruction set mode (arm) 这个也不管,也已经是arm了。

 (参考http://blog.chinaunix.net/u1/34474/showart_2198589.html)

   Target options  ---> 从datasheet中的 BLOCK DIAGRAM 中可以看到                

  (armv4t)Architecture level

          (arm9tdmi) Emit assembly forCPU   

          (arm920t)Tune for CPU

(在新版本可能不太一样,可能只需要填写(arm920t) Tune for CPU就可以。

      下面对上面三个名词做出解释:

    (armv4t):    Architecture level() 这个要改 ~~

         通过查找资料,这个应该是指令集的架构,对于S3C2410/S3C2440,都是ARM920T的核心,架构指令是armv4t    ,所以,如果要编译2410/2440的,就选armv4t

         以此类推

   (arm9tdmi):         S3C6410ARM1176JZF-S核心 使用的是armv6架构,就选armv6

       那么,具体都支持哪些架构呢?可以用man gcc来查询,搜索arm,再搜索-march=就可以找到本gcc支持的处理器核心列表了:

          -march=name
           This specifies thename of the target ARM architecture.  GCC uses
           this name todetermine what kind of instructions it can emit when
           generatingassembly code.  This option can be used in conjunction
           with or instead ofthe -mcpu= option.  Permissible names are:
           armv2, armv2a,armv3, armv3m, armv4, armv4t, armv5, armv5t, armv5e,
           armv5te, armv6,armv6j, armv6t2, armv6z, armv6zk, armv6-m, armv7,
           armv7-a, armv7-r,armv7-m, iwmmxt, iwmmxt2, ep9312.

这里有些问题,比如S3C2416处理器,使用的是ARM926EJ-S核心,通过查手册,arm926ej-s的核心是armv5tej,可上述列表中并没有这样的核心。所以,这里就选择一个最相近的核心 armv5te

   Emitassembly for CPU() 这个要改~~    这个对应的是CPU的核心类型。

(arm920t):   同样,也和上面的选项一样,对应一个GCC选项。GCC中这样描述

    -mcpu=name
           This specifies thename of the target ARM processor.  GCC uses this
           name to determinewhat kind of instructions it can emit when
           generatingassembly code.  Permissible names are: arm2, arm250,
           arm3, arm6, arm60,arm600, arm610, arm620, arm7, arm7m, arm7d,
           arm7dm, arm7di,arm7dmi, arm70, arm700, arm700i, arm710, arm710c,
           arm7100, arm720,arm7500, arm7500fe, arm7tdmi, arm7tdmi-s, arm710t,
           arm720t, arm740t,strongarm, strongarm110, strongarm1100,
           strongarm1110,arm8, arm810, arm9, arm9e, arm920, arm920t, arm922t,
           arm946e-s,arm966e-s, arm968e-s, arm926ej-s, arm940t, arm9tdmi,
           arm10tdmi,arm1020t, arm1026ej-s, arm10e, arm1020e, arm1022e,
           arm1136j-s,arm1136jf-s, mpcore, mpcorenovfp, arm1156t2-s,
           arm1176jz-s,arm1176jzf-s, cortex-a8, cortex-a9, cortex-r4,
           cortex-r4f,cortex-m3, cortex-m1, xscale, iwmmxt, iwmmxt2, ep9312.

            这样看简单一些了如果是 S3C2410/S3C2440 就选 arm920t  如果是s3c6410就选arm1176jzf-s            如果是s3c2416就选 arm926ej-s

接下来就是:

Floating point() 浮点相关的选项 s3c2410/s3c2440都没有硬件浮点,所以,这里就选software FPU

     s3c6410有硬件VFP,所以这里选的 hardware FPU。

 为了增加编译时的并行进程数,以增加运行效率,加快编译。
Paths and misc options  --->
   *** Build behavior ***
   (8) Number of parallel jobs  //多线程编译可节省时间,具体数字为cpu内核的2倍即可。
   这个数值不宜过大,应该为CPU数量的两倍。由于我的CPU是4核的,所以我填了8.

一些个性化的修改(可以不修改)
Toolchain options  --->
       *** Tuple completion and aliasing *** 
       (jason) Tuple's vendorstring
这样产生的编译器前缀就是:arm-jason-linux-gnueabi-

(arm-linux)Tuple's alias //这里是给产生的交叉编译工具起个别名,设置别名,这样会给每个工具创建一个软链接,比如:

arm-linux-gcc链接到到 arm-unknown-linux-gnueabi-gcc

这样就省去后面自己建立软连接的步骤。

下面是选择几个库的版本,这里选用针对linxu3.14的内核的版本:

operation systemà

linux kernel version 选择4.14.xx

 

c compilerà

gcc version

Gcc的版本选择对应的4.9.xx

这里还需要在operating system-->选择相应的编译版可以在。(当然也可以在.config手动修改)
配置好以后保存。这里我选择的内核版本是3.14.28glibc是2.18。

glibc是2.18     http://ftp.gnu.org/gnu/glibc/

binutils是2.22   http://ftp.gnu.org/gnu/binutils/

gcc4.9.1    http://ftp.gnu.org/gnu/gcc/gcc-4.9.1/

gdb7.8     http://ftp.gnu.org/gnu/gdb/

mpc1.0.2 http://ftp.gnu.org/gnu/mpc/

gmp5.1.3 http://ftp.gnu.org/gnu/gmp/

mpfr3.1.2  http://ftp.gnu.org/gnu/mpfr/

dmalloc5.5.2  http://fossies.org/linux/misc/dmalloc-5.5.2.tgz/

strace  http://sourceforge.net/projects/strace/files/strace/  假如是.xz格式的先解压成.tar

至于需要哪些安装包可以参看.config 其余愿意下载就下载不愿意下载就让他自己去下载吧

然后在/work/tools/crosstool-ng-built/的.config看到里面的基本配置比如内核的选择等等。

注意:当执行ct-ng的时候.Config内容都会改变。

最后ct-ng build  

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。然后是漫长的等待

有错误出现:

[ERROR]  Missing: 'i686-pc-linux-gnu-g++' or'i686-pc-linux-gnu-g++' or 'g++' : either needed!

[ERROR]  

[ERROR]  >>

[ERROR]  >> Build failed in step '(top-level)'

[ERROR]  >>

[ERROR]  >> Error happened in: CT_Abort[scripts/functions@331]

[ERROR]  >>        called from:CT_TestAndAbort[scripts/functions@351]

[ERROR]  >>        called from:main[scripts/crosstool-NG.sh@455]

[ERROR]  >>

[ERROR]  >> For more info on this error, look at the file: 'build.log'

[ERROR]  >> There is a list of known issues, some with workarounds, in:

[ERROR]  >>     '/work/tools/ct-ng/share/doc/crosstool-ng/ct-ng.1.20.0/B - Knownissues.txt'

[ERROR]  

[ERROR]  (elapsed: 0:03.31)

[00:05] / make:*** [build] 错误 1

这是由于ubuntu的gcc没有装g++,这里只需要安装g++就可以:

sudo apt-get install g++

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

[INFO ]  Installing pass-1 core C compiler

[EXTRA]    Configuring gcc

[EXTRA]    Building gcc

[ERROR]    make[1]: *** [configure-gcc] Error 1

[ERROR]  

[ERROR]  >>

[ERROR]  >> Build failed in step 'Installing pass-1 core C compiler'

[ERROR]  >>        called in step '(top-level)'

[ERROR]  >>

[ERROR]  >> Error happened in: CT_DoExecLog[scripts/functions@257]

[ERROR]  >>        called from:do_cc_core_backend[scripts/build/cc/gcc.sh@479]

[ERROR]  >>        called from:do_cc_core_pass_1[scripts/build/cc/gcc.sh@102]

[ERROR]  >>        called from:main[scripts/crosstool-NG.sh@638]

[ERROR]  >>

[ERROR]  >> For more info on this error, look at the file: 'build.log'

[ERROR]  >> There is a list of known issues, some with workarounds, in:

[ERROR]  >>     '/work/tools/crosstool-ng-1.20.0/share/doc/crosstool-ng/ct-ng.1.20.0/B -Known issues.txt'

[ERROR]  

[ERROR]  (elapsed: 28:53.93)

[28:56] / make:*** [build] 错误 2原因:好像是之前的gcc中的cloog方面的bug

解决办法:

最后是使用 gcc 4.6.0,可以正常编译,可以避免此问题

下载gcc4.6.0 http://ftp.gnu.org/gnu/gcc/gcc-4.6.0/

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

[INFO ]  Installing cross-gdb

[EXTRA]    Configuring cross-gdb

[EXTRA]    Building cross-gdb

[ERROR]    configure: error: expat is missing orunusable

[ERROR]    make[2]: *** [configure-gdb] Error 1

[ERROR]    make[1]: *** [all] Error 2

[ERROR]  

[ERROR]  >>

[ERROR]  >> Build failed in step 'Installing cross-gdb'

[ERROR]  >>        called in step '(top-level)'

[ERROR]  >>

[ERROR]  >> Error happened in: CT_DoExecLog[scripts/functions@257]

[ERROR]  >>        called from: do_debug_gdb_build[scripts/build/debug/300-gdb.sh@170]

[ERROR]  >>        called from:do_debug[scripts/build/debug.sh@35]

[ERROR]  >>        called from:main[scripts/crosstool-NG.sh@638]

[ERROR]  >>

[ERROR]  >> For more info on this error, look at the file: 'build.log'

[ERROR]  >> There is a list of known issues, some with workarounds, in:

[ERROR]  >>     '/work/tools/crosstool-ng-1.20.0/share/doc/crosstool-ng/ct-ng.1.20.0/B -Known issues.txt'

[ERROR]  

[ERROR]  (elapsed: 95:29.57)

[95:30] / make:*** [build] 错误 2

这里安装sudo apt-get install libexpat1-dev

大概过一个多小时终于完工最后可以用tree查看其目录结构。

这里说明一下,刚一开始我使用虚拟机编译的但是一旦安装到某个程序是虚拟机就会出错,不是ubuntu出错,是vmware出错。最后在非虚拟机的ubuntu系统安装成功的。

这样一来所有的工具都在/work/tools/ ct-ng-2440/ bin的目录下。接下来设置环境变量

export  PATH=$PATH:/work/tools/ct-ng-2440/ bin

为了防止每次重启系统都要设置,在sudo vi /etc/environment 修改PATH的值

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/work/tools/crosstool/ bin"

然后运行. /etc/environment 使生效环境变量(点后面有个空格)

原文地址:https://www.cnblogs.com/sky-heaven/p/13503502.html