小提醒Linux用户非常热衷的嵌入式系统

来源:互联网 发布:淘宝网纯棉四件套 编辑:程序博客网 时间:2024/05/20 14:23


Small reminder for Linux user very keen of embedded system.

We will detail the design of a cross-toolchain "From Scratch".

The purpose of this webpage is to understand the design method of a cross-toolchain of a pedagogical perspective.

 

1°) Obtaining a cross-toolchain for ARM architecture

There are several ways to obtain a cross-toolchain. First, the most tedious requiring one to one to compile the sources is commonly called "From Scratch". Another method, more comfortable, is the one requiring the implementation of a tool to generate a string. There crosstool ( http://www.kegel.com/crosstool/ ) which is obsolete but is still able to produce beautiful though somewhat veillotte chains. Crosstool is replaced by crosstool-ng (ng: New Generation) ( http://crosstool-ng.org). It is maintained and managed by a French. Its setting is kind of like the nucleus (ncurses menu to the sauce). There are chains of cross-made compilations and downloadable on the website of the German company DENX Software Engineering ( http://www.denx.de/en/News/WebHome ). Finally, there are also tools for creating complete embedded Linux distribution (kernel + file system + toolchain cross) as Buildroot, OpenEmbedded, PTXdist. Disadvantage, in many cases, these chains are specific to cross-compilation tool for creating distribution.

A cross toolchain consists of different elements as follows:
- The file header of a Linux kernel,
- A set of software development tools: binutils (binary utilities),
- A Compiler: GCC,
- A C library: glibc
- For more recent versions of GCC: a set of libraries for scientific computing: MPFR and GMP.

All these elements are vital to achieving a toolchain. Their various combinations can generate a cross-toolchain with the help of a few patches or not at all be compatible with each other. It should be to experiment with different versions of each element before reaching a channel without too much difficulty. The library used in the following examples is glibc. It is mainly used in the Linux world. This library contains the main C library system. Glibc provides a set of routines (opening / - closing file; memory allocation etc ...) necessary for the proper functioning of the system based on GNU Linux kernel. It acts as an interface between the kernel and operating system calls with these systems it provides. However, there are other C library that are much lighter and more suitable for embedded systems, for example, the library uClibc, dietlibc library or library newlib.

2) What you need to know or own

Base for a cross toolchain fully functional, it should obviously have:
- Preferably a fast machine (reduced build time),
- A Linux operating system,
- A GCC compiler,
Whichever method of designing the cross-toolchain, it should also have prior program "autoconf" installed in the host machine. This program is responsible for producing a file (called make) that automates the compilation of all sources of a package. To generate such a file, the "configure" script has the mission to inspect the system to ensure that sources can find all dependencies set on the system to properly compile the sources. It should also clarify some terms passed as parameters to the configure script:
build : refers to the machine where the source code is compiled,
host : is the machine where the compiler is running,
target : is the machine for which code is generated.
In all cases the name of the chain will be final type arm-none-linux-gnueabi . The four values ​​mean:
arm : information on the processor name. It can be mips, i686, x86_64 etc. ...
none : provides information on additional information. Sometimes this field does not exist. In the case of its presence, the field type is unknown or none,
linux : information about the operating system,
gnueabi : information on the type of libc. There are other gnuabi, gnulibc, uclibc.

3) The common steps of creating a chain

1. Obviously obtaining sources is essential. Downloading them from an official website can be done either by hand (systematic use of the wget command for each package), or automatically by script (this is the case with crosstool-ng and crosstool). You can download the sources from CVS (Concurrent Versions System). The latter is a version control system client-server that allows multiple people to work simultaneously on a single set of files. This method allows for the latest update sources. In our case, since we will work with a little packet of old and whose changes are included in the next higher versions, CVS is not used.

2. The first package to be compiled because the compiler is GCC binutils depends on the tools of it to create executables. Indeed, this is binutils which assembles the object files generated by GCC in an executable image,

3. We need the functions header of the Linux kernel specifically for the ARM architecture. They contain essential functions such as system calls to interact with the kernel. These headers are used to produce the C library (glibc) for ARM,

4. Formal credit We will compile a GCC compiler depleted basic functions. Often called "bootstrap GCC", the compiler is still able to produce a library for ARM using Glibc functions of the kernel headers from the previous step,

5.t We use our "bootstrap GCC" to produce the file header of Glibc,

6, We get a C library function for ARM.

6. We have all the tools to start designing our next GCC compiler for ARM,

4. We compile the GMP and MPFR math libraries for ARM,

9. Finally, we compile the final GCC with previous libraries.

 

4) The alchemy of different versions of components of a cross toolchain

For the generation of a chain "from scratch", you have to hand all the previous steps. Versions of the various components work well with only a few patches:

- The Linux kernel 2.6.28.3 in its version, downloadable from the address http://www.kernel.org/pub/linux/kernel/v2.6/ ,

The other ingredients are downloadable from the address: http://ftp.gnu.org/gnu/ ,

- Binutils in its version 2.20,

- GCC version 4.3.3,

- Glibc in version 2.9,

- Glibc-ports in its version 2.9,

- GMP version 4.3.2,

- MPFR version in 3.0.1:

5) Get a cross-toolchain "From Scratch"

a) Introduction

This procedure is inspired by the book "Pro Linux Embedded Systems" by Gene Sally by Apress. There is also here and there web sites more or less serious that get a toolchain smoothly and without patch. I confess to being very cautious about getting a chain smoothly and without a shadow of one patch. Here is detailed, with patch, all the compiler options and each step is discussed.
The compilation of the chain was performed in a PC which is running a 64 bit Ubuntu 4.11. The elements of the host system interfere little in the construction of the chain, but it should be clarified version of the various components installed:

- Binutils in its version 2.21,

- GCC version 4.5.2,

- Glibc in version 2.13,

- Glibc-ports in the version 2.13,

- GMP version 4.3.2,

- In its MPFR version 3.0.0.

For reasons of convenience, we will use two terminals to generate our cross toolchain. These terminals can be called T1 and T2. Both terminals have similar environment variables. However, the terminal T2 advantage of environment variables to facilitate the compilation. In each terminal, enter the following common environment variables:

export SRCDIR=/root/chaine/sources
This directory home all sources downloaded.

export BUILDDIR=/root/chaine/build
It is in this directory that will compile all source packages.

export TARGETMACH=arm-none-linux-gnueabi
This variable specifies the type of target architecture.

export BUILDMACH=x86_64-pc-linux-gnu
This variable specifies the type of architecture in which the package is compiled.

export INSTALLDIR=/opt/arm
This variable provides information about the folder hosting the cross-toolchain.

export SYSROOTDIR=/opt/arm/sysroot
This variable provides information on the directory hosting the libraries and header files the kernel of the target system.

T2 to add more environment variables as follows:

export CROSS=arm-none-linux-gnueabi
Indicates that we use the variable fields CROSS with arm-none-linux-gnueabi.

export CC=${CROSS}-gcc
Indicates that we use the GCC compiler for the ARM architecture.

export LD=${CROSS}-ld
Indicates that we use the dynamic library of the ARM architecture.

export AS=${CROSS}-as
Indicates that we use the assembler of the ARM architecture.

b) Compilation of Binutils

The first package to be compiled is Binutils. Its compilation is not a problem and is fast. From the terminal T1, let's type the following lines:


mkdir $BUILDDIR/binutils
cd $BUILDDIR/binutils
../../sources/binutils-2.20/configure \
--disable-werror \
--build=$BUILDMACH \
--prefix=$INSTALLDIR \
--with-sysroot=$SYSROOTDIR \
--target=$TARGETMACH
make
make install

-> A few explanations:

Parameters

  Fonction

--disable-werrorDisabling "warning": avoid blocking the compilation--build=$BUILDMACHArchitecture of the host PC which is the compilation--prefix=$INSTALLDIRHome directory of the executable--with-sysroot=$SYSROOTDIRHome directory of booksellers--target=$TARGETMACHTarget architecture

 

c) kernel header files


Compiling the kernel header files generates an error due to a function name reused by different codes when compiling. Open the file linux-2.6.28.3/script/unifdef.c by an editor like vim. Change the function name by removing the letter "e" of the name of the function getline() in getlin() . You can complete the transaction by directly applying the patch unifdef.c.patch . It simply copy this patch into the directory linux-2.6.28.3/script/ , to go to that directory and apply it by typing:patch < unifdef.c.patch
Now, the compilation and installation is done without hassle.

From the terminal T1, let's type the following lines:


cd $SRCDIR/linux-2.6.28.3
make mrproper
make ARCH=arm kb9202_defconfig
make ARCH=arm headers_check
make ARCH=arm INSTALL_HDR_PATH=$INSTALLDIR/sysroot/usr headers_install

-> A few explanations:

Option ARCH=arm accurate, of course, the type of target architecture. We will use this string for the card (a little older, I admit) KwikByte KB9202C which is, unfortunately, more for sale on the manufacturer's website http://www.kwikbyte.com

That is why we specify its use by the entrance kb9202_defconfig . This file includes all the options for the Linux kernel map. To map a generic ARM: Optionintegrator_defconfig brings together all the common options of the kernel for all ARM. In the kernel directory linux-2.6.28.3/arch/configs/ , we can see all cards natively taken into account by the kernel.

d) Bootstrap GCC

Before proceeding with the compilation and installation of primer GCC (bootstrap GCC), ensure that the GMP and MPFR math libraries are installed in your Linux system.
The GMP library (download at: http://gmplib.org ), contains arithmetic functions to multi-particulars. It is used mainly in research in cryptography and algebraic.GMP is defined as a Debian / Ubuntu as the package to download / install via the Synaptic package manager. The packages are:
libgmp3c2 (C library),
libgmp3-dev (C libraries and C + +),
lib32gmp3-dev (C libraries and C + + in 32-bit)
- libgmpxx4ldbl (C + + library).

The MPFR library (download at: http://www.mpfr.org ), contains mathematical functions that can perform calculations multi clarification floating point with rounded accurate. It is maintained by Laurent Fousse ( laurent@komite.net ) professor at Grenoble. 
The library is downloadable and installable under Debian / Ubuntu, in the form of package via Synaptic:
libmpfr4 (Main Library)
libmpfr-dev (header functions needed for compiling)
lib32mpfr4 (32-bit version)
lib32mpfr-dev (header functions required to compile in 32-bit version).

From the terminal T1, let's type the following lines:


mkdir $BUILDDIR/amorce-gcc
cd $BUILDDIR/amorce-gcc
../../sources/gcc-4.3.3/configure \
--build=$BUILDMACH \
--host=$BUILDMACH \
--target=$TARGETMACH \
--prefix=$INSTALLDIR \
--without-headers \
--enable-bootstrap \
--enable-languages=c \
--disable-threads \
--enable-__cxa_atexit \
--disable-libmudflap \
--with-gnu-ld \
--with-gnu-as \
--disable-libssp \
--disable-libgomp \
--disable-nls \
--disable-shared

make all-gcc install-gcc

make all-target-libgcc install-target-libgcc

ln -s /opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a \
/opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_sh.a

-> A few explanations:

Most settings entered on the command line disable a number of options not required for the design of a standard library. 

ParametersFonction--without-headersnot compile with the headers in comment--enable-bootstrapmode activation "bootstrap"--enable-languages=cwe compile for the C language and it is also possible to compile the C + +--disable-threadsDisabling include files multithreaded because they have not yet been created for the target architecture. GCC will be able to find information on multi-threaded after the headers are created Glibc library--enable-__cxa_atexitoption describing the implementation of the function atexit ()--disable-libmudflaplibrary used for complex débuger errors in a userspace program. Not necessary here.--with-gnu-ldCompiling with native linker--with-gnu-asCompiling with native assembler--disable-libsspdeactivation of the bookstore that specializes in memory or stack overflow--disable-libgompDisabling the OpenMP API specialized in parallel computing--disable-nlsDisabling all local languages ​​except English (POSIX)--disable-sharednative compiler (GCC bootstrap) will not support dynamic libraries time to design the final GCC compiler.

CommandExplanationmake all-gcc install-gcccreated the basic compiler and installs it in the directory specified by the variable $ INSTALLDIRmake all-target-libgcc install-target-libgccConstruction of a core library used by GCC to produce code. This library must be built before the final because it depends entirely on it.ln -s /opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a /opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_sh.aBy this symbolic link, we force the design of the library of static toolchain.

e) Creation of header files from glibc

These header files are used for defining the functions created by the compiler installed on the target system (our famous Bootstrap GCC). 
Before proceeding with the compilation and installation of header files glibc, it should be patched two files. The first patch changes the version number supported by Glibc and is configure.patch (applicable in the root of glibc-2.9).
The second solves a problem with sed backslash and is gen-sorted.awk.patch . (Applicable in the directory glibc-2.9/scripts/ ).

Since the terminal T2, let's type the following lines:

mkdir $BUILDDIR/libc-header
cd $BUILDDIR/libc-header
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
export PATH=$INSTALLDIR/bin:$PATH
../../sources/glibc-2.9/configure \
--build=$BUILDMACH \
--host=$TARGETMACH \
--prefix=$SYSROOTDIR/usr \
--with-headers=$SYSROOTDIR/usr/include \
--config-cache \
--enable-add-ons=glibc-ports-2.9,nptl \
--enable-kernel=2.6.0
make -k install-headers cross_compiling=yes install_root=$SYSROOTDIR
ln -s /opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a \
/opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_eh.a


ParametersFonction--prefix=$SYSROOTDIR/usr
Home directory of the executable.--with-headers=$SYSROOTDIR/usr/include
Use of the headers of the core of step c).--config-cache
Force the executable configure to read the instructions file config.cache--enable-add-ons=glibc-ports-2.9,nptl
Using the additional library glibc-ports for ARM (our case). Also valid for MIPS and PowerPC.--enable-kernel=2.6.0Design of the library to the Linux kernel 2.6.0 kind.
CommandExplanationecho "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
The file config.cache contains these two lines that prevent the execution of code compiled for ARM toolchain with cross installed on the host which is the x86.make -k install-headers cross_compiling=yes install_root=$SYSROOTDIRThe header files are cross-compiled and installed into the $SYSROOTDIRln -s /opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a \
/opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_eh.a
Same here: by this symbolic link, we force the design of the library of static toolchain.

e) Establishment of Glibc

Well, here we are, we have all the elements in the directory $INSTALLDIR to be able to design our Glibc for ARM. You will notice that the controls are very similar compared to the previous step.
Note: The compilation takes a long time and most of the parameters have already been explained.

Since the terminal T2, let's type the following lines:

mkdir $BUILDDIR/glibc
cd $BUILDDIR/glibc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
../../sources/glibc-2.9/configure \
--build=$BUILDMACH \
--host=$TARGETMACH \
--prefix=/usr \
--with-headers=$SYSROOTDIR/usr/include \
--config-cache \
--enable-add-ons=glibc-ports-2.9,nptl \
--enable-kernel=2.6.0
make -k install-headers cross_compiling=yes install_root=$SYSROOTDIR
make
make install_root=$SYSROOTDIR install


f) Creation of the GCC compiler for ARM

The GCC compiler generated after this step, is able to compile code static. You can stop after this step if you develop applications using extensions static libraries.

From the terminal T1, let's type the following lines:

mkdir $BUILDDIR/gcc
cd $BUILDDIR/gcc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
export CC=gcc
../../sources/gcc-4.3.3/configure \
--build=$BUILDMACH \
--target=$TARGETMACH \
--prefix=$INSTALLDIR \
--with-sysroot=$SYSROOTDIR \
--enable-languages=c \
--with-gnu-as \
--with-gnu-ld \
--disable-multilib \
--with-float=soft \
--disable-sjlj-exceptions \
--disable-nls \
--enable-threads=posix \
--enable-long-longx
make all-gcc
make install-gcc


ParametersFonctionexport CC=gccThe environment variable forces the compiler for ARM GCC compiler of the host.--disable-multilib
Different variants for different library arhitecture different is not designed.--with-float=softSupport for floating point numbers emulated by the software because the ARM have no FPU (Floating Point Unit)--disable-sjlj-exceptions
Exceptions specific to C + +, they should be seen off our string only supports C.--enable-threads=posix
Threads are POSIX format--enable-long-longxC, support for long integers 
g) Cross-compiling bibilothèques GMP and MPFR

Add functionality to our final GCC by implementing special libraries for multiprecision GMP and MPFR. Prior to cross-compile GMP (GMP is compiled first because MPFR depends on it), it is necessary to install the package m4 is a macro processing language (maintained by Santiago Vila at sanvila@debian.org) . GMP and MPFR libraries to compile statically with the previous CCG. They will move into the directory /opt/arm/lib

Since the terminal T2, let's type the following lines:

mkdir $BUILDDIR/gmp
cd $BUILDDIR/gmp
export CFLAGS=-static
../../sources/gmp-4.3.2/configure \
--build=$BUILDMACH \
--host=$TARGETMACH \
--prefix=$INSTALLDIR \
--disable-shared
make
make install


Since the terminal T2, let's type the following lines:

mkdir $BUILDDIR/mpfr
cd $BUILDDIR/mpfr
../../sources/mpfr-3.0.1/configure \
--build=$BUILDMACH \
--host=$TARGETMACH \
--prefix=$INSTALLDIR \
--with-gmp=$INSTALLDIR
make
make install


h) Creating final GCC compiler

We have all the elements to finalize the design of the GCC compiler. The toolchain is obitent in the cross compiling with the compiler of the host (where the line export CC=gcc ). This is a rather long operation.
The arguments passed are the same as f) with some exceptions: support for libraries and compiler previous final supporting dynamic compilation.

From the terminal T1, let's type the following lines:

mkdir $BUILDDIR/gcc-final
cd $BUILDDIR/gcc-final
export CC=gcc
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" » config.cache
../../sources/gcc-4.3.3/configure \
--build=$BUILDMACH \
--target=$TARGETMACH \
--prefix=$INSTALLDIR \
--with-sysroot=$SYSROOTDIR \
--enable-languages=c \
--with-gnu-ld \
--with-gnu-as \
--disable-multilib \
--with-float=soft \
--disable-sjlj-exceptions \
--disable-nls \
--enable-threads=posix \
--disable-libmudflap \
--disable-libssp \
--enable-long=longx \
--with-shared \
--with-gmp=$INSTALLDIR \
--with-mpfr=$INSTALLDIR
make
make install


The final library of GCC is in the directory: /opt/arm/arm-none-linux-gnueabi/lib . The cross toolchain is in the directory /opt/arm/bin . In the terminal T1, we can add the executables of cross-toolchain in the environment variable PATH by typing: export PATH=$INSTALLDIR/bin:$PATH 
By typing the first letters of executable arm and pressing the tab key, we now have direct access to executables.

6) Test of the cross-toolchain "From Scratch"

Do a test build with our newly installed chain. We will compile the program celebrates Helloworld that just prints a terminal in the message "Hello World". 
In compiling the program by:

arm-none-linux-gnueabi-gcc -o helloworld helloworld.c

We can check the file type compiled using the command line:
file helloworld

gives:

helloworld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped

Well, this little test tells us that the executable is generated for the ARM architecture. You diposez now a beautiful cross-toolchain for ARM made for yourself!


Page updated on 06/04/2012

 



我们将详细设计的交叉工具链“从零开始”。

此网页的目的是要了解教学的角度交叉工具链的设计方法。

 

1°) 获取交叉工具链ARM架构

取得的横工具有几种方法: 首先,需要一个到一个编译源代码,最繁琐的,通常被称为“从头开始” 的另一种方法,更舒适,需要执行一个工具,以产生一个字符串。 的crosstool(http://www.kegel.com/crosstool/)是过时的,但仍然能够产生美丽的虽然有点veillotte的链。 的crosstool取代的crosstool-NG(NG:新一代)(呻/的crosstool ng.org的)。维护和管理由法国, 它的设置是怎么样的,像的核(ncurses的菜单酱)。 链交叉汇编和DENX软件工程的德国公司(包含http://网站上下载www.denx.de / EN /新闻/ WebHome的)。 最后,也有工具,用于创建完整的嵌入式Linux发行版(内核+文件系统+工具链交叉)Buildroot里面,OpenEmbedded的,PTXdist。 缺点,在很多情况下,这些连锁店具体的交叉编译工具,用于创建分布。

交叉工具链由不同的元素如下:
-一个Linux内核头文件
-一组软件开发工具:binutils的(二进制事业)
-一个编译器:GCC 
- AC库:glibc的
-对于较新版本的GCC:一套用于科学计算的库:MPFR和GMP。

所有这些因素是至关重要的,以实现工具链, 它们的各种组合,可以产生一个交叉工具的帮助下几个补丁或根本不是彼此相容的, 它应该是与不同版本的每一个元素,才作实验渠道不会有太大困难。在下面的例子中使用这个库是glibc, 它主要用于在Linux世界, 这个库包含了主要的C库系统。 ...)基于GNU Linux内核系统的正常运作所需。 它作为内核和操作系统调用,它提供了与这些系统之间的接口。 不过,也有其他C库,轻得多,更适合嵌入式系统,例如,图书馆的uClibc的,dietlibc图书馆图书馆newlib。

2)你需要知道或拥有

基地跨工具功能齐全,它显然应该有:
-最好是快速的机器(减少构建时间),
- Linux操作系统
- GCC编译器,
无论方法设计交叉工具链,它也应该有事先计划“autoconf的”安装在主机上。 这个程序是负责生产自动编译所有源包文件(名为make)。 为了生成这样的文件,“配置”脚本任务来检查系统以确保来源可以找到正确编译源代码,在系统中设置的所有的依赖。 还应该澄清一些条款作为参数传递给configure脚本:
建设:是指源代码编译的机器
主机:的机器上运行编译器
目标
在所有的情况下将是最终的名称链型臂没有Linux的gnueabi 这四个值的意思是:
:信息处理器的名称, 它可以是MIPS在i686,x86_64的等... 
没有提供额外的信息的信息。 有时这一领域不存在, 在其存在的情况下,字段类型是未知或没有,
linux的操作系统的信息,
gnueabi:libc中的类型信息, 还有其他gnuabi,gnulibc,uClibc的。

3)的共同的步骤创建链轮

1。 显然取得来源是至关重要的。 他们从官方网站下载,可以做手(系统使用wget命令为每个包),或自动脚本(这是crosstool的NG和crosstool的情况下)。 从CVS(并行版本系统),可以下载的来源, 后者是一个版本控制系统的客户端-服务器,允许多人同时在一个单一的文件集, 这种方法允许最新的更新源, 在我们的案例中,由于我们将与旧的和一个小的数据包,其变动计入在未来更高版本,CVS不使用。

(2) 第一包进行编译,因为编译器GCC的binutils依赖于它来创建可执行文件的工具。 事实上,这是binutils的组装对象GCC所生成的可执行映像文件,

3, 我们需要的功能,专门针对ARM架构的Linux内核头。它们含有人体必需的功能,如系统调用与内核的交互, 这些头被用于生产的C库(glibc)为ARM,

4。正规信贷 枯竭的基本功能, 通常被称为“引导GCC”,编译器仍然能够生产出库ARM内核的头文件使用glibc的功能从以前的步骤,

5.T 我们用我们的“引导海湾合作委员会”,以产生Glibc的文件头,

6, 我们得到了ARM C库函数。

6, 我们拥有所有的工具,开始设计我们未来的ARM GCC编译器,

4, 我们编译为ARM库GMP和MPFR数学的,

9, 最后,我们最终的GCC编译与以前的库。

 

4)交叉工具链组件的不同版本的炼金术

对于连锁“从零开始”的产生,你必须把所有前面的步骤。 版本的各个组成部分的工作以及与只有几个补丁:

- Linux内核2.6.28.3版本,下载地址http://www.kernel.org/pub/linux/kernel/v2.6/,

下载地址:http://ftp.gnu.org/gnu/的其他成分​​,

- Binutils的2.20版本,

- GCC 4.3.3版本,

- 在2.9版本的Glibc

- 端口,在其2.9版本的glibc-

- GMP版本4.3.2,

- 3.0.1 MPFR版本:

5)交叉工具链“从零开始”

a)导言

这个程序的灵感来自书“临Linux的嵌入式系统Apress的基因莎莉”, 也有在这里和那里网站或多或少严重,平稳,无补丁工具链。 我承认非常谨慎得到链顺利,没有一个补丁的影子。 下面是详细的,带补丁,所有的编译器选项,每一步的讨论。
链汇编在一台PC运行的是64位Ubuntu 4.11进行。 系统干扰小链的建设,但应该澄清的版本安装的各个组成部分:

- Binutils的2.21版本,

- GCC 4.5.2版本,

- 中的Glibc版本为2.13,

- 港口的glibc-2.13版本,

- GMP版本4.3.2,

- 在MPFR 3.0.0版本。

为了方便起见,我们将使用我们的交叉工具生成的两个端子, 这些端子可以称为T1和T2, 两个终端有相似的环境变量, 然而,终端T2利用环境变量,以方便汇编 在每个终端输入以下的通用环境变量:

出口SRCDIR = /根/ CHAINE /来源
回家这个目录下载所有来源。

BuildDir的出口= /根/ CHAINE /建立
此目录中,将编译所有源代码包。

出口TARGETMACH =臂没有Linux的gnueabi 
这个变量指定类型的目标架构。

出口BUILDMACH = x86_64的PC-Linux的GNU 
此变量指定类型的架构,其中包编译。

出口INSTALLDIR = / opt /手臂中
这个变量所在的文件夹交叉工具链提供的信息。

出口SYSROOTDIR = /选择/手臂/ SYSROOT的的
此变量提供目录上托管信息库和头文件的内核目标系统。

T2添加更多的环境变量如下:

出口CROSS =臂没有Linux的gnueabi 
表示,我们使用可变领域交叉臂没有Linux的gnueabi。

出口CC = $ {CROSS}-gcc的
指示,我们使用GCC编译器的ARM架构。

出口LD = $ {CROSS}-LD 
表示,我们使用动态库的ARM架构。

导出为= $ {CROSS},
表示我们使用汇编的ARM架构。

B)Binutils编译

第一包编译Binutils的 编制是没有问题的,并很快。 从端子T1,让键入以下命令行:


BuildDir的MKDIR $ / binutils的
BuildDir的CD $ / binutils的
../../sources/binutils-2.20/configure \
- 关闭使用-Werror的\
- 构建= $ BUILDMACH \
- 前缀= $ INSTALLDIR \
- SYSROOT = $ SYSROOTDIR \
- 目标= $ TARGETMACH
使
使安装

- >有几个解释:

参数

  Fonction

- 禁止使用-Werror禁用“警告”:避免阻塞编译- 构建= $ BUILDMACH主机PC的体系结构汇编的 - prefix = $ INSTALLDIR首页目录下的可执行- SYSROOT = $ SYSROOTDIR首页目录书商- 目标= $ TARGETMACH目标体系结构

 

C)内核头文件


编译内核头文件生成一个错误,由于在编译时通过不同的代码重用的函数名。 由一个编辑打开文件linux-2.6.28.3/script/unifdef.c,像vim 更改函数名删除字母“e “函数的getline函数()getlin()的名称, 你可以完成由应用补丁unifdef.c.patch直接交易, 它只是简单地复制这个补丁放到目录linux-2.6.28.3/script /去到该目录,并申请通过键入以下命令:补丁<unifdef.c.patch的
编译和安装不麻烦。

从终端T1,让键入以下命令行:


CD $ SRCDIR/linux-2.6.28.3 
使mrproper 
ARCH =手臂kb9202_defconfig的
ARCH =臂headers_check 
ARCH = arm INSTALL_HDR_PATH的= $ INSTALLDIR / SYSROOT的/ USR的headers_install的

- >有几个解释:

选项ARCH =手臂准确,当然,目标架构的类型。 我们将使用这个字符串存储卡(年纪大一点的,我承认),不幸的是,更多的销售制造商的网站上的http://www KwikByte KB9202C kwikbyte.com。

这就是为什么我们入口kb9202_defconfig所指定其使用 此文件包含Linux内核映射的所有选项。 要映射一个通用的ARM:选项integrator_defconfig带来了所有常见的所有ARM内核的选项。在内核目录linux-2.6.28.3/arch/configs /,我们可以看到所有的卡本身所考虑的内核。

四)引导GCC

进行底漆GCC(引导海合会)的编译和安装之前,请确保安装在你的Linux系统的GMP和MPFR数学的库。
多详情。 主要用于加密和代数研究。 GMP被定义为一个Debian / Ubuntu的包通过新立得软件包管理器下载/安装 包:
libgmp3c2的(C库),
与libgmp3- dev(C库和C + +)
-dev的lib32gmp3(C库和C + +在32位)的
libgmpxx4ldbl(C + +库)。

的的MPFR库(下载:http://www.mpfr。 ORG),包含可以执行计算多澄清四舍五入精确浮点数学函数。 保持由Laurent Fousse的在格勒诺布尔(laurent@komite.net)教授。 
图书馆是根据Debian / Ubuntu的下载和安装的形式,包,通过突触:
libmpfr4(主馆)
-dev的libmpfr(头功能需要进行编译)
lib32mpfr4(32位版本)
lib32mpfr-dev的(头功能需要编译32位版本)。

从终端T1,让键入以下命令行:


MKDIR $ BuildDir的/ amorce-gcc的
CD $ BuildDir的/ amorce-GCC 
../../sources/gcc-4.3.3/configure \ 
-构建= $ BUILDMACH \ 
-主机= $ BUILDMACH \ 
-目标= $ TARGETMACH \ 
的- prefix = $ INSTALLDIR \ 
-无头\ 
-使引导\ 
-使语言= C \ 
-禁用线程 禁用libmudflap \ 
-使__cxa_atexit \ 
- \ 
- GNU-ld的\ 
-与GNU-\ 
-禁用libssp的\ 
-禁用libgomp的\ 
-禁用NLS \ 
-禁用共享

使所有GCC安装GCC

使所有目标libgcc的安装目标libgcc的

LN-S / opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a \ 
/ opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_sh一个。

- >有几个解释:

在命令行中输入的大部分设置禁用一些不需要的选项标准库的设计。 

参数Fonction- 无头不进行编译的头在评论- 允许自举模式激活“引导”- 使语言= C我们的C语言编译,也可以编译C + +- 禁用线程禁用包括文件多线程的,因为他们还没有被创建为目标架构。 GCC将头后能够找到多线程的信息创建glibc库- 启用__cxa_atexit选项​​atexit函数的实施()- 禁用libmudflap库用于在用户空间程序复杂débuger错误, 没有必要在这里。- 与GNU-LD与本地链接器编译- 与GNU-与本地汇编编译- 禁用libssp停用的书店,专门在内存或堆栈溢出- 禁用libgomp禁用OpenMP API的专门从事并行计算- 禁用NLS禁用所有本地语言除英语(POSIX)- 禁用共享本地编译器(GCC引导)将不支持动态库的时间来设计最终的GCC编译器。

命令解释使所有GCC安装GCC创建基本的编译器,它安装在指定的目录变量$ INSTALLDIR使所有目标libgcc的安装目标libgcc的使用GCC来产生代码的核心库的建设, 必须建立这个库前的最后,因为它完全依赖于它。LN-S / opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a / opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_sh的的。一通过这种象征性的链接,我们强制静态工具库的设计。

e)建立glibc的头文件

使用这些头文件定义的函数创建在目标系统上安装编译器(我们著名的引导GCC) 
进行编译和安装glibc的头文件之前,应修补两个文件。 第一个补丁的版本改变支持的数目的Glibc和是configure.patch(适用于根的glibc-2.9),
第二个解决的问题用sed反斜线是根sorted.awk.patch的。(适用目录中的glibc-2.9/scripts /)。

T2航站楼,让键入以下命令行:

BuildDir的MKDIR $ / libc的头
CD $ BuildDir的/ libc的头
回声“libc_cv_forced_unwind =是”config.cache的
回声“libc_cv_c_cleanup =是”config.cache的
出口PATH = $ INSTALLDIR /斌:$ PATH 
.. / .. / sources/glibc-2.9/configure \ 
-构建= $ BUILDMACH \ 
-主机= $ TARGETMACH \ 
的- prefix = $ SYSROOTDIR的/ usr \ 
-头= $ SYSROOTDIR / usr / include目录\ 
-配置缓存\ 
-启用附加组件glibc的端口-2.9。NPTL \ 
-启用内核2.6.0 
做出-K安装头cross_compiling =是install_root = $ SYSROOTDIR 
LN-S / OPT /手臂/ lib中/ GCC / arm-none-linux-gnueabi/4.3.3/libgcc.a \ 
/ opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_eh.a的


参数Fonction- 前缀= $ SYSROOTDIR的/ usr
首页目录下的可执行。- 头= $ SYSROOTDIR的/ usr / include中
使用的核心报头的步骤c)。- 配置缓存
强制配置阅读说明书文件config.cache的可执行文件- 启用附加组件的glibc-端口-2.9,NPTL
使用额外的库glibc的端口为ARM(我们的情况下), 也有效的MIPS和PowerPC。- 启用内核2.6.0图书馆建筑设计的Linux内核2.6.0样。
命令解释回声“libc_cv_forced_unwind =是”> config.cache的
回声“libc_cv_c_cleanup =是”config.cache的
文件config.cache的包含这两条线,防止执行的代码为ARM工具链是x86主机上安装的交叉编译。做出-K安装头cross_compiling =是install_root = $ SYSROOTDIR交叉编译头文件安装到$ SYSROOTDIRLN-S / opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a \ 
/ opt/arm/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc_eh一个。
同样在这里:这个符号链接,我们强制静态工具库的设计。

e)建立的glibc

嘛,我们在这里,我们有目录$ INSTALLDIR能够为ARM设计我们的glibc中的所有元素。你会注意到,控制是非常类似的一步。
注:编译需要很长的时间和大部分参数都已经被解释。

让终端T2以来的键入以下行:

MKDIR BuildDir的美元/ glibc的
CD $ BuildDir的/ glibc的
回声“libc_cv_forced_unwind =是”config.cache的
回声“libc_cv_c_cleanup =是” -构建»config.cache的
../../sources/glibc-2.9/configure \ 
= $ BUILDMACH \ 
-主机= $ TARGETMACH \ 
的- prefix = / USR \ 
-头= $ SYSROOTDIR / usr / include目录\ 
-配置缓存\ 
-启用附加产品的glibc-端口-2.9。NPTL \ 
-启用内核= 2.6.0 
品牌-K安装的头cross_compiling =是install_root = $ SYSROOTDIR install_root = $ SYSROOTDIR安装




F)创作的GCC编译器ARM

GCC编译器生成的这一步后,能够编译代码静态的, 可以停止这一步后,如果您开发的应用程序使用静态库扩展。

从终端T1,让键入以下命令行:

MKDIR $ BuildDir的/ GCC 
CD $ BuildDir的/ GCC 
呼应“libc_cv_forced_unwind =是”> config.cache的
回声“libc_cv_c_cleanup =是”» config.cache的
出口CC = GCC 
../../sources/gcc-4.3.3/configure \ 
-构建= $ BUILDMACH \ 
-目标= $ TARGETMACH \ 
的- prefix = $ INSTALLDIR \ 
- SYSROOT = $ SYSROOTDIR 
= C \ 
-与GNU-\ 
- \ -使语言GNU-LD \ 
-禁用的multilib \ 
-浮=软\ 
-禁用sjlj的例外\ 
-禁用NLS \ 
-使线程= POSIX \ 
-使长期longx,
使所有GCC 
安装GCC


参数Fonction出口CC = gcc的环境变量强制编译器为ARM GCC编译器的主机。- 禁用的multilib
是不是设计不同为不同库arhitecture的不同变种。- 与浮=软通过软件模拟支持浮点数,因为ARM有没有FPU(浮点运算单元)- 禁用sjlj的例外
具体到C + +,他们应该看到我们的字符串只支持C.例外- 使线程= POSIX
主题是POSIX格式- 使长期longxC,支持长整数 
g)跨编译bibilothèquesGMP和MPFR

功能加入到我们的最终GCC通过实施特殊多倍GMP和MPFR库。此前交叉编译GMP(GMP是先编译由于MPFR依赖于它),它是必要的M4是一个宏处理语言(维持由sanvila@debian.org圣地亚哥维拉)来安装软件包。 GMP和MPFR图书馆的编译与以往CCG静态 他们将移动到该目录下的/ opt /手臂/ lib中

由于终端T2,让键入以下命令行:

BuildDir的MKDIR $ / GMP 
BuildDir的CD $ / GMP 
出口CFLAGS =-静态的
.. / .. / sources/gmp-4.3.2/configure \ 
-构建= $ BUILDMACH的\ 
-主机= $ TARGETMACH \ 
的- prefix = $ INSTALLDIR \ 
-禁用共享 安装



,让键入以下命令行:

MKDIR $ BuildDir的/ MPFR 
CD $ BuildDir的

-构建= $ BUILDMACH \ 
-主机= $ TARGETMACH \ 
的- prefix = $ INSTALLDIR \ 
- / MPFR ../../sources/mpfr-3.0.1/configure的GMP = $ INSTALLDIR 安装



八)创建最终的GCC编译器

的所有元素都敲定GCC编译器的设计。与主机的编译器(线出口CC = gcc的),的交叉编译工具链是obitent 
:以前的库和编译器的支持最终支持动态编译,

从终端T1,让键入以下命令行:

MKDIR $ BuildDir的/ GCC决赛的
CD $ BuildDir的/ GCC决赛
出口CC = gcc的
回声“libc_cv_forced_unwind =是”> config.cache的
回声“libc_cv_c_cleanup =是” -构建»config.cache的
../../sources/gcc-4.3.3/configure的\ 

-目标= $ BUILDMACH = $ TARGETMACH \ 
的- prefix = $ INSTALLDIR \ 
-与SYSROOT = $ SYSROOTDIR \ 
-使语言
与GNU-LD C \ - \ 
- \ 
- 与GNU- 禁用的multilib \ 
-浮=软\ 
-禁用sjlj的例外\ 
-禁用NLS \ 
-启用的线程= POSIX 禁用libssp \ 
-禁用libmudflap的\ 
- \ 
-使长= longx \ 
-共享\ 
- GMP = $ INSTALLDIR \ 
- MPFR = $ INSTALLDIR 使安装



在目录:/ OPT /手臂/臂没有Linux的gnueabi / lib目录 交叉工具链是在目录/ opt /臂/ bin目录中 我们可以添加交叉工具链的可执行文件在环境变量PATH打字:出口PATH = $ INSTALLDIR / bin中:$ PATH 
键入可执行臂的第一个字母,然后按Tab键,我们现在有可执行文件的直接访问。

6)测试交叉工具链“从零开始”

做一个测试建立我们新安装的链。 我们将编译程序的Helloworld庆祝,只是在消息打印终端“世界你好”。 
在编译程序:

臂没有Linux的gnueabi-GCC-O的HelloWorld HelloWorld的。 Ç 

,我们可以使用命令行编译检查的文件类型:
文件的HelloWorld 

给:

历史:ELF 32位LSB的可执行文件,ARM,版本1(SYSV),动态链接(使用共享库),为GNU / Linux的2.6.16未剥离

好了,这个小测试告诉我们,生成可执行文件针对ARM架构。你现在是一个美丽的交叉工具链ARM为自己制造!diposez


 

原创粉丝点击