Abstract: When we use the compiler to compile the project, we will require the generation of executable files, which will be burned to MCU for running, to achieve the purpose of testing and using the program, and then use the tool chain to compile time often generate. Bin,. Hex,. Elf,. Alf files, what is the difference between these files? Is it interchangeable? What are the executables in LiteOS? The significance of this paper is expounded.
Three file formats, Bin, HEX and ELF, have been downloaded into the MCU.
When we use the compiler to compile the project, we will require the generation of executable files, and burn these files to MCU for running, so as to achieve the purpose of testing and using the program. When we use the tool chain to compile, we usually generate files such as.bin,.HEX,.elf, and.alf. What are the differences between these files? Is it interchangeable? What are the executables in LiteOS? The significance of this paper is expounded.
BIN
The bin file is a basic binary file, which is the basic information saved by IO in Flash and the binary code directly compiled by the assembler. The bin file records the information in Flash in sequence. The text itself contains any address information. The bin file generated by compiling LiteOS using STM32CubeProm is shown in the figure below. We need to set the flash write address to burn.
HEX
Hex file format is a file format that can be written to and executed by microcontrollers. There are many ways to generate HEX files. C programs or assembler programs can be compiled by different compilers to generate HEX files. The most common Hex format is the Intel Hex file format, which is an ASCII text file that follows the Intel Hex file format. Each line of the file contains a Hex record. These records are made up of hexadecimal data representing machine language code and constants. Intel HEX files are commonly used to transfer programs and data to be stored in ROM or EPROM. Most EPROM programmers and FLASH can use Intel HEX files.
The HEX file corresponding to huawei_liteos. bin above is as follows (open with notepad++)
:020000040800F2 :2000000000000820F50E0008650F0008650F0008650F0008650F0008650F00080000000041 :20002000000000000000000000000000650F0008650F000800000000650F0008650F0008D0 . . . :208E0000D883050828830508D4820508148505081C8505082485050868CC03082C850508C8 :0C8E20003485050804CD030804CD0308C8 :00000001FFCopy the code
The file will have a header and a tail.
File header information
:020000040800F2
Copy the code
02 Data length with edge; 0x00 immediately followed by 0x00 is the address; The following 0x04 indicates the data type, which can be divided into the following categories:
’00’ // Data record ’01’ // File end record ’02’ // Extended segment address record ’03’ // Start segment address record ’04’ // Extended linear address record ’05’ // Start linear address record
The two 0x08 0x00 after 0x04 are the data, indicating the offset address, and the last 0xF2 is the parity code.
The format of the recorded address and corresponding data at the beginning of the second line is
: start code data | | | | address data type
:20|0000|00|00000820F50E0008650F0008650F0008650F0008650F0008650F000800000000|41
Copy the code
:20 The length of the recorded data is 20 bytes. The starting address of the 0000 data, 00 00 record type (record) is a data 00000820 f50e0008650f0008650f0008650f0008650f0008650f000800000000 41 this line calibration data content
The last line represents the end-of-file record
:00000001FF
Copy the code
The HEX file can also print the contents of memory in STM32CubeProm (same as the bin print before).
ELF
In computer science, is a file for binaries, executables, object code, shared libraries, and core dump formats developed and published by UNIX Systems Laboratories (USL) as the Application Binary Interface (ABI), It is also the main executable file format for Linux.
Elf (Executable and Linkable Format) is an Executable and Linkable Format file for connection dumps, as distinct from hex and BIN formats for recording data. Elf object files are generated by the assembler and link Editor and are binary, not readable text, code that can be run directly on the processor.
The elf file is an execution file packaged with binary (bin) files and program description files. The bin file is still downloaded into the program, but the emulator can rely on the rest of the program to express the file to obtain the program execution location and the corresponding binary. Ideographic files can be read under Linux using Readelf, but for my system’s sake I won’t go into details.
Other executable files:
.asf,.o,.out files are compiled executable files, and ELF are described with link format to preach, which can be simulated using emulators, but the compiler format and compiler Settings can choose different file formats.
Convertible sex
Since bin and HEX only record data, elf types not only record data but also program descriptions, so elf can be converted to bin and HEX, but reversed.
By comparison, it is found that the bin file is the smallest and simplest, but has poor security and functionality. Hex contains header and tail and check, which has good security, but the file is larger than BIN and has less powerful function than ELF. Elf has many features, but the largest files.
How does LIteOS generate these files
LiteOS uses the makefile to compile the file, and also uses the makefile to set the output format of the GCC compilation file, in the makefile code in the project directory:
$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/[email protected] -o $(OUT)/[email protected] --start-group $(LITEOS_BASELIB) --end-group
$(OBJCOPY) -O binary $(OUT)/[email protected] $(OUT)/[email protected]
$(OBJDUMP) -t $(OUT)/[email protected] |sort >$(OUT)/[email protected]
$(OBJDUMP) -d $(OUT)/[email protected] >$(OUT)/[email protected]
$(SIZE) $(OUT)/[email protected]
Copy the code
Interpreted code in code
arm-none-eabi-gcc -o xx.elf
arm-none-eabi-objcopy -O ihex xx.elf xx.hex
arm-none-eabi-objcopy -O binary xx.elf xx.bin
out --format ihex write xx.hex
Copy the code
The command compiled through GCC generates the result in xx.elf format, which generates the bin and HEX object files through ELF.
conclusion
As a result of using engineering compilations, it is best to have either BIN or HEX with elf files, elf for simulation and debugging, but output files to the factory can use HEX and bin.
Click to follow, the first time to learn about Huawei cloud fresh technology ~