Step by step create crosstoolchain based on ARM + Linux
Source: Internet
Author: User
Step by step, create a crosstoolchain based on ARM + Linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. Disclaimer: This article is based on the reference of online materials, and is based on Liang yuanen's "How to Build a cross-compiling environment for Embedded Development. I have explained in detail the problems I encountered during the establishment process. This article will be updated as I learn.
1 Introduction
Due to the limited storage capacity of embedded development systems, a cross-compiling environment for the target machine is usually required on a PC before Linux is customized and used in embedded systems, that is, various binary tool assemblies are used as tool chains, including GNU linker (ld), GNU assembler (as), and ar (generate modifications and unzipping an archive file) C compiler (gcc) and C link library (glibc ). This document describes how to establish a tool chain for cross-platform development on the target arm in Linux.
2 Basic Concepts
2.1 What is cross-compilation?
In short, cross-compilation is the code generated on one platform and executed on another platform. The platform here includes Architecture and Operating System (OS ). The same architecture can run different operating systems, and the same operating system can run on different architectures. For example, the x86 Linux platform is a general term of the Intel x86 architecture and the Linux for x86 operating system.
2.2 why do I use cross-compilation?
There are two reasons. First, cross-compilation is required when the bootloader and OS core required by the target platform are not yet established. Second, the target machine does not have certain processor capabilities and storage space, that is, the program development cannot be completed on the target board separately, so you have to ask for the host machine. In this way, the application program to be run on the target machine can be compiled on the host machine to generate the code format that can be run on the target machine, and then transplanted to the target board, that is, the Host/Target mode developed by embedded programs.
2.3 i386 Comprehension
I386 and i686 refer to the CPU type. In terms of linux kernel design, i386 is the architecture, and i386 is the CPU architecture of i386, so many linux designs are based on i386. Put simply, when i386 is put together with ppc, alpha, and arm, it refers to the architecture. If it is put together with i586 and i686, it refers to the processor model. One is horizontal and the other is vertical.
3. creation process
3.1 selected software version
To select an appropriate version to ensure the availability of the tool chain, you must find a combination suitable for the host and target board. You can test these versions on your own, or search for version combinations that have been tested on the Internet, that is, binutils, gcc, and glibc versions. I used the host machine for the redhat-9.0, the target machine arm, the selected version is as follows:
You can select an updated version, and use the older version in turn when the compilation fails. Immediately discover that the new version combination can be compiled successfully, and you still need to test whether the created tool chain can be used.
You can. The download paths of the selected versions are shown below.
When creating and using some tool programs, these directory paths may be used. If you design a short Command Script and set appropriate environment variables, the operation can be simplified. The following is a Command Script hjbl:
Enter the following content in the edit emacs window that will be opened later (if you are using the command line interface, you must use the vi text editor, but not emacs ):
Export PRJROOT =/home/lqm/embedded-system
Export TARGET = arm-linux
Export PREFIX = $ PRJROOT/tool-chain
Export TARGET_PREFIX = $ PREFIX/$ TARGET
Export PATH = $ PREFIX/bin: $ PATH
Save and close the emacs window. If you want to execute this script in the current window to make the environment variable take effect, you also need to execute the following statement:
This environment variable takes effect only in the current Terminal window. If you close the window and open a new window, the environment variable is effective and you need to execute the following command again:
$./Home/lqm/embedded-system/doc/scripts/hjbl
Note:
The TARGET variable is used to define the type of the TARGET Board. In the future, the tool chain will be established based on the type of the TARGET board. See table 1. The TARGET board definition has nothing to do with the host type, but if you change the TARGET value, the GNU toolchain must be re-established once.
The PREFIX variable provides pointers to the directory where the target board tool program will be installed.
The TARGET_PREFIX variable points to the directory to which the header file and link library related to the target board will be installed.
The PATH variable points to the directory where the binary file (Executable File) will be installed.
The configuration of the kernel header file is the first step to establish a tool chain. It is similar to other steps to be executed. Most of the steps are as follows:
1. decompress the package
2. Configure packages for cross-platform development
The values of the ARCH and CROSS_COMPILE variables are related to the architecture type of the target board. If you use the PPC target board, ARCH = ppc CROSS_COMPILE = ppc-linux -. If i386 target board is used, ARCH = i386 CROSS_COMPILE = i386-linux -.
Make menuconfig is configured in text menu mode.
Make xconfig is configured on the GUI.
Make config is configured in plain text mode.
Select make menuconfig. Note that the correct hardware type is selected in System Types. After the configuration is complete, exit and save, check whether the kernel/linux-2.4.21/include/linux/version. h and autoconf. h files in the kernel directory are generated, which is needed to compile glibc. The existence of version. h and autoconf. h files indicates that you have generated the correct header file.
Then, create the include directory required by the toolchain and copy the kernel header file.
1. You don't have to reset the tool chain every time you reset the Kernel configuration, unless you change the type of the processor or system. The toolchain only requires a set of valid header files available for the target board. These header files have been provided in the previous program.
2. When the asm-linux folder is placed in the target folder $ TARGET_PREFIX/include/, you must change the name to asm because the include Inclusion Method of the configuration file is the same. This is also the difference between cross-compilation. Otherwise, an error message similar to the following will appear:
Tools in the binutils package are often used to operate binary objects. The two most important tools in this package are the GNU assembler as and the linker ld.
Note: The prefix of each tool's file name is the value previously set for the TARGET variable. If the target board is a i386-linux, the file name prefix for these tools will be i386-linux -. In this way, you can find the correct tool program based on the target board type.
3.6 initial compiler Creation
At the beginning, only C-language-supported boot compilers can be established, because the C-Linked Library (glibc) is not supported. After glibc is compiled, You Can recompile gcc and provide complete C ++ support.
Because it is a cross compiler and does not need the system header file of the target board, you need to use the -- without-headers option. -- Enable-language = c is used to tell the language supported by the compiler to be generated for script configuration. Currently, only c is supported. -- Disable-threads: threads requires glibc support.
Prepare the Makefile file and modify the src-dir/gcc-2.95.3/gcc/config/arm/t-linux file before compiling. Add two definitions in TARGET_LIBGCC2_CFLAGS: -Dinhibit_libc-D _ gthr_posix_h; otherwise, an error is returned.
This step is the most tedious process. The target board must be used to execute or develop most applications. Glibc kit 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 replacement for the C-Linked Library, such as uClibc. Here, the standard gnu c is used as an example to establish a tool chain.
The install_root variable is set here to point to the directory currently to be installed by the link library component. This allows the Linked Library and its header files to be installed in the directory related to the target board specified through TARGET_PREFIX, rather than the/usr directory of the system. Because the -- prefix option was used to set the value of the prefix variable, and the value of the prefix will be appended to the value of install_root and become the installation directory of the link library component, therefore, you need to reset the prefix value. In this way, all glibc components will be installed in the directory specified by $ TARGET_PREFIX.
The above output indicates that you have compiled a hello-linux system that can run in the arm architecture, proving that your compilation tool has been successful.
4. Summary
Through the above operations, we have been able to establish a full-featured cross-platform development tool chain, which will be frequently used in future embedded development.
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.