当前位置:网站首页>Embedded system transplantation [5] - Cross compilation tool chain

Embedded system transplantation [5] - Cross compilation tool chain

2022-07-24 03:22:00 imysy_ 22_

         Before that, we learned Linux How to transplant , But the Linux kernel 、 The files of the device tree and the root file system are directly provided to us , Later we will learn “uImage”、“exynos4412-fs4412.dtb” and “ramdisk.img” The origin of .

Compiler principle

         First , Let's review the principle of compilation , If you don't understand the compilation principle , The follow-up study will be very difficult .

Machine code ( Binary system ):

        CPU Language that can be recognized directly , Different machine codes represent different operation instructions . The processor can identify which machine codes are determined by the hardware design of the processor , Different processors have different machine codes , So the machine code is not portable . The original program is machine code .

assembly :

         Assembly language , Is the symbolization of machine code , To put it bluntly, it is to use a symbol one One correspondingly replaces a machine code . Different processor assemblies are also different , Even assembly language is not portable .

C Language :

         When compiling, we can use different compilers to translate C Compile the source code into a compilation of processors with different architectures , therefore C Languages can be transplanted .

stay Ubuntu Next , The most commonly used compiler is GCC.

Cross compilation

Cross compilation is actually a big category , In our case, cross compilation means that the compilation and operation of programs are not on the same machine

  notes : Need to be in advance Ubuntu Put one on top ARM The compiler .

Cross compile toolchain

Acquisition of cross compilation tool chain :

          1) Official website acquisition ( Not recommended , You need to configure and compile yourself )

                  http://ftp.gnu.org/gnu/gcc/

          2) BSP Board level development support package ( Configured by the manufacturer , recommend )

                  samsung、 Full ambition ...

Cross compile the content of the tool chain

          1) Cross compiler tool

                  gcc/readelf/size/nm/strip/objcopy/objdump/addr2line

          2) library

                  ARM Architecture Library

ELF File format

ELF The format is Linux On the platform One of the most widely used binary Industrial Standards

         We are linux The generated executable file is ELF Format .ELF The format file contains many segments, and different segments store different information ; because ELF The format of the file should be through Linux The loading and management of the system can run , So in addition to the most basic code and data segments , It also stores a lot of other information , Such as the symbol table 、 Debugging information, etc .

ELF File related commands :

file

    file + file name   View file details

readelf

    readelf -h + file name   List elf The header information of the file

    readelf -a + file name   List elf All the information in the file

BIN File format

        BIN The file is usually Run directly at CPU above The executable of , The file contains only CPU Instructions and data that can be directly identified and run , It does not contain information related to other systems .

Cross compilation tool chain common tools

size  List the size of each segment of the target file and the overall size

    size + file name  

The machine code generated by the assembly instruction is in text paragraph ; The initialized variables are data paragraph ; The initialized variable exists bass paragraph .

a.out piecewise
The size of executable files compiled with different compilation tools is different

nm  List the symbol table in the target file ( Identifier )

    nm + file name  

  notes : It can be used nm Command to see the functions in the Library

strip  Discard symbols in the target file ( Slimming order

    strip + file name  

  The symbol table has no meaning for the execution of the program , Delete the symbol table , Reduce the memory space required .

notes : For embedded development , This order is very important

①file + The file name command can see whether the file has been executed strip command .

②arm-none-linux-gnueabi-gcc To compile executable files arm-none-linux-gnueabi-strip Slimming .

objdump  Display information from the target file  

    eg: 

      objdump -d + file name   Put the target file Disassembly ( Machine code -> assembly )
 

notes : Although you can use machine code to disassemble , But you can't reverse it with assembly C Language , because C Language and assembly instructions are not one-to-one correspondence

   

objcopy  Copy and convert the target file

    eg:

      objcopy --gap-fill=0xff -O binary a.out a.bin 

  take Target file conversion by bin Format , Used to run programs on bare metal . The principle is to combine the code segment and data segment of the object file copy Come out and generate bin File format .

expand : Bare metal development generation .bin Format object file Makefile Code reference

led.bin:led.s

    arm-linux-gnueabihf-gcc -g -c led.s -o led.o

    arm-linux-gnueabihf-ld -Ttext 0X87800000 led.o -o led.elf

    arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin

    arm-linux-gnueabihf-objdump -D led.elf > led.dis

clean:
    rm -rf *.o led.bin led.elf led.dis

原网站

版权声明
本文为[imysy_ 22_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207222224093329.html