BIN, HEX, ELF, and AXF files,
File Format 1.Bin in Embedded Software Development
Binfile is the most pure binary machine code, or "sequential format ". The machine code is translated into binary machine code in the order of assembly code, and there is no address tag inside. Bin is a direct memory image. The size of the binary file is the actual size of the data contained in the file. The binfile is a direct binary file. It generally starts from 00 when it is written by the programmer. If it is downloaded and run, it can be downloaded to the address at compile time. It can be run directly on bare metal.
2. Hex
Intel hex files are often used to save the target program code of single-chip microcomputer or other processors. It saves the target code image in the physical program storage area. General programmers support this format. It is the hexadecimal form of the machine code, which is expressed by the ASCII code of a certain file format.
A hex file consists of records. In the HEX file, each row represents a record. Each record is prefixed by a colon (:) In the following format:
: BBAAAATTHHHH... HHHHCC
BB: number of bytes.
AAAA: the starting address of the data record. The highest is in the front, and the lowest is in the back.
TT: Type
00 data records, used to record data.
01 end the record, which is placed at the end of the file to identify the end of the file.
02 records used to identify extended segment addresses
04 extended Address Record (indicating the 32-bit address prefix)
HHHH: a data record of a Word, with a high byte in front and a low byte in the back. After TT, there are BB/2 Characters in total.
CC: The CheckSum that occupies a Byte
Example:
: 020000040000FA
: 400ff00a0e314209fe5001092e5011092e5a3
: 00000001FF
The analysis is as follows:
The length of 1st records is 0x02, the load offset is 0000, And the RECTYPE is 04. This indicates that this record is an extended segment address record. Data is 0000, And the checksum is FA. From the record length and data, we can calculate that the base address is 0X0000. All subsequent data records are based on this address.
The length of 2nd records is 0x10 (16), the load offset is 0004, And the RECTYPE is 00. This indicates that the record is a data record. The data is FF00A0E314209FE5001092E5011092E5, a total of 16 bytes, and the record checksum is A3. In this case, the base address is 0X0000, And the OFFSET value is added. The starting address of the 16BYTE data in this record is 0x0000 + 0x0004 = 0x0004. the actual data is only 16 bytes: FF00A0E314209FE5001092E5011092E5.
The length of the 3rd records is 00, the load offset is 0000, TYPE = 01, and the checksum is FF. The type is 01, indicating that this is an end of file record, marking the end of the FILE. The HEX Terminator generally ends with: 00000001FF.
Briefly summarize the differences between the two file formats:
1. the HEX file contains the address information, while the binfile only contains the data. When you burn or download the HEX file, you generally do not need to specify the address because the HEX file contains the address information. When burning a binfile, you must specify the address to be burned.
2. the HEX file uses ASCII codes to represent binary values. For example, the 8-BIT binary value 0x4E, which is represented by ASCII, must represent the '4' and 'E' characters respectively. Each character requires one byte, therefore, the HEX file requires at least two times the binfile space.
3. ELF
The ELF (Executableand linking format) file is a common object file format in x86 Linux systems. There are three main types:
(1) A relocatablefile suitable for connection. It can be used with other target files to create executable files and share the target files.
(2) executable files suitable for execution, which are used to provide the process image of the program and load it To the memory for execution.
(3) shared object file (shared object file). The connector can connect it with other relocated files and shared target files to other target files, the dynamic connector can also combine it with executable files and other shared target files to create a process image.
Summary: The elf file can be converted into two types of files: hex and bin. hex can also be directly converted to a binfile, but the base address must be given to convert the bin to a hex file. Hex and bin cannot be converted to elf files because elf has a large amount of information. The Axf file can be converted to a bind file. In KEIL, run the following command fromelf-nodebug xx. axf-bin xx. bin.
4. AXF
The Axf file is generated by the ARM compiler. In addition to the bin content, it also attaches other debugging information that is added before the executable binary data. During debugging, the debugging information is not downloaded to RAM. The information actually downloaded to RAM is only executable code. Therefore, if the ram size is smaller than the axf file size, the program may be fully debugged in ram, as long as the axf removes the debugging information and the file size is smaller than the ram size.
Debugging information has the following functions:
1. The source code, including comments, can be clipped into the disassembly code so that we can switch to the source code for debugging at any time.
2. We can also track the function calls in the Program (view through Watch & Call Stack Window ).
3. Track variables (using Watch & Call Stack Window ).
Although debugging information is useful, it is very helpful to reduce debugging information in the target file and library after the program function is implemented. Reducing debugging information can reduce the size of the target file and library, speed up the link, and reduce the final image code. The following methods can be used to reduce debugging information generated by each source file:
1. Avoid using # define in the header file. The linker cannot remove the shared debugging parts unless they are identical.
2. Change the C/C ++ source file so that all header files contained in # sorted ded are in the same order.
3. Try to use a large number of small header files instead of a large single header file, which facilitates the linker to obtain more general blocks.
4. It is best to include only necessary header files in the program. To avoid repeated header files, you can use the compiler option-remarks to generate warning information;
Note:
(1) Both axf and elf are executable files generated by the compiler. The difference is that ADS compiles AXF files. The ELF file is compiled by gcc. Although the two are similar, they are still different. This is a file format difference and does not involve debugging formats.
(2) axf/elf is a Formatted Image, and bin is a direct memory image.
(3) in Linux OS, ELF is usually an executable file, usually gcc-o test. c. The generated test file is in ELF format. input it in Linux Shell. /test. In Embedded, the system starts running after power-on, and there is no OS system. If you burn an ELF file, which contains some ELF files, arm runs these commands, causing failure, if the binfile is used, the program can be run step by step.
Therefore, HEX and bind files can be run on bare metal instances, while ELF files are run in OS environments.