Make your own arm-linux cross tool chain

Source: Internet
Author: User
Tags bz2 gmp

Learn embedded well, you have to do more hands-on, more practice. To get started, configure your own development environment and migrate the kernel. The development environment does not say that the porting kernel will have to compile the kernel first. You have to have a compiler. Because the architecture of arm CPUs is not the same as x86. The usual practice is to use the arm cross compiler in the x86 development platform to compile the kernel and then port it to the Development Board. Making a cross-tool chain is a careful work, cumbersome and difficult. Online recommended practice is to use others to create a good tool chain, and so on after more experience, and then to carefully study this. I do not know why I have to bite the bullet, the results took one weeks or daoteng out, is a harvest. So this blog post on a simple record, the content does not involve the principle of cross-compiler production and details, just write down the production process, most of the content is also online, so there is no depth. When you learn FLS later, you'll have to study it carefully.

1. Preparatory work

I refer to this article to make cross-tool chain, the content of this article is mostly similar. Can think this article is a reprint. Http://www.cnblogs.com/Charles-Zhang-Blog/archive/2013/02/21/2920999.html

In addition, this article is to make arm9--s3c2440 the CPU of the cross compiler. The Linux version used is 2.6.29

Download tool chain source code, kernel source code

binutils-2.19.tar.bz2

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

gcc-4.4.4.tar.bz2

http://mirrors.kernel.org/gnu/gcc/gcc-4.4.4/

glibc-2.11.2.tar.bz2

glibc-ports-2.11.tar.bz2

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

gmp-4.2.tar.bz2

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

mpfr-2.4.0.tar.bz2

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

linux-2.6.29.tar.bz2

patch-2.6.29.bz2

http://www.kernel.org/pub/linux/kernel/v2.6/

Create a working directory

In the normal user mode, the first set up the ~/cross/embedded-toolchains/ directory, and then follow the relationship to create each sub-folder, so the structure is clear, but also conducive to the following description.

After the directory structure is set up, you need to modify the setup-dir properties of the folder, chmod 777 setup-dir and then copy all the downloaded source-code compressed packages to this directory. Finally, some environment variables are set up to facilitate the use of the production process. doc/srciptunder Create a envionment-variables script, the content is as follows, notice to modify your own home directory:

Then switch to Superuser and the next is done under superuser privileges. Execution source envionment-variables makes the environment variable effective.

2. Production process

Before making the cross-tool chain, explain the production process, so that the creator has overall grasp, not disoriented.

    1. Set up binary tools (binutils)

    2. Build Kernel header File

    3. Build initialization compiler (Bootstarp GCC)

    4. Compiling glibc

    5. Build a full set of compilers (fully GCC)

Let's start making it!!

3. Create a binary tool (Binutils)

Binutils is one of the GNU tools that includes connectors, assemblers, and other tools for target files and archives, which are binary code processing and maintenance tools. The installation Binutils tool contains programs such as Addr2line, AR, as, c++filt, gprof, LD, NM, objcopy, Objdump, Ranlib, readelf, size, strings, strip, Libiberty, LIBBFD and Libopcodes. The use of these tools is not introduced, and so later encountered to learn.

Extracting source code

cd $PRJROOT/src-dir
tar jxvf ../setup-dir/binutils-2.19.tar.bz2
cd $PRJROOT/build-dir/build-binutils

Configuration

../../src-dir/binutils-2.19/configure --target=$TARGET --prefix=$PREFIX --disable-werror

Installation

make
make install

Check

Check if the ls $PREFIX/bin installation was successful by looking under whether a tool was generated binutils , as follows:

4. Build the kernel header file

This step uses the compiler that comes with the system to compile the kernel, the main purpose is to get some header files. Either the cross-compiler or the local compiler compiles the kernel. is the compilation of the Linux kernel, the basic process is the same. It is therefore better to understand the process of compiling the Linux kernel before making it down. Can find some information on the Internet to see.

Extracting source code

cd kernel
tar jxvf ../setup-dir/linux-2.6.29.tar.bz2
cd linux-2.6.29

Configuring the Kernel

Here I will use s3c2410_defconfig this default file to configure:

cp ./arch/arm/configs/s3c2410_defconfig ./.configmake ARCH=arm CROSS_COMPILE=arm-linux- menuconfig

Compile

make ARCH=arm CROSS_COMPILE=arm-linux-

This step is definitely going to go wrong, and arm-linux-gcc the compiler hasn't done it yet. This is done just to get some header files related to ARM architecture that can be viewed /kernel/linux-2.6.29/include/linux/version.h and the autoconf.h file is not generated, which is compiled glibc to use. version.hand autoconf.h the existence of the file, stating that you have generated the correct header file.

Copy

Next, set up the Include directory required for the toolchain and copy the kernel header files to the past.

mkdir -p $TARGET_PREFIX/includecp –r $PRJROOT/kernel/linux-2.6.29/include/linux $TARGET_PREFIX/include
cp –r $PRJROOT/ kernel /linux-2.6.29/include/asm-arm $TARGET_PREFIX/include/asm
cp –r $PRJROOT/ kernel /linux-2.6.29/include/asm-generic $TARGET_PREFIX/include
cp –r $PRJROOT/ kernel /linux-2.6.29/arch/arm/include/asm $TARGET_PREFIX/include
cp –r $PRJROOT/ kernel /linux-2.6.29/arch/arm/mach-s3c2410/include/mach $TARGET_PREFIX/include/asm

The Note:mach-xxx is selected based on the CPU type used by the target board.

5. Build initialization compiler (Bootstarp GCC)

The purpose of this step is to establish the ARM-LINUX-GCC tool, note that this GCC does not have glibc library support, so can only be used to compile the kernel, bootloader, etc. do not need C library support programs, the subsequent creation of C library will also use this compiler, So to create it is mainly to create a C library to prepare, if you just want to compile the kernel and bootloader, then the installation of this can be finished. The installation process is as follows:

Extracting source code

cd $PRJROOT/setup-dir
mv gcc-core-4.4.4.tar.bz2 gcc-4.4.4.tar.bz2
cd $PRJROOT/src-dir
tar jxvf ../setup-dir/gcc-4.4.4.tar.bz2

From GCC-4.3 onwards, the installation of GCC will depend on the GMP-4.1 and above versions and MPFR-2.3.2. If the two packages are extracted separately into the root directory of the GCC source tree and are named "GMP" and "MPFR" respectively, then the GCC compiler will automatically compile both with GCC. It is recommended to use the latest GMP and MPFR versions whenever possible.

tar jxvf ../setup-dir/mpfr-2.4.0.tar.bz2
tar jxvf ../setup-dir/gmp-4.2.tar.bz2
mv mpfr-2.4.0 gcc-4.4.4/mpfr
mv gmp-4.2.0 gcc-4.4.4/gmp

Configuration

Since the first installation of the arm cross-compilation tool, then the support of the LIBC library header file is not, src-dir/gcc-4.4.4/gcc/config/arm/t-linux file, in the TARGET_LIBGCC2_CFLAGS add two definitions:-Dinhibit_libc –D__gthr_posix_h

Original:

TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer –fPIC

After the change:

TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D_gthr_posix.h

Further configuration:

cd $PRJROOT/build-dir/build-gcc
../../src-dir/gcc-4.4.4/configure --target=$TARGET --prefix=$PREFIX --without-headers --enable-languages=c --disable-shared --disable-threads --disable-decimal-float --disable-libmudflap --disable-lipssp

Compile

make all-gcc
make install-gcc
make all-target-libgcc
make install-target-libgcc

In the GLIBC compilation, it is also necessary libgcc_eh.a (otherwise an error: cannot find -lgcc_eh ), --disable-shared the options used, will not be generated libgcc_eh.a , can be implemented by the link to libgcc.a .

ln -vs libgcc.a $PRJROOT/tool-chain/lib/gcc/arm-linux/4.4.4/libgcc_eh.a 

Check

ls $PREFIX/binSee arm-linux-gcc If the tool has been built.

6. Compiling glibc

This step is the most tedious process, and the target board must rely on it to execute or develop most of the applications. The glibc suite is often called a C-link library, but glibc actually produces many link libraries, one of which is the C-link library libc. Due to the limitations of the embedded system, the standard GNU C link library is too large to be applied on the target board. Therefore, we need to find a substitute for C link library, here is the standard GNU C as an example to establish a tool chain.

Extracting source code

cd $PRJROOT/src-dir
tar jxvf ../setup-dir/glibc-2.11.2.tar.bz2
tar jxvf ../setup-dir/glibc-ports-2.11.tar.bz2
mv –v glibc-ports-2.11 glibc-2.11.2/ports

Configuration

cd $PRJROOT/build-dir/build-glibc
CC=arm-linux-gcc AR=arm-linux-ar RANLIB=arm-linux-ranlib
../../src-dir/glibc-2.11.2/configure --host=arm-linux --prefix=$PREFIX/$TARGET --with-tls --disable-profile --enable-add-ons --with-headers=$PREFIX/$TARGET/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_arm_tls=yes

Compile

make
make install

7. Build a full GCC configuration

../../src-dir/gcc-4.4.4/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ --enable-shared

Compile

make allmake install

The entire cross-compilation environment is now complete.

8. Cross-tool chain testing

Let's write a Hello World program to test whether our own toolchain can actually be compiled.

cd $PRJROOT/programvim hello.c

#include <stdio.h>int  main () {    printf ("Hello arm-linux\n") );     return 0 ;}

Then compile:

arm-linux-gcc hello.c -o hello

Finally, you can file hello see whether the generated program is an arm platform.

9. Troubleshooting Process

Here are the errors and troubleshooting problems that I made in my cross-compilation tool chain in accordance with the above process, hoping to help everyone.

Compile binutils appears [-werror=unused-but-set-parameter]

This is required when configuring the Configure file, use the--disable-werror parameter

Make Menuconfig does not appear in the Configuration interface:

Workaround: Install the ncurses Library Reference: http://blog.chinaunix.net/uid-24782829-id-3211008.html

./configure--without-cxx-binding

Abi-versions.h
No rule to make Target/home/gru/cross/embedded-toolchains/build-dir/build-glibc/versions.all ', needed by/home/gru/ Cross/embedded-toolchains/build-dir/build-glibc/abi-versions.h '. Stop.

http://www.linuxquestions.org/questions/linux-from-scratch-13/glibc-2-5-1-make-error-588488/

You need to reconfigure and make when you are finished installing gawk

When making cross-compilation tools, you need to be as careful as possible, and when you strike a command, you may not be able to make a mistake when the letter is accidentally wrong. There will inevitably be a few times to push the process back to the beginning. Just stick to it and you will succeed.

Make your own arm-linux cross tool chain

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.