1, what is the cross-tool chain:
Understanding from two levels, the first level, the crossover tool, the second level, the chain;
Chain is the meaning of the set, merged together, the Cross tool chain is a series of cross-tool collection;
2. Embedded development model--cross-development
In embedded development, there is a very important model called cross-development model;
In this model, there is a host, the Target Machine (Development Board), host and target hardware platform is not the same, host is generally X86 platform, the target machine has arm, etc., X86 very few, if the host on the compiler, only compiled on the x86 platform, obviously put on the target machine above the operation can not be run, Then you have to compile the program running on the target machine, but the host is the x86 platform, so there will be a x86 platform on the production of a kind of other hardware platform running on the program, this development model is called cross-development mode;
In embedded development, there are the roles of host and Target: The host is the computer that compiles and links the embedded software, and the target machine is the hardware platform to run the embedded software.
3. Common Cross tools:
(1) Cross compiler: ARM-LINUX-GCC
GCC is looking for header files from/usr/include, ARM-LINUX-GCC can be viewed with parameters-print-serach-dirs;
(2) Cross linker: ARM-LINUX-LD
From a well-edited program to a program that can be run, compiled and linked;
LD is the completion of the link, linked to the arm platform to run the program;
Example: Arm-linux-gcc-g-C LED. S
Arm-linux-ld-tled.lds-o led.elf LED.O
First, the name of the tool, and then if you want to use the linker script, use-T to indicate the linker script, use-O to indicate the name of the program after the link, and finally indicate which intermediate files are linked by the program;
(3) Crossover converter: Arm-linux-objcopy
The linked programs are in ELF format, this format of files can not be directly on the ARM processor running, on the Development Board of the Linux system, the first will be the Linux system with the ELF parser to parse it into binary files, and then go to run, Programs that are capable of running on ARM processors or other processors must be binary format programs;
How do I convert an elf-formatted file into a binary file?
To be done by arm-linux-objcopy:
Example: Arm-linux-objcopy-o binary led.elf Led.bin
-O indicates the format of the output and then follow the name of the input file and output file
Bin file can be run directly on the ARM processor, because burning to NAND flash, and no Linux system support, there is no one to help you to convert elf into binary, so to burn before writing with objcopy conversion to binary, in order to run on ARM processor;
(4) Cross elf file tool: Arm-linux-readelf
Whether it is ARM-LINUX-GCC directly compiled link out of the program, or through the arm-linux-ld indirect link out of the program, the final program is the ELF format;
Arm-linux-readelf-a led.elf can view the elf file information;
Compile a program with ARM-LINUX-GCC: ARM-LINUX-GCC hello.c-o Hello
Put this application on the Development Board to run, can not run, the possible situation: first, the application is not running on the arm platform, how to check? You can use the command file Hello,
Second, the size of the end is not correct, you can use arm-linux-readelf-a led.elf to view the size of the end of the arm is generally small terminal mode;
Another situation is that the library information is not correct, an application to use some libraries, on your development board have these libraries? We have to go check it out!
You can use: arm-linux-readelf-d hello to see which libraries are needed;
(5) Cross-disassembler arm-linux-objdump
The disassembler is a very useful tool in the development of the underlying, when we write a program to run on the board, the effect is not what we want, we can go to the assembly code to see whether there is a compilation level error.
Example: arm-linux-objdump-d-S Hello->dump (output information to a dump file)
Make the output more simple:
Arm-linux-gcc-g Hello.c-o Hello
Then disassemble: arm-linux-objdump-d-S->dump
You can find the main () function in vim and compare it!
Plus--help can see the usage!
We are only concerned with the last name LD/GCC, the front arm is the platform, the back is the essence!
016 Cross Tool chain