Hex文件类型全名:Intel hexadecimal object file format, Intel hex format or Intellec Hex。
实际上是将二进制文件转换成了ASCII码形式的文本文件,我们用文本编辑器打开hex文件,就可以看到里面的内容。
这种文件类型的目的就是为了烧写microcontroller, EPROMs和其他一些可编程逻辑器件。
总结
在使用IAR EWARM给项目设定输出文件类型时,就有一个Intel Extended Hex选项,这个就是指支持扩展记录类型的Hex文件。
一般就是使用00,01,04,05四个记录类型。
截取实际生成的hex文件举例:
:020000040800F2:10000000F0A10520B1FD030889EB03088BEB030881:100010008DEB03088FEB030891EB03080000000051:106EA0001C6014605C6021462B68104810229847D3:106EB0002B680F482146102298472B680D48214621。。。。。。:10C2E000FFF0FFF0FFF0FFF0FFF0FFF0FFF00000C5:10C2F000F0F000000000000000000000000000005E:0AC300000000000000000000000033:040000050803F8E113:00000001FF
------------------------------------------------------------------------------------ 数据分析举例: Record Format
An Intel HEX file is composed of any number of HEX records. Each record is made up of five fields that are arranged in the following format:
:llaaaatt[dd...]cc Each group of letters corresponds to a different field, and each letter represents a single hexadecimal digit. Each field is composed of at least two hexadecimal digits-which make up a byte-as described below:
* : is the colon that starts every Intel HEX record.
* ll is the record-length field that represents the number of data bytes (dd) in the record.
* aaaa is the address field that represents the starting address for subsequent data in the record.
* tt is the field that represents the HEX record type, which may be one of the following:
00 - data record
01 - end-of-file record
02 - extended segment address record
04 - extended linear address record
05 - start linear address record (MDK-ARM only)
* dd is a data field that represents one byte of data. A record may have multiple data bytes. The number of data bytes in the record must match the number specified by the ll field.
* cc is the checksum field that represents the checksum of the record. The checksum is calculated by summing the values of all hexadecimal digit pairs in the record modulo 256 and taking the two's complement. Data Records
The Intel HEX file is made up of any number of data records that are terminated with a carriage return and a linefeed. Data records appear as follows:
:10246200464C5549442050524F46494C4500464C33This record is decoded as follows::10246200464C5549442050524F46494C4500464C33||||||||||| CC->Checksum|||||||||DD->Data|||||||TT->Record Type|||AAAA->Address|LL->Record Length:->Colon where:
* 10 is the number of data bytes in the record.
* 2462 is the address where the data are to be located in memory.
* 00 is the record type 00 (a data record).
* 464C...464C is the data.
* 33 is the checksum of the record.
Extended Linear Address Records (HEX386)
Extended linear address records are also known as 32-bit address records and HEX386 records. These records contain the upper 16 bits (bits 16-31) of the data address. The extended linear address record always has two data bytes and appears as follows:
:02000004FFFFFC where:
* 02 is the number of data bytes in the record.
* 0000 is the address field. For the extended linear address record, this field is always 0000.
* 04 is the record type 04 (an extended linear address record).
* FFFF is the upper 16 bits of the address.
* FC is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
When an extended linear address record is read, the extended linear address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The linear address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted address data from the extended linear address record. The following example illustrates this process..
Address from the data record's address field 2462Extended linear address record data field FFFF --------Absolute-memory address FFFF2462 Extended Segment Address Records (HEX86)
Extended segment address records-also known as HEX86 records-contain bits 4-19 of the data address segment. The extended segment address record always has two data bytes and appears as follows:
:020000021200EA where:
* 02 is the number of data bytes in the record.
* 0000 is the address field. For the extended segment address record, this field is always 0000.
* 02 is the record type 02 (an extended segment address record).
* 1200 is the segment of the address.
* EA is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
When an extended segment address record is read, the extended segment address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The segment address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted-address data from the extended segment address record. The following example illustrates this process.
Address from the data record's address field 2462Extended segment address record data field 1200 --------Absolute memory address 00014462 Start Linear Address Records (MDK-ARM only)
Start linear address records specify the start address of the application. These records contain the full linear 32 bit address. The start linear address record always has four data bytes and appears as follows:
:04000005000000CD2A where:
* 04 is the number of data bytes in the record.
* 0000 is the address field. For the start linear address record, this field is always 0000.
* 05 is the record type 05 (a start linear address record).
* 000000CD is the 4 byte linear start address of the application.
* 2A is the checksum of the record and is calculated as
01h + NOT(04h + 00h + 00h + 05h + 00h + 00h + 00h + CDh).
The Start Linear Address specifies the address of the __main (pre-main) function but not the address of the startup code which usually calls __main after calling SystemInit(). An odd linear start address specifies that __main is compiled for the Thumb instruction set.
The Start Linear Address Record can appear anywhere in hex file. In most cases this record can be ignored because it does not contain information which is needed to program flash memory.
End-of-File (EOF) Records
An Intel HEX file must end with an end-of-file (EOF) record. This record must have the value 01 in the record type field. An EOF record always appears as follows:
:00000001FF where:
* 00 is the number of data bytes in the record.
* 0000 is the address where the data are to be located in memory. The address in end-of-file records is meaningless and is ignored. An address of 0000h is typical.
* 01 is the record type 01 (an end-of-file record).
* FF is the checksum of the record and is calculated as
01h + NOT(00h + 00h + 00h + 01h).
Example Intel HEX File
Following is an example of a complete Intel HEX file:
:10001300AC12AD13AE10AF1112002F8E0E8F0F2244:10000300E50B250DF509E50A350CF5081200132259:03000000020023D8:0C002300787FE4F6D8FD7581130200031D:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016:04003F00A42EFE22CB:00000001FF --------------------------------------------------------------------------------------
在IAR-ARM工程(比如STM32L4芯片,Cortext-M4)里输出程序文件的格式选项里是:Intel Extended Hex,就是Extended Linear Address Records (HEX386),里面有type 04的记录,能够表示的更大程序。
在Keil C51工程里,程序文件的输出格式是: HEX-80。这种程序较小,里面可能没有基地址设置命令。
遇到不同的HEX文件类型,是之里面的基地址设置方式不同,这只是Intel Hex文件格式的扩展。
"Intel Hex" is the name. "Hex-80" indicates that none of the extensions introduced for the 8086 (20-bit addresses) and/or the 386 (32-bit addresses) are used.
Hex文件类型全名:Intel hexadecimal object file format, Intel hex format or Intellec Hex。
实际上是将二进制文件转换成了ASCII码形式的文本文件,我们用文本编辑器打开hex文件,就可以看到里面的内容。
这种文件类型的目的就是为了烧写microcontroller, EPROMs和其他一些可编程逻辑器件。
总结
在使用IAR EWARM给项目设定输出文件类型时,就有一个Intel Extended Hex选项,这个就是指支持扩展记录类型的Hex文件。
一般就是使用00,01,04,05四个记录类型。
截取实际生成的hex文件举例:
:020000040800F2:10000000F0A10520B1FD030889EB03088BEB030881:100010008DEB03088FEB030891EB03080000000051:106EA0001C6014605C6021462B68104810229847D3:106EB0002B680F482146102298472B680D48214621。。。。。。:10C2E000FFF0FFF0FFF0FFF0FFF0FFF0FFF00000C5:10C2F000F0F000000000000000000000000000005E:0AC300000000000000000000000033:040000050803F8E113:00000001FF
------------------------------------------------------------------------------------ 数据分析举例: Record Format
An Intel HEX file is composed of any number of HEX records. Each record is made up of five fields that are arranged in the following format:
:llaaaatt[dd...]cc Each group of letters corresponds to a different field, and each letter represents a single hexadecimal digit. Each field is composed of at least two hexadecimal digits-which make up a byte-as described below:
* : is the colon that starts every Intel HEX record.
* ll is the record-length field that represents the number of data bytes (dd) in the record.
* aaaa is the address field that represents the starting address for subsequent data in the record.
* tt is the field that represents the HEX record type, which may be one of the following:
00 - data record
01 - end-of-file record
02 - extended segment address record
04 - extended linear address record
05 - start linear address record (MDK-ARM only)
* dd is a data field that represents one byte of data. A record may have multiple data bytes. The number of data bytes in the record must match the number specified by the ll field.
* cc is the checksum field that represents the checksum of the record. The checksum is calculated by summing the values of all hexadecimal digit pairs in the record modulo 256 and taking the two's complement. Data Records
The Intel HEX file is made up of any number of data records that are terminated with a carriage return and a linefeed. Data records appear as follows:
:10246200464C5549442050524F46494C4500464C33This record is decoded as follows::10246200464C5549442050524F46494C4500464C33||||||||||| CC->Checksum|||||||||DD->Data|||||||TT->Record Type|||AAAA->Address|LL->Record Length:->Colon where:
* 10 is the number of data bytes in the record.
* 2462 is the address where the data are to be located in memory.
* 00 is the record type 00 (a data record).
* 464C...464C is the data.
* 33 is the checksum of the record.
Extended Linear Address Records (HEX386)
Extended linear address records are also known as 32-bit address records and HEX386 records. These records contain the upper 16 bits (bits 16-31) of the data address. The extended linear address record always has two data bytes and appears as follows:
:02000004FFFFFC where:
* 02 is the number of data bytes in the record.
* 0000 is the address field. For the extended linear address record, this field is always 0000.
* 04 is the record type 04 (an extended linear address record).
* FFFF is the upper 16 bits of the address.
* FC is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
When an extended linear address record is read, the extended linear address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The linear address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted address data from the extended linear address record. The following example illustrates this process..
Address from the data record's address field 2462Extended linear address record data field FFFF --------Absolute-memory address FFFF2462 Extended Segment Address Records (HEX86)
Extended segment address records-also known as HEX86 records-contain bits 4-19 of the data address segment. The extended segment address record always has two data bytes and appears as follows:
:020000021200EA where:
* 02 is the number of data bytes in the record.
* 0000 is the address field. For the extended segment address record, this field is always 0000.
* 02 is the record type 02 (an extended segment address record).
* 1200 is the segment of the address.
* EA is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
When an extended segment address record is read, the extended segment address stored in the data field is saved and is applied to subsequent records read from the Intel HEX file. The segment address remains effective until changed by another extended address record.
The absolute-memory address of a data record is obtained by adding the address field in the record to the shifted-address data from the extended segment address record. The following example illustrates this process.
Address from the data record's address field 2462Extended segment address record data field 1200 --------Absolute memory address 00014462 Start Linear Address Records (MDK-ARM only)
Start linear address records specify the start address of the application. These records contain the full linear 32 bit address. The start linear address record always has four data bytes and appears as follows:
:04000005000000CD2A where:
* 04 is the number of data bytes in the record.
* 0000 is the address field. For the start linear address record, this field is always 0000.
* 05 is the record type 05 (a start linear address record).
* 000000CD is the 4 byte linear start address of the application.
* 2A is the checksum of the record and is calculated as
01h + NOT(04h + 00h + 00h + 05h + 00h + 00h + 00h + CDh).
The Start Linear Address specifies the address of the __main (pre-main) function but not the address of the startup code which usually calls __main after calling SystemInit(). An odd linear start address specifies that __main is compiled for the Thumb instruction set.
The Start Linear Address Record can appear anywhere in hex file. In most cases this record can be ignored because it does not contain information which is needed to program flash memory.
End-of-File (EOF) Records
An Intel HEX file must end with an end-of-file (EOF) record. This record must have the value 01 in the record type field. An EOF record always appears as follows:
:00000001FF where:
* 00 is the number of data bytes in the record.
* 0000 is the address where the data are to be located in memory. The address in end-of-file records is meaningless and is ignored. An address of 0000h is typical.
* 01 is the record type 01 (an end-of-file record).
* FF is the checksum of the record and is calculated as
01h + NOT(00h + 00h + 00h + 01h).
Example Intel HEX File
Following is an example of a complete Intel HEX file:
:10001300AC12AD13AE10AF1112002F8E0E8F0F2244:10000300E50B250DF509E50A350CF5081200132259:03000000020023D8:0C002300787FE4F6D8FD7581130200031D:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016:04003F00A42EFE22CB:00000001FF --------------------------------------------------------------------------------------
在IAR-ARM工程(比如STM32L4芯片,Cortext-M4)里输出程序文件的格式选项里是:Intel Extended Hex,就是Extended Linear Address Records (HEX386),里面有type 04的记录,能够表示的更大程序。
在Keil C51工程里,程序文件的输出格式是: HEX-80。这种程序较小,里面可能没有基地址设置命令。
遇到不同的HEX文件类型,是之里面的基地址设置方式不同,这只是Intel Hex文件格式的扩展。
"Intel Hex" is the name. "Hex-80" indicates that none of the extensions introduced for the 8086 (20-bit addresses) and/or the 386 (32-bit addresses) are used.