Build an arm-Linux cross-compiling environment on Ubuntu 9.10

Source: Internet
Author: User
Tags gcov gmp

 

I. Preface

Anyone who has learned about ARM embedded knows that in order to make the PC program run on the ARM board, a cross-compilation environment must be established to compile the source code. I will not talk about the basic concepts of the Cross-compilation environment. Here, I mainly write the steps and ideas for creating a cross-compilation environment.

My setup process went through four crazy days. In these four days, I sat in front of my computer almost all the time except for sleeping, eating, and going to the toilet, just for the last 100 MB of files. I finally realized the sense of helplessness in the face of complicated problems. Finally, I realized the capabilities and mentality I wanted to be a free software supporter (that is, how to find a solution in the face of difficulties and errors ).

It is hard to learn embedded Linux, especially DIY. In order to build a cross-compilation environment, I spent four days to get the result. It seems that there are no more than 100 MB files, but the time cost is huge. I did nothing in the past few days, and all my classes were skipped. One of my classmates even sent a text message asking me if I had disappeared? _? Hey, of course I didn't disappear. I just hid in my bedroom and compiled the files on my computer. This is the trouble of free software. The dependency between files is complex and cumbersome. Beginners do not know what the contact between their files is. I do not know the cause of an error following the steps on the Internet. There are always some strange errors during compilation. What should I do if I have any errors? Check the Internet, read the README documents, read the standards, and go to the BBS to ask if there are any websites in China, you have to go to a foreign website to check it. Some errors are common, and there are solutions. There are hundreds of errors that I cannot try one by one. Even two times I have compiled errors that do not exist on the network, I was dizzy. Sometimes the compilation is not always complete, so I will delete all the files and re-execute them. In this way, I do not know how many times there are. No wonder some people say that the cross-compilation environment depends on luck.

But fortunately, I found a new build step in a foreign website with a high pass rate and no major error. Next we will go to the topic and write down my establishment process.

2. Prepare documents

My computer is installed with Ubuntu 9.10 Linux, not a virtual machine. To build a cross-compilation environment, first you have a compilation environment in your computer, which is common, such as GCC. I don't want to write this, and there are many online websites, which are too common.

Then, we need to download the required file. Here is the list:

Source code files and their versions and:

Binutils-2.19.1.tar.bz2 http://ftp.gnu.org/gnu/binutils/
Gcc-4.3.3.tar.bz2 http://ftp.gnu.org/gnu/gcc/gcc-4.3.3/

Glibc-2.11.tar.bz2 http://ftp.gnu.org/gnu/glibc/
Glibc-ports-2.11.tar.bz2 http://ftp.gnu.org/gnu/glibc/
Gmp-4.2.4.tar.bz2 http://ftp.gnu.org/pub/gnu/gmp/
Linux-2.6.30.1.tar.bz2 http://ftp.kernel.org/pub/linux/kernel/v2.6/
Mpfr-2.4.1.tar.bz2 http://www.mpfr.org/mpfr-2.4.1/
Patch package version and:

Binutils-2.19.1-branch_update-1.patch

Http://ftp.crosslfs.org/pub/clfs/conglomeration/binutils/
Binutils-2.19.1-posix-1.patch

Http://ftp.cross-lfs.org/pub/clfs/conglomeration/binutils/
Gcc-4.3.3-branch_update-5.patch

Http://ftp.lfs-matrix.net/pub/clfs/conglomeration/gcc/
Gcc-4.3.3-posix-1.patch

Http://ftp.lfs-matrix.net/pub/clfs/conglomeration/gcc/
Gcc_eh.patch.cross

Http://svn.exactcode.de/t2/trunk/package/base/glibc/gcc_eh.patch.cross
Mpfr-2.4.1-branch_update-1.patch

Http://cross-lfs.org/files/packages/embedded-0.0.1/
Mpfr-2.4.1-branch_update-2.patch

Http://cross-lfs.org/files/packages/embedded-0.0.1/

Note: 1. version requirements: At the beginning, many people will choose the latest version of each source code. In fact, this is not necessary or good. First, your board does not necessarily support such a new source code. Second, because new items will be added to the new version, an error will occur when you compile based on the original method, but you don't know where the error is. This is very troublesome. I am suffering from this loss. So when you are a new employee, try to select the version of the successful online example, this will reduce the probability of errors. Of course, for example, if you are a master or have some knowledge about the compilation process of various source codes in Linux, that's an exception.

2. patch method: the patch method is very simple. first enter the folder you want to patch, and then execute patch-P1 <path/to/your patch document (that is, the path of your patch file, note that there are spaces before and after "<"), for example:

$ Binutils-2.19.1 CD

$ Patch-P1

If you want to learn more please see: http://www.diybl.com/course/6_system/linux/Linuxjs/2008826/137710.html

Then we start to create a file directory:

/Home/yourname/ARM/-- build/* directory where the source code is stored/-- binutils/* binary file

| -- Gcc/* Compiler

| -- Glibc/* C library file

| -- Linux-kernel/* directory for storing the kernel

| -- Cross-compile/* tool installation directory

After the directory is established, the various source code files into the corresponding folder, then ../build/binutilsshould have binutils-2.19.1.tar.bz2, binutils-2.19.1-branch_update-1.patch, binutils-2.19.1-posix-1.patch. /Build/GCC should have gcc-4.3.3.tar.bz2,gmp-4.2.4.tar.bz2, mpfr-2.4.1.tar.bz2, gcc-4.3.3-branch_update-5.patch, gcc-4.3.3-posix-1.patch, mpfr-2.4.1-branch_update-1.patch. Glibc-2.11.tar.bz2,glibc-ports-2.11.tar.bz2 and gcc_eh.patch.cross should be included in build/glibc. Linux-kernelshould contain linux-2.6.30.1.tar.bz2

Next, extract the files and patch them accordingly. Then, rename the gmp-4.2.4 GMP and mpfr-2.4.1 mpfr into the gcc-4.3.3 folder. Rename the glibc-ports-2.11 to ports in the glibc-2.11.

For Ubuntu users, there is a tool called mawk. I don't know what it is for, but it is not good for the establishment of a cross-compilation environment. It should be replaced with gawk. The specific method can be Google.

So far, all file preparation has been completed.

Iii. binutils)

Create environment variables:

$ Vim ~ /. Add the following code to bashrc first:

Export prjroot =/home/yourname/ARM

Export prefix = $ prjroot/cross-compile
Export $ target = arm-Linux
Export Path = $ prefix/tools/bin: $ path
Export host = i486-cross-linux-gnu

Then run

$ CD/home/youname/ARM/build/binutils

$ Mkdir B

$ CD B

$ AR = Ar as = As ../binutils-2.19.1/configure/

-- Build = i486-cross-linux-gnu/

-- Host = i486-cross-linux-gnu/

-- Target = $ target/

-- Prefix = $ prefix/tools/

-- With-sysroot = $ prefix/

-- Disable-NLS -- enable-shared -- disable-multilib -- disable-werror note: "/" cannot be saved with leading Spaces

$ Make all

$ Make install

Let's take a look at what files generated under $ prefix/tools/bin are used.

Add2line-convert the address you are looking for into a file and a line number. It uses the debug information.

Ar-generate, modify, and unlock an archive file

As-GNU assembler C ++ Filt-C ++ and Java have a type of overload function. The used overload function will be compiled and converted to the Assembly label, c ++ filt is to implement this inverse conversion, and obtain the function name based on the number.

Gasp-GNU Compiler pre-compiler.

LD-GNU connector nm-list the symbols of the target file and the corresponding address objcopy-convert a target file of a certain format into a target file of another format objdump-display the information of the target file

Ranlib-generates an index for an archive file and stores the index in the archive file.

Readelf-display the information of the target file in ELF format

Size-displays the size of each section of the target file and the size of the target file.

Strings-print the printable strings in the target file. The default length is 4.

Strip-strip all the symbolic information of the target file

4. Create a kernel header file (Linux kernel)

$ CD $ prjroot/Linux-kernel/linux-2.6.30.1

$ Mkdir-p $ prefix/usr/include

$ Make mrproper

$ Make arch = arm headers_check

$ Make arch = arm install_hdr_path = DEST headers_install

$ CP-rv dest/include/* $ prefix/usr/include

$ Find $ prefix/usr/include-name. Install-or-name .. install. CMD | xargs Rm-FV

V. Build an initial Compiler (bootstrap GCC)

$ CD $ prjroot/build/GCC

$ Mkdir g

$ CD g

$ AR = ar ldflags = "-wl,-rpath, $ prefix/lib "/

/Home/Polaris/ARM/build/GCC/gcc-4.3.3/configure/

-- Build = i486-cross-linux-gnu/

-- Host = i486-cross-linux-gnu/

-- Target = arm-Linux/

-- Prefix $ prefix/tools/

-- Enable-languages ages = C/

-- Disable-NLS -- disable-shared -- disable-threads/

-- Disable-libmudflap -- disable-libssp -- disable-libgomp/

-- Disable-Decimal-float -- without-headers -- With-newlib/

-- With-sysroot = $ prefix

$ Make

$ Make install

Let's take a look at what is added to $ prefix/bin. You will find several files including arm-Linux-GCC, arm-Linux-unprotoize, CPP, and gcov.

Gcc-gnu c language compiler

Unprotoize-convert the source code of ansi c to K & r c and remove the parameter types in the function prototype.

CPP-gnu c pre-Compiler

Gcov-GCC's auxiliary testing tool, which can be used for analysis and optimization.

6. Create a C library (glibc) 

$ CD $ prjroot/build/glibc

$ Mkdir g

$ CD g

$ Echo "libc_cv_forced_unwind = yes"> config. Cache/

Echo "libc_cv_c_cleanup = yes"> config. cache/

Echo "libc_cv_arm_tls = yes"> config. cache

$ BUILD_CC = "gcc" CC = arm-linux-gcc AR = arm-linux-ar RANLIB = arm-linux-ranlib

$ PRJROOT/build/glibc/glibc-2.11/configure/

-- Build = i486-cross-linux-gnu/

-- Host = arm-linux/

-- Target = arm-linux/

-- Prefix = $ PREFIX/usr/

-- With-tls -- disable-profile -- enable-add-ons/

-- Enable-kernel = 2.6.0 -- with-_ thread/

-- With-binutils = $ PREFIX/tools/bin/

-- With-headers = $ PREFIX/usr/include/

-- Cache-file = config. cache

$ Make all

$ Make install

Then you need to modify the libc. so file and change GROUP (/lib/libc. so.6/lib/libc_nonshared.a)
Group (libc. so.6 libc_nonshared.a) then the Connection Program LD will be in libc. the directory where so is located looks for the library it requires, because the/lib directory of your machine may have installed a library with the same name, A library for compiling programs that can run on your host machine, rather than for cross-compilation.

7. Create a full set of compilers (full GCC)

We only support C when creating boot-GCC. Here, we need to build a full set of compilers to support C and C ++.

$ CD $ prjroot/build/GCC

$ Mkdir G1

$ CD G1

$/Home/Polaris/ARM/build/GCC/gcc-4.3.3/configure/

-- Build = i486-cross-linux-gnu/

-- Host = i486-cross-linux-gnu/

-- Target = arm-Linux/

-- Prefix = $ prefix/tools/

-- Enable-languages ages = C, C ++ -- enable-c99/

-- Enable-threads = POSIX -- enable-Long-long -- enable-shared/

-- Enable-_ cxa_atexit -- disable-multilib -- disable-NLS -- disable-libgomp/

-- With-sysroot = $ prefix

$ Make

$ Make install

Let's take a look at what is added to $ prefix/bin. You will find multiple files, including arm-Linux-G ++, arm-Linux-protoize, and arm-Linux-C ++.

G ++-gnu c ++ compiler.

Protoize-opposite to unprotoize, convert the source code of K & r c to ansi c, and add the parameter type to the function prototype.

C ++-gnu c ++ compiler.

So far, the entire cross-compilation environment has been established.

8. Test)

Write a hello World program to test your cross-compilation environment

$ Vim hello. c

# Include <stdio. h>

Int main ()

{

Printf ("Hello world! /N ");

Return 0;

}

$ Arm-Linux-GCC hello. C-O hello

$ File hello

Hello: Elf 32-bit LSB executable, arm, Version 1, dynamically linked (uses SHARED libs), not stripped

The above output indicates that you have compiled a helloworld that can be run under the ARM architecture, proving that your compilation tool has been successful!

9. Descending Order

The above is my setup process, because the computer configuration in each person's hands is different and the Linux internal environment settings are different, this step may not be correct. Therefore, this article serves only as a reference. During the establishment process, we need to use a network to find a solution to the problem, so as to establish a complete cross-compilation environment. If any error occurs in this article, please forgive me!

10. References

1. http://blog.chinaunix.net/u2/60303/showart_2159276.html of "self-experiment build cross-compilation tool chain"

2. http://www.ibm.com/developerworks/cn/linux/l-embcmpl/ on how to build a cross-compiling environment for Embedded Development

 

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.