Create an arm cross-compiling environment in ubuntu10.04

Source: Internet
Author: User
Tags gcov gmp
Create an arm cross-compiling environment in ubuntu10.04

 

In Linux, the overall process of creating the entire arm cross-compiling environment is as follows:

1. Download the source file

2. Create a compiling directory in Linux and set Environment Variables

3. Create a kernel header file

4. binutils)

5. Create an initial Compiler (bootstrap GCC)

6. Create a glibc Library

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

8. Verify the Compiler

 

 

1. Download source files

All GNU source code files can be downloaded at this address: http://ftp.gnu.org/gnu/

Linux kernel source code can be downloaded here: http://www.kernel.org

PC can go here download: http://www.multiprecision.org

The source code package I downloaded is as follows:

Binutils-2.21.1.tar.bz2

Gcc-4.6.1.tar.gz

Glibc-2.14.tar.gz

Glibc-linuxthreads-2.5.tar.bz2

Glibc-ports-2.13.tar.gz

Gmp-5.0.2.tar.bz2

Linux-2.6.32.45.tar.gz

Mpc-0.9.tar.gz

Mpfr-2.4.2.tar.gz

Note: version 3.0.0 is not recommended for mpfr. There is a bug in the mpfr-3.0.0 that will cause GCC compilation to fail.

 

 

2. Create a compiling directory in Linux and set Environment Variables

Select your working directory, for example,/home/embedded as your working directory. Then, create the build-tools, kernel, and tools folders in embedded. Instance:

Root @ Ubuntu:/home/huchao # cd/home/

Root @ Ubuntu:/home # mkdir embedded

Root @ Ubuntu:/home # cd embedded/

Root @ Ubuntu:/home/Embedded # mkdir build-tools kernel tools

Root @ Ubuntu:/home/Embedded # cd build-tools/

Root @ Ubuntu:/home/Embedded/build-tools # mkdir build-binutils build-boot-GCC build-glibc build-gcc

Each folder has the following functions:

/Home/Embedded: main directory of the Cross-compiling environment

/Home/Embedded/build-tools: stores GNU source codes such as binutils, GCC, and glibc and directories used to compile these source codes.

/Home/Embedded/kernel: used to store the Linux kernel source code

/Home/Embedded/tools: used to store compiled cross-compilation tools and library files

/Home/Embedded/build-tools/build-binutils: directory for compiling binutils

/Home/Embedded/build-tools/build-boot-GCC: directory for compiling the GCC startup part

/Home/Embedded/build-tools/build-glibc: directory for compiling glibc

/Home/Embedded/build-tools/build-GCC: Compile the entire GCC directory

 

After creating the compiled directory, you can set the environment variable (we recommend that you directly go ~ /. Modify it in bashrc. Run terminal again after modification ). As follows:

Export prjroot =/home/embedded

Export target = arm-Linux

Export prefix = $ prjroot/tools

Export target_prefix = $ prefix/$ Target

Export Path = $ prefix/bin: $ path

The meanings of environment variables are as follows:

Prjroot: root directory of the entire cross-compilation environment

Target: The architecture corresponding to the target file. Arm-Linux indicates that the compiled target can only be run in ARM architecture.

Prefix: The Path prefix of the target folder.

Target_prefix: path prefix of the target folder

Path: Specifies the executable file path, which mainly specifies the compilation tool.

 

 

3. Create a kernel header file

Extract the Linux kernel source code to the $ prjroot/kernel directory, Create Symbolic Links to several files, and generate a version. h file. Instance:

First, extract the Linux kernel source file.

Root @ Ubuntu:/home/Embedded/kernel # cp/mnt/HGFS/vmwareshare_ubuntux64/linux-2.6.32.45.tar.gz.

Root @ Ubuntu:/home/Embedded/kernel # tar-xvf linux-2.6.32.45.tar.gz

Root @ Ubuntu:/home/Embedded/kernel # mkdir/home/Embedded/tools/ARM-Linux

Root @ Ubuntu:/home/Embedded/kernel # mkdir/home/Embedded/tools/ARM-Linux/include

Root @ Ubuntu:/home/Embedded/kernel # ln-S/home/Embedded/kernel/linux-2.6.32.45/include/Linux/home/Embedded/tools/ARM-Linux/include/Linux

Root @ Ubuntu: /home/Embedded/kernel # ln-S/home/Embedded/kernel/linux-2.6.32.45/include/ASM-generic/home/Embedded/tools/ARM-Linux/include/ASM-generic

Root @ Ubuntu: /home/Embedded/kernel # ln-S/home/Embedded/kernel/linux-2.6.32.45/ARCH/ARM/include/ASM/home/Embedded/tools/ARM-Linux/include/ASM

Check whether the created symbolic link is correct. Instance:

Root @ Ubuntu:/home/Embedded/kernel # cd/home/Embedded/tools/ARM-Linux/include/

Root @ Ubuntu:/home/Embedded/tools/ARM-Linux/include # ll

Total usage 8

Drwxr-XR-x 2 root Root 4096 ./

Drwxr-XR-x 3 Root 4096 ../

Lrwxrwxrwx 1 Root 58 ASM->/home/Embedded/kernel/linux-2.6.32.45/ARCH/ARM/include/ASM/

Lrwxrwxrwx 1 Root 57 2011-09-29 05:10 ASM-generic->/home/Embedded/kernel/linux-2.6.32.45/include/ASM-generic/

Lrwxrwxrwx 1 Root 51 2011-09-29 05:09 Linux->/home/Embedded/kernel/linux-2.6.32.45/include/Linux/

The above result indicates that the symbolic link is correctly created.

 

Finally, generate the version. h file. Instance:

Root @ Ubuntu:/home/Embedded/kernel/linux-2.6.32.45 # cd/home/Embedded/kernel/linux-2.6.32.45/

Root @ Ubuntu:/home/Embedded/kernel/linux-2.6.32.45 # Make include/Linux/version. h

Chk include/Linux/version. h

UPD include/Linux/version. h

Check whether the version. h file is successfully created. Instance:

Root @ Ubuntu:/home/Embedded/kernel/linux-2.6.32.45 # cd/home/Embedded/kernel/linux-2.6.32.45/include/Linux/

Root @ Ubuntu:/home/Embedded/kernel/linux-2.6.32.45/include/Linux # ll | grep version. h

-RW-r -- 1 Root 97 2011-09-29 05:14 version. h

If the above result is displayed, the version. h file is successfully created.

 

 

4. binutils)

Binutils is a collection of binary tools, including common commands. First, decompress binutils-2.21.1.tar.bz2 to build-tools, enter the build-binutils directory, configure and compile binutils, and then install binutils using make install. Instance:

Root @ Ubuntu:/home/Embedded/build-tools # cd/home/Embedded/build-tools/

Root @ Ubuntu:/home/Embedded/build-tools # cp/mnt/HGFS/vmwareshare_ubuntux64/binutils-2.21.1.tar.bz2.

Root @ Ubuntu:/home/Embedded/build-tools # tar-xjf binutils-2.21.1.tar.bz2

Root @ Ubuntu:/home/Embedded/build-tools # cd build-binutils/

Root @ Ubuntu:/home/Embedded/build-tools/build-binutils # ../binutils-2.21.1/configure -- target = $ target -- prefix = $ prefix

Root @ Ubuntu:/home/Embedded/build-tools/build-binutils # Make

Root @ Ubuntu:/home/Embedded/build-tools/build-binutils # make install

After that, check the generated Tool in $ prefix. Instance:

Root @ Ubuntu:/home/Embedded/build-tools/build-binutils # cd/home/Embedded/tools/bin

Root @ Ubuntu:/home/Embedded/tools/bin # ll

Total usage 49988

Drwxr-XR-x 2 root Root 4096 ./

Drwxr-XR-x 6 Root 4096 ../

-Rwxr-XR-x 1 Root 3009029 arm-linux-addr2line *

-Rwxr-XR-x 2 root Root 3161667 arm-Linux-ar *

-Rwxr-XR-x 2 root Root 4789065 arm-Linux-*

-Rwxr-XR-x 1 Root 2981965 arm-Linux-C ++ filt *

-Rwxr-XR-x 1 Root 77829 arm-Linux-elfedit *

-Rwxr-XR-x 1 Root 3456392 arm-Linux-GPROF *

-Rwxr-XR-x 4 Root 4502054 arm-Linux-LD *

-Rwxr-XR-x 4 Root 4502054 arm-linux-ld.bfd *

-Rwxr-XR-x 2 root Root 3048986 arm-Linux-Nm *

-Rwxr-XR-x 2 root Root 3710926 arm-Linux-objcopy *

-Rwxr-XR-x 2 root Root 4176150 arm-Linux-objdump *

-Rwxr-XR-x 2 root Root 3161666 arm-Linux-ranlib *

-Rwxr-XR-x 1 Root 807601 arm-Linux-readelf *

-Rwxr-XR-x 1 Root 3036038 arm-Linux-size *

-Rwxr-XR-x 1 Root 3010718 arm-Linux-strings *

-Rwxr-XR-x 2 root Root 3710917 arm-Linux-strip *

 

The functions of these generated files are as follows:

Arm-linux-addr2line: Convert the address you are looking for into a file and a line number, which uses debug information

Arm-Linux-AR: Generate, modify, and unlock an archive file

Arm-Linux-as: GNU Assembler

Arm-Linux-C ++ filt: there is a type of overload function in C ++ and Java. The overload function used will be compiled and converted to the Assembly mark, c ++ filt is used to implement this reverse conversion. The function name is obtained based on the number.

Arm-Linux-elfedit: Unknown Purpose

Arm-Linux-GPROF: GNU Compiler pre-Compiler

Arm-Linux-ld: GNU Connector

Arm-linux-ld.bfd: usage temporarily unknown

Arm-Linux-NM: list the symbols and corresponding addresses of the target file.

Arm-Linux-objcopy: converts a target file of a certain format into a target file of another format.

Arm-Linux-objdump: displays information about the target file.

Arm-Linux-ranlib: generates an index for an archive file and stores the index in the archive file.

Arm-Linux-readelf: displays information about the target file in ELF format.

Arm-Linux-size: displays the size of each section of the target file and the size of the target file.

Arm-Linux-strings: prints the strings that can be printed in the target file. The default length is 4.

Arm-Linux-Strip: removes all symbolic information from the target file.

 

 

V. Build an initial Compiler (bootstrap GCC)

GCC is the main compiler. Unzip them to the directory where the GCC source code is located, rename the directory to GMP, mpfr, and MPC, and then enter the build-boot-GCC directory for compilation and configuration, then make all-GCC and install it. Then make all-target-GCC and install it. Instance:

Root @ Ubuntu:/home/Embedded/build-tools # cd/home/Embedded/build-tools/

Root @ Ubuntu:/home/Embedded/build-tools # cp/mnt/HGFS/vmwareshare_ubuntux64/gcc-4.6.1.tar.gz.

Root @ Ubuntu:/home/Embedded/build-tools # tar-xvf gcc-4.6.1.tar.gz

Root @ Ubuntu:/home/Embedded/build-tools # gcc-4.6.1/CD/

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # cp/mnt/HGFS/vmwareshare_ubuntux64/mpfr-2.4.2.tar.gz.

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # cp/mnt/HGFS/vmwareshare_ubuntux64/gmp-5.0.2.tar.bz2.

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # cp/mnt/HGFS/vmwareshare_ubuntux64/mpc-0.9.tar.gz.

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # tar-xvf mpfr-2.4.2.tar.gz

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # mv mpfr-2.4.2/mpfr

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # tar-xjf gmp-5.0.2.tar.bz2

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # mv gmp-5.0.2/GMP

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # tar-xvf mpc-0.9.tar.gz

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # mv mpc-0.9 MCM

 

Here you need to modify the compilation configuration file:/home/Embedded/build-tools/gcc-4.6.1/GCC/config/ARM/t-Linux

Change "target_libgcc2_cflags =-fomit-frame-pointer-FPIC" to "TARGET_LIBGCC2-CFLAGS =-fomit-frame-pointer-FPIC-dinhibit_libc-D _ gthr_posix_h ".

Then you can switch to the Build-boot-GCC directory for compilation. Example:

Root @ Ubuntu:/home/Embedded/build-tools/gcc-4.6.1 # cd/home/Embedded/build-tools/build-boot-gcc/

Root @ Ubuntu:/home/Embedded/build-tools/build-boot-GCC #.. /gcc-4.6.1/configure -- target = $ target -- prefix = $ prefix -- without-headers -- enable-classes ages = c -- disable-threads -- With-newlib -- disable-shared -- disable-libmudflap -- disable-libssp

Root @ Ubuntu:/home/Embedded/build-tools/build-boot-GCC # Make all-gcc

Root @ Ubuntu:/home/Embedded/build-tools/build-boot-GCC # make install-gcc

Root @ Ubuntu:/home/Embedded/build-tools/build-boot-GCC # Make all-target-libgcc

Root @ Ubuntu:/home/Embedded/build-tools/build-boot-GCC # make install-target-libgcc

 

After completion, several more files are added under $ prefix/bin:

-Rwxr-XR-x 1 Root 864105 arm-Linux-CPP *

-Rwxr-XR-x 2 root Root 854850 arm-Linux-GCC *

-Rwxr-XR-x 2 root Root 854850 arm-linux-gcc-4.6.1 *

-Rwxr-XR-x 1 Root 126539 arm-Linux-gcov *

The functions of these generated files are as follows:

Arm-Linux-CPP: Pre-compiler of GNU C

Arm-Linux-GCC: C language compiler of GNU

Arm-linux-gcc-4.6.1: gnu c language compiler, in fact, and arm-Linux-GCC is the same

Arm-Linux-gcov: an auxiliary testing tool for GCC to analyze and optimize programs.

 

 

6. Create a glic Library

Glibc is the Runtime Library of the Cross-compiling environment. Unzip to the directory where the glibc source code is located and rename it to ports. Go to the Build-glibc folder, create the config. cache file for glibc configuration, configure and compile glibc, install glibc, and modify libc. So. Instance:

Root @ Ubuntu:/home/Embedded/build-tools # cd/home/Embedded/build-tools/

Root @ Ubuntu:/home/Embedded/build-tools # cp/mnt/HGFS/vmwareshare_ubuntux64/glibc-2.14.tar.gz.

Root @ Ubuntu:/home/Embedded/build-tools # tar-xvf glibc-2.14.tar.gz

Root @ Ubuntu:/home/Embedded/build-tools # glibc-2.14/CD/

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # cp/mnt/HGFS/vmwareshare_ubuntux64/glibc-linuxthreads-2.5.tar.bz2.

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # tar-xjf glibc-linuxthreads-2.5.tar.bz2

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # cp/mnt/HGFS/vmwareshare_ubuntux64/glibc-ports-2.13.tar.gz.

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # tar-xvf glibc-ports-2.13.tar.gz

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # mv glibc-ports-2.13/Ports

Root @ Ubuntu:/home/Embedded/build-tools/glibc-2.14 # CD ../build-glibc/

Create a config. cache file for glibc configuration. The file content is:

Libc_cv_forced_unwind = Yes

Libc_cv_c_cleanup = Yes

Libc_cv_arm_tls = Yes

 

After the establishment, you can start to configure and compile glibc. Example:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # build_cc = "GCC" cc = $ target-GCC .. /glibc-2.14/configure -- Host = $ target -- target = $ target -- prefix =/usr -- enable-add-ons -- disable-profile -- cache-file = config. cache -- With-binutils = $ prefix/bin/-- With-headers = $ target_prefix/include/

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

../Ports/sysdeps/Unix/sysv/Linux/ARM/sigrestorer. S: 30: Error: Previous CFI entry not closed (missing. cfi_endproc)

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Vi ../glibc-2.14/ports/sysdeps/Unix/sysv/Linux/ARM/sigrestorer. s

Find the following line:

Entry (_ default_sa_restorer)

Add:

End (_ default_sa_restorer)

Find the following line:

Entry (_ default_rt_sa_restorer)

Add:

End (_ default_rt_sa_restorer)

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

../Sysdeps/Unix/syscall-template.S: 82: Error: CFI instruction used without previous. cfi_startproc

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Vi ../glibc-2.14/sysdeps/Unix/syscall-template.S

Find the following line:

# Define t_pseudo do (symbol, name, n) pseudo do (symbol, name, n)

Add:

# Define pseudo (name, syscall_name, argS )\

. Text ;\

Entry (name );\

Do_call (syscall_name, argS );\

CEN r0, $4096;

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

Allocatestack. C: 247: 33: Error: 'tls _ dtv_unallocated 'is not declared (used for the first time in this function)

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Vi ../glibc-2.14/nptl/allocatestack. c

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Vi ../glibc-2.14/Elf/dl-tls.c

Add the following after the include in the file:

# Define tls_dtv_unallocated (void *)-1l)

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

/Home/Embedded/tools/lib/GCC/ARM-Linux/4.6.1 /.. /.. /.. /.. /ARM-Linux/bin/ld: cannot find-lgcc_eh

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # ln-S/home/Embedded/tools/lib/GCC/ARM-Linux/4.6.1/libgcc. a/home/Embedded/tools/lib/GCC/ARM-Linux/4.6.1/libgcc_eh.a

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

../Sysdeps/ieee754/dbl-64/s_fma.c: 152: 15: Error: 'fe _ towardzero 'is not declared (used for the first time in this function)

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # vi.../glibc-2.14/sysdeps/ieee754/dbl-64/s_fma.c

Add the following content after include:

# Define fe_towardzero 0xc00000

# Define fe_inexact 16

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Compilation error:

../Sysdeps/ieee754/dbl-64/s_fmaf.c: 39: 15: Error: 'fe _ towardzero 'is not declared (used for the first time in this function)

Solution:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Vi ../glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c

Add the following content after include:

# Define fe_towardzero 0xc00000

# Define fe_inexact 16

Continue make Compilation

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # Make install_root = $ target_prefix prefix = "" Install

 

Finally, modify libc. So to complete this step.

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # vi.../tools/ARM-Linux/lib/libc. So

Find the following line:

Group (/lib/libc. so.6/lib/libc_nonshared.a as_needed (/lib/ld-linux.so.2 ))

Change it:

Group (libc. so.6 libc_nonshared.a)

 

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

First, go to the Build-GCC directory, configure and compile full GCC, and the installation is complete. Instance:

Root @ Ubuntu:/home/Embedded/build-tools/build-glibc # cd/home/Embedded/build-tools/build-gcc/

Root @ Ubuntu:/home/Embedded/build-tools/build-GCC #.. /gcc-4.6.1/configure -- target = $ target -- prefix = $ prefix -- enable-extensions ages = C, C ++ -- disable-libgomp

Root @ Ubuntu:/home/Embedded/build-tools/build-GCC # Make

Root @ Ubuntu:/home/Embedded/build-tools/build-GCC # make install

After completion, several more files are added under $ prefix/bin:

-Rwxr-XR-x 2 root Root 869603 arm-Linux-C ++ *

-Rwxr-XR-x 2 root Root 869603 arm-Linux-G ++ *

The functions of these generated files are as follows:

Arm-Linux-G ++: gnu c ++ Compiler

Arm-Linux-C ++: equivalent to arm-Linux-G ++

 

 

8. Verify the Compiler

Use Vim to write the following code and save it as the main. c file:

# Include <stdio. h>

Int main (void)

{

Printf ("Hello world \ n ");

Return 0;

}

Then execute the compilation command. Instance:

Root @ Ubuntu:/home/Embedded/tmp # arm-Linux-gcc-static main. C-o helloworld

Verify the final compiled file after compilation. Instance:

Root @ Ubuntu:/home/Embedded/tmp # file helloworld

Helloworld: Elf 32-bit LSB executable, arm, Version 1, statically linked, for GNU/Linux 2.0.0, not stripped

Output indicates that the arm version program is successfully compiled.

From: http://blog.csdn.net/xt_xiaotian/article/details/6836739

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.