Install the embedded cross-compilation tool

Source: Internet
Author: User
Tags printable characters

1. Introduction to toolchain

Toolchain contains many components: GCC, which can be a native compilation tool or a cross-compilation tool. GCC is supported by binuitls and binutils is binary.
Code maintenance tools, which are essential for program compilation, also require the support of library C (glibc. Think about it: customizing a compilation tool is not as easy as you think! If you want to continue
To continue, you must have the following skills:

Familiar with Linux environment
Familiar with the use of necessary Linux commands and tools
Know how to configure, compile core and Application

The following sections describe how to customize the arm cross-compilation tool set. However, for most arm developers, there is no need to do this in person and they can use the ready-made tool set. Unless the ready-made toolsets do not meet your usage requirements, or you want to improve your application development capabilities. In short, we strongly recommend that you use a stable and ready-to-use tool set for application development!

2. Custom toolchain

First, let's take a look at the major steps:

Determine the target name
Determines the storage location of the target
Compile and install binutils
Compile and install gcc
Compile and install glibc
Enable the cross-compilation tool to support more compilation languages
Test customized cross-compilation tools

2.1 determine the target name

The Code Compiled by the native compilation toolset can only be run on the local machine (most PCs are x86). For arm developers, A set of cross-compilation tools that can be compiled locally but compiled to generate arm code.
Therefore, it is necessary to select a target name with a specific meaning different from the local tool set.

Arm-Linux: a popular name that supports the ELF format (armlinux standard ). Except that acorn users use the old A. Out format.

Arm-linuxaout: select the. Out format, which is basically not supported by armlinux.

Arm-Aout, arm-coff, arm-elf, and arm-thumb: other format names.

You can also insert version information, for example:

Armv2: armv2 core, supports 26bit mode.

Armv3l, armv3b: armv3 core, small byte (l) or large byte (B) mode.

Armv4l and armv4b: armv4 cores, such as Strongarm, ARM7TDMI, arm8, and ARM9. Also supports the small-byte (l) or large-byte (B) mode.

Armv5l and armv5b: armv5, for example, XScale arm10. Also supports the small-byte (l) or large-byte (B) mode.

Selecting a name does not have much impact on the customized arm cross-compilation tool set, but it is better to use a commonly used name.

2.2 determine the storage location of the target

Since it is a custom arm cross-compilation tool set, it cannot overwrite the compilation tool set of the Local Machine (otherwise, the local machine will no longer be able to compile the local code to run !), At the same time, we also need to consider the multi-user and multi-task features of the local Linux environment. Therefore, it is necessary to select a multi-user sharing location different from the local compilation toolset.

Storage location of the arm cross-compilation toolset: In this article, we make it equal to/usr/local/ARM
(The local compilation tool set is usually stored in/usr or/usr/local)

Name of the arm cross-compilation tool set: In this article, we make it equal to arm-PC-Linux, which indicates
And generates the arm command code (for detailed rules, see the README file of glibc ).
(The native compilation toolset name is usually: i686-pc-linux-gnu, indicating compilation on the local PC,
I686 command code is generated)

ARM core file location: In this article, we make it equal ~ /Armlinux. However ,~ /Armlinux only
It is a join and points to the true ARM core source code location (see Section 2.4.1 ).
(The local core is usually stored in/usr/src/Linux)

2.3. Compile and install binutils

It is one of the GNU (ftp://ftp.gnu.org) tools, mainly binary code processing maintenance tools.

2.3.1 Introduction to binutils tool components

Add2line: converts an address to a file name or line number pair for debugging.

AR: creates, modifies, and extends program code from the system file.

As: Generate assembler code.

C ++ filt: Establishes the names and symbols of low-level languages and user-level languages, and maintains their relationships.

Gasp: assembler macro processor.

Ld: connects the target code blocks to generate executable code.

NM: Enumerate all debugging Symbol names from the target code file.

Objcopy: Use the gnu bsd library to copy the target code from a file lattice to another type of lattice.

Objdump: displays the target file information.

Readelf: displays the ELF File Information.

Ranlib: generate an index to accelerate access to the archive file.

Size: list the code size of the target module or file.

Strings: prints printable characters of the target code (at least 4 characters. Pair
In other cells, print the string.

Strip: discard all symbolic joins.

2.3.2 binutils configuration and compilation and Installation

Tar-jxvf binutils-2.16.1.tar.bz2-C ~
Cd ~ Binutils-2.16.1

Make clean
Make distclean

./Configure -- target = arm-PC-Linux -- prefix =/usr/local/ARM

Make
Make install

If the installation is successful (normally there is no problem), go to the next step: gcc

2.4. Compile and install gcc

It is one of the GNU (ftp://ftp.gnu.org) tools, is the main compilation processing tool.

2.4.1 ARM core header file

For the compilation tool set on the local machine, the core header file is usually installed in/usr/src/Linux/include, or is copied to the search path by GCC. However, for ARM crossover
Compile the toolset, which may not have been installed before (unless it has been installed before. Therefore, we need to extract the core header file of arm. Here we use the core for at91rm9200
File linux-2.4.27-vrs1.tar.bz2
(If it is a general-purpose Core, you need a patch file for ARM)

Tar-jxvf linux-2.4.27-vrs1.tar.bz2-C ~
Cd ~
Ln-s linux-2.4.27-vrs1-ATMEL armlinux

Now, we have created :~ /Armlinux connection

Cd ~ /Armlinux
Vim makefile

Check the arch: = line. If it is not arm, change it to arch: = arm. Save and exit.

(Check cross_compile: =/usr/local/ARM/bin/ARM-PC-Linux-. If different, modify it)

Make clean
Make distclean

Make menuconfig

Configure the core (select "arm" as "at91rm9200" and other related configurations), save and exit.

Make Dep

(In case of an error, check if Part 1 has any answers !)

There must be an error and it will be terminated! Of course, we do not want to compile this core, but just straighten out the relationship between the core files so that the following copy operations can proceed smoothly ......

Mkdir/usr/local/ARM-PC-Linux/sys-include

CP-dr ~ /Armlinux/include/ASM-arm/usr/local/ARM-PC-Linux/sys-include/ASM

CP-dr ~ /Armlinux/include/Linux/usr/local/ARM-PC-Linux/sys-include/Linux

Now we have a public core header file that is cross-compiled by arm.

2.4.2 configure, compile, and install gcc

Read the files in the GCC source code install directory for more configuration and compilation and installation help.

To use the previously compiled binutils tool, add a path.

Export Path = $ path:/usr/local/ARM/bin
(This step is omitted if/usr/local/ARM/bin is already included in path)

Tar-jxvf gcc-3.4.5.tar.bz2-C ~

Cd ~ Gcc-3.4.5

2.4.3 first install the arm cross-compilation tool gcc

(Read the files in the GCC source code install directory for more configuration, compilation, and installation help)

The entire process cannot be completed because the following factors must be taken into account:

Since it is the first time to install the arm cross-compilation tool, glibc on this machine should support the native compilation tool library instead of the arm cross-compilation tool library. Supports arm cross-Compilation
The libc library of other Supported languages (such as C ++ and Java) of the tool (the final connection to the binary code generated by GCC requires the support of this library) is not available either, to add the compilation switch:
-- Enable-versions ages = c -- disable-threads -- disable-shared
Likewise, because the arm cross-compilation tool is installed for the first time, the header files of the libc library are not supported! Therefore, we need to use dinhibit_libc for hack (this word is only intended and cannot be said. The procedure is as follows:

CP ~ /Gcc-3.4.5/GCC/config/ARM/t-Linux ~ /Gcc-3.4.5/GCC/config/ARM/t-linux.orig

Vim ~ /Gcc-3.4.5/GCC/config/ARM/t-Linux
Add operation parameters to target_libgcc2_cflags =
-Dinhibit_libc-D _ gthr_posix_h
Save and exit.

Let's reconfigure and compile it ......

Export Path = $ path:/usr/local/ARM/bin
(This step is omitted if/usr/local/ARM/bin is already included in path)

Cd ~ Gcc-3.4.5

Make clean
Make distclean

./Configure -- target = arm-PC-Linux
-- Prefix =/usr/local/arm -- disable-threads -- disable-shared -- enable-versions ages = C

(Since we copied the cross-compiled header file to the default sys-include directory of GCC, we do not need to define the -- with-headers parameter. In actual tests, the definition of -- With-headers is not allowed to pass the make statement, and the bug is unknown)

Make
(Painful bug Removal Process !)
(In case of an error, check whether there are any answers in Part 1. We strongly recommend that you start from make clean !)

Make install

If the installation is successful, we will have the arm cross-compilation tool GCC that can compile C language. If you just use the arm cross-compilation tool to compile the ARM core, OK! You can stop it. If you want to compile user-level code, continue to the next stage ......

2.5. Compile and install glibc.

Glibc is a C library, and almost all applications need to share the functions it provides (except for the kernel, bootload, and other functional code that does not need the C library at all). Therefore, glibc
There are benefits for small systems or embedded systems to reduce the total size and storage space of the system code (although a single glibc library is relatively large ). Therefore, the final task is to construct an arm cross-compilation system.
Glibc library.

2.5.1 decompress the source code

First decompress the glibc code, and then decompress the linuxthreads code to the glibc code source code directory ......

Tar-jxvf glibc-2.3.6.tar.bz2-C ~
Tar-jxvf glibc-linuxthreads-2.3.6.tar.bz2-C ~ Glibc-2.3.6

2.5.2 configure, compile, and install glibc

Read the files in glibc source code: README, FAQ, and install for more configuration, compilation, and installation help.

Export Path = $ path:/usr/local/ARM/bin
(This step is omitted if/usr/local/ARM/bin is already included in path)

Export cc = arm-PC-Linux-gcc
(Define to compile with the just-generated arm cross-compilation tool. Otherwise, the generated glibc library is the local machine code library, not the arm Instruction Set code library !!!)

Warning: cannot operate in the source code directory (why? Ask GNU. I don't know either !)......

Mkdir ~ /Temp
Cd ~ /Temp

Make clean
Make distclean

~ /Glibc-2.3.6/configure
-- Host = arm-PC-Linux -- Build = i686-pc-linux-gnu -- With-headers =/usr/local/ARM-PC-Linux/sys-include -- enable-add-ons = linuxthreads -- enable-shared -- prefix =/usr/local/ARM-PC-Linux

(You may notice that the -- prefix value of glibc is different from that of GCC! Yes, you must define it like this. Otherwise, the GCC make process will end incorrectly because the public header file or library of glibc cannot be found !)

Make
(Painful bug Removal Process !)
(In case of an error, check whether there are any answers in Part 1. We strongly recommend that you start from make clean !)

Make install

2.6 enable the cross-compilation tool to support more compilation languages

Even though the C compiler of the Cross-compilation tool is completed, programs in Ada, C ++, f77, Java, objc, and other languages cannot be compiled.

2.6.1. Rebuild GCC with the existing cross-compilation tool

As we now have the basic C cross-compilation tool, it will not be subject to the constraints described in 2.4.3. Let's reconstruct GCC ......

Export Path = $ path:/usr/local/ARM/bin
(This step is omitted if/usr/local/ARM/bin is already included in path)

Export-N CC
(Clear the CC environment variables and use the local default compiler. Otherwise, the re-generated cross-compilation tool GCC cannot run on the local machine !!!)

Restore the T-Linux File Modified previously (Step 2.4.3:
CP ~ Gcc-3.4.5/GCC/config/ARM/t-linux.orig ~ /Gcc-3.4.5/GCC/config/ARM/t-Linux

Cd ~ Gcc-3.4.5

Make clean
Make distclean

If you need to support all programming languages allowed by GCC (niu ba), use the following Configuration:
./Configure -- target = arm-PC-Linux
-- Prefix =/usr/local/ARM-host = i686-pc-linux-gnu -- enable-threads = POSIX

If you only need GCC to support C and C ++ programming languages (reduce space usage), use the following Configuration:
./Configure -- target = arm-PC-Linux
-- Prefix =/usr/local/arm -- Host = i686-pc-linux-gnu -- enable-threads = POSIX -- enable-languages ages = C, C ++

Make
(Boil water, make tea, wait patiently !)

Make install

2.6.2. Re-construct glibc with a complete cross-compilation tool

Repeat steps 2.5.2, which is simple! (Continue drinking tea !)

2.7. Test customized cross-compilation tools

Write your own Hello word! C program (you won't write it)... for example: Hello. c

Export Path = $ path:/usr/local/ARM/bin
(This step is omitted if/usr/local/ARM/bin is already included in path)

Arm-PC-Linux-gcc-O2-O hello-c.arm hello. c

Run the compiled program:

/Hello-c.arm
Error message: cannot execute binary file

Oh! Forget to run it in the arm system environment ...... copy the file to the USB flash drive and attach it to the at91rm9200 system board (the system board runs Linux, but what is the $ money system like wince !),
Run the hello-c.arm, Super Terminal --- finally saw a long-time violation:

Hello word!

(Congratulations! A generation of masters can wait for a while ......)

**************************************** *******************************

3. What should I do if I encounter a problem?

The following are my problems encountered during the above steps for your reference. The record is as follows:

========================================================== ====================================
Q: When you use make Dep (or make) ARM core, the error message is as follows:
C0: Error: Invalid option 'short-load-bytes'

A: Reference http://gcc.gnu.org/ml/gcc-patches/1999-11n/msg00649.html
The gcc-3.x.x does not support-mshort-load-bytes, instead of-malignment-traps.

CP ~ /Armlinux/ARCH/ARM/makefile ~ /Armlinux/ARCH/ARM/makefile. orig

Modify the ARM core file ARCH/ARM/makefile and replace-mshort-load-bytes with-malignment-traps.

========================================================== ====================================

Q: When glibc is compiled, the system prompts that the core version is too old and earlier than 2.0.10.

A: If you are sure that the header file you copied to sys-include is higher than 2.0.10, for example, 2.4.27-vrs1 is used in this article, this error is also prompted,

CP/usr/local/ARM-PC-Linux/sys-include/Linux/version. h/usr/local/ARM-PC-Linux/sys-include/Linux/version. h. orig

Modify the file versions. H, replace # define uts_release "2.4.27-vrs1"
# Define uts_release "2.4.27"

========================================================== ====================================
Q: The glibc compilation error is as follows:
Error: 'bus _ ISA 'undeclared

A: Reference http://www.ussg.iu.edu/hypermail/linux/kernel/0311.0/0529.html
The core of kernel-2.4.23 or above should replace bus_isa with ctl_bus_isa,

CP ~ /Glibc-2.3.6/sysdeps/Unix/sysv/Linux/ARM/ioperm. C ~ /Glibc-2.3.6/sysdeps/Unix/sysv/Linux/ARM/ioperm. C. orig

Therefore, modify the file sysdeps/Unix/sysv/Linux/ARM/ioperm. c In the glibc source code to replace bus_isa with ctl_bus_isa.

========================================================== ====================================
Q: The glibc compilation error is as follows:
Ld: cannot find-lgcc_eh

A: Reference http://kegel.com/crosstool/crosstool-0.38/patches/glibc-20040822/glibc-2.3.3-libeh-kludge.patch

CP ~ /Glibc-2.3.6/makeconfig ~ /Glibc-2.3.6/makeconfig. orig

Modify the makeconfig file in the glibc source code.

# Gnulib: =-lgcc $ (libgcc_eh) # static-gnulib: =-lgcc-lgcc_eh $ (libunwind)
Changed to: gnulib: =-lgccstatic-gnulib: =-lgcc
========================================================== ====================================
Q: The glibc compilation error is as follows:
../Sysdeps/generic/s_fmax.c: 28: Internal compiler error: In elim_reg_cond, at flow. C: 3273

A: Reference http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc
/Flow. C. diff? Cvsroot = GCC & only_with_tag = CSL-arm-branch & R1 = 1.563.4.2 & r2 = 1.563.4.3
The problem comes from the internal GCC, CP ~ /Gcc-3.4.5/GCC/flow. C ~ /Gcc-3.4.5/GCC/flow. C. orig
Modify the GCC source code ~ /Gcc-3.4.5/GCC/flow. c file, recompile and install arm-PC-Linux-gcc
(Start step 2.4.3 again !)

========================================================== ====================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.