Lesson 2 cross-compiling environment for creating an embedded Linux development environment

Source: Internet
Author: User

The last time we talked about how to build a Linux
Development environment. This time, we will build our own cross-compiling environment for ARM-Linux based on different target platforms.
There are many ways to build a cross-compiler environment. different architectures, different operations, and even different kernel versions all use different cross compilers. For example, uboot, kernel, and file systems require different compiling environments. Therefore, select the appropriate cross compiler for embedded
Development is very important. Generally, a complete cross-compiler involves multiple software, including binutils, GCC, and glibc. Among them, binutils mainly generates some auxiliary tools; GCC is used to generate a cross compiler, mainly to generate an arm-Linux-GCC cross compilation tool, ear glibc mainly provides some basic function libraries required by the user program.

 
 
It seems that the establishment of the Cross-compilation environment is complicated, so the general development board company's CD is basically accompanied by the compiled cross compiler, the general version is 2.95.3, 3.3.2 and
3.4.1. 2.95.3 is generally used to compile the linux2.4 kernel, and 3.3.2 is used to compile the linux3.3.2 kernel. Generally, these compilers have been tested and
The distribution board can be well matched, so it can be used directly without configuration at the beginning. Of course, due to the lag of time, these compilers are often not the latest. When a new version is required, developers are often urged to release the new version ^_^, so here we will introduce two methods to build an arm-Linux debugging environment.

Method 1: Use a ready-made Cross Compiler


It is relatively simple to use the off-the-shelf cross compiler. Generally, the Development Board carries several arm-Linux tool chains of different versions. For example, the development version used to compile the kernel is 3.4.1.
1. Extract the tool chain to the specified directory. Take the sample creation as an example.
After sshlogin, transmit arm-linux-gcc-3.4.1.tar.bz2 to Linux using the file transfer tool provided by SSH, and decompress it using the tar command.
The command is as follows:
Mkdir/usr/local/ARM // SSH Login operation must have write permission, or directly Log On As root

Tar-xjvf arm-linux-gcc-3.4.1.tar.bz2-C/

-C /:
The idea is to decompress the package to the specified directory, which refers to the directory. Because the directory structure in the package itself contains usr/local/arm, therefore, to decompress the package to the root directory is to decompress the file to the/usr/local/ARM folder.


2. environment variable settings

When setting environment variables, We can output the path generated by the preceding path. Here we use the bash configuration file, which is used to execute the file each time we log on to or open the shell. You can also skip this unless you are willing to export the environment variable every time you open it.



In
/Etc/bashrc

Add the path after the file: (if it is Ubuntu, modify
/Etc/bash. bashrc
, Or/etc/bash. bashrc. Local


)

Path = $ path:/usr/local/ARM/3.4.1/bin

OK. Enter the command arm-Linux-GCC -- version on the SSH terminal to view the GCC version.


Arm-linux-gcc.jpg


(15.92 KB)


In the same way, you can create tool chains of multiple versions. Modify bash
Configuration file.

Note: To edit a file in the terminal or SSH window, run the VI command. The file development command is the VI file name.

For example, to edit the/etc/bashrc file, run the following command:
VI/etc/bashrc

The following commands are mainly used:
: Q // do not save and exit


: WQ // save and exit

I // insert

ESC // switch between command mode and edit mode

We need to add the statement Path = $ path:/usr/local/ARM/3.4.1/bin after bashrc:

1. VI/etc/bashrc

2. move the cursor to the end of the file and press the I key to enter the insert mode.

3. Press enter and enter Path = $ path:/usr/local/ARM/3.4.1/bin.

4. Press ESC to switch to the command mode (if you do not know the current mode, press ^_^)

5. Press: QW (note that there is a colon) to save and exit.

6. You can run the CAT/etc/bashrc command to check whether the modification is successful.

Method 2: Build a new cross-compilation environment


We can use the crosstool tool to easily build a cross-compilation environment. Crosstool is a script program developed by Dan Keel, an American (graduated from the National Institute of Technology in lifonia) to automatically compile and test GCC and glibc of different matching versions.

Http://kegel.com/crosstool/crosstool-0.43.tar.gz

In http://kegel.com/crosstool/crosstool-0.43/buildlogs/

We can see that the CPU and GCC + glibc versions that have been compiled successfully, those that have been partially succeeded, and those that have completely failed. If you are not a compiler developer, follow the above steps.




You can also go to ttp: // kegel.com/crosstool/#download

Check whether any updated version exists.



 

Step 1: Check whether the Linux host has the following tools:
Bison, flex, Build-essential
I installed fedora.
8. These tools are basically available.



 

Step 2: Install and unzip the crosstool Tool



 


(Ssh 21ieeafter login, directly upload crosstool-0.4.3.tar.gz)



Tar-xzvf crosstool-0.43.tar.gz
// Extract




Step 3: Go to the crosstool folder and you can see many. Sh files.
Script and. dat
Configuration file. Because we use the development target system for S3C2440, So we choose demo-arm9tdmi.sh
. The content is as follows:

#! /Bin/sh

# This script has one line for each known working toolchain

# For this architecture. uncomment the one you want.

# Generated by generate-demo.pl from buildlogs/all.dats.txt

Set-ex

Tarballs_dir =
/Home/21iee/ARM/source


Result_top =
/Home/21iee/ARM/crosstool


// Tarballs_dir is the directory of the compressed tool source code package. We need to put the source code package here.

// Result_top is the directory where the toolchain to be generated is stored and requires write permission. Otherwise, compilation will fail.


Export
Tarballs_dir result_top
Gcc_ages =
"C, C ++"

Export
Gcc_ages
#
Really,
You shoshould do
The mkdir before running this
,

#
And
Chown/
OPT/
Crosstool to yourself so you Don

'T need to run as root.
Mkdir-p $ result_top




# Eval 'cat arm9tdmi. dat gcc-3.2.3-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.2.3-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.2.3-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.3.6-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.3.6-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.3.6-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.2.5.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.5.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.5-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.6.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-3.4.5-glibc-2.3.6-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.2.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.5.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.5-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.6.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.0.2-glibc-2.3.6-tls.dat 'sh all. Sh -- notest
# Eval 'cat arm9tdmi. dat gcc-4.1.0-glibc-2.3.2.dat 'sh all. Sh -- notest
Eval 'cat arm9tdmi. dat gcc-4.1.0-glibc-2.3.2-tls.dat 'sh all. Sh -- notest




// Indicates the version number of the toolchain to be selected! "#" Starts the annotation function! Select a row!



Echo done.







Step 4: Download the source package to $ {tarballs_dir}
Directory. As shown in the preceding table




The eval 'cat arm9tdmi. dat gcc-4.1.0-glibc-2.3.2-tls.dat 'sh all. Sh -- notest
, Open
Arm9tdmi. dat gcc-4.1.0-glibc-2.3.2-tls.dat
The content is as follows:










 

Binutils_dir = binutils-2.16.1

Gcc_core_dir = gcc-3.3.6

Gcc_dir = gcc-4.1.0

Glibc_dir = glibc-2.3.2

Linux_dir = linux-2.6.15.4

Linux_sanitized_header_dir = linux-libc-headers-2.6.12.0

Glibcthreads_filename = glibc-linuxthreads-2.3.2

Gdb_dir = gdb-6.5

Glibc_extra_config = "$ glibc_extra_config -- With-TLS -- With-_ thread -- enable-kernel = 2.4.18"

Download the .bz2 source code package corresponding to the red mark on the Internet and save it to $ {tarballs_dir}
Directory. Note: In Windows, the bz2 package downloaded by some software may be faulty. It is recommended that you right-click IE and save it as (I cannot decompress a few packages under thunder for a long time, so I am dizzy)


Finally, enter the crosstool-0.43 directory and enter./demo-arm9tdmi.sh to start compilation. Then you can take a nap. If there is no compilation error, you will see the desired tool chain in your toolchains directory about an hour later.
Then add the modified path to the path to work (same as above)

Author: Please indicate the source for hztour Reprinting

Related Article

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.