Clever Geek Handbook
📜 ⬆️ ⬇️

Intel hex

Intel HEX is a file format designed to represent arbitrary binary data in text form. For historical reasons, it is the de facto standard when flashing a variety of memory chips ( microcontrollers , ROMs , EEPROM , etc.). Accordingly, most of the tools for preparing firmware images ( compilers , editors, viewers, etc.) can work with this format.

A file usually has a .hex extension. The names I8HEX, I16HEX and I32HEX are sometimes used to define the set of records used in a file. The I8HEX uses only entries with types 00/01 (16-bit addressing), the 02/03 (20-bit addressing) entries are added to the I16HEX, and the 04/05 (32-bit addressing) entries are added to I32HEX.

The advantage of the format (unlike simple binary) is the ability to specify only certain areas of the address (up to a byte ). Many microcontroller architectures have several programming areas with vast voids in the addressing between them.

Content

Record Format

Explanation One

The file consists of ASCII text strings. Each row represents one entry. Each entry begins with a colon ( :) , followed by a set of hexadecimal digits multiple of a byte :

  • Start recording ( :) .
  • The number of bytes of data contained in this record. It occupies one byte (two hexadecimal digits), which corresponds to 0 ... 255 in the decimal system .
  • The starting address of the block of recorded data is 2 bytes. This address defines the absolute location of the data for this entry in the binary.
  • One byte indicating the type of record. The following record types are defined:
    • 0 - the record contains binary file data.
    • 1 - the record indicates the end of the file , contains no data. Has the characteristic appearance of ": 00000001FF".
    • 2 - record the segment address (see below for more details).
    • 4 - record of the extended address (see below for more details).
  • Bytes of data to be stored in EPROM (their number is indicated at the beginning of recording, from 0 to 255 bytes).
  • The last byte in the record is the checksum . It is calculated so that the sum of all bytes in the record is 0.
  • The line ends with a standard CR / LF pair (0Dh 0Ah).

Explanation Two

An Intel HEX file can consist of any number of records. Each entry is an ASCII string consisting of several pairs of hexadecimal digits. The line must begin with a colon and end with a pair of CR and LF characters. A record consists of five fields in the following format:
: LLAAAATTDD ... CC
Each group of letters (LL, AAAA, TT, etc.) represents a separate field. Each letter is a separate hexadecimal digit (4 bits). Each field consists of at least two hexadecimal digits (one byte). The following is a description of the record fields:

  • : Each entry in the Intel HEX file must begin with a colon.
  • LL Length field - indicates the number of data bytes (DD) in the record.
  • AAAA Address Field — Represents the starting address of the entry.
  • TT Type field. It can take the following values:
    • 00 record contains binary file data.
    • 01 record is the end of the file.
    • 02 record the segment address (see below for more details).
    • 03 Start Segment Address Record.
    • 04 record of the extended address (for more details see below).
    • 05 Start Linear Address Record.
  • DD Data field. A record can contain several bytes of data. The number of data bytes must correspond to the LL field.
  • CC Checksum field. The checksum field is calculated by adding the values ​​of all bytes (pairs of hexadecimal digits) of the record modulo 256, followed by conversion to an additional format (subtract the resulting value from 0). Thus, if you sum up all pairs of hexadecimal numbers, including LL, AA, TT, DD, CC, you get 0.

Record segment address

An Intel HEX file may contain entries for Intel 8086 processors that determine the segment address (in other words, the paragraph number, one paragraph is 16 bytes). If the H167 directive is used, then this type of entry replaces the extended linear address entry. The paragraph number is used as the address offset for all data records following this record. An offset is an address shift of four bits to the left. For example, an offset of 0x1234 will give the real address 0x12340. Record Example:
: 020000021000EC where:

  • 02 Number of data bytes
  • 0000 In this type of record is always equal to 0000
  • 02 Record type 02 (segment address record).
  • 1000 Paragraph number (real address will be 0x10000).
  • EC Checksum

Extended Address Record

When the H167 directive is used, the Intel HEX format file may possibly contain extended linear address entries. This type of record determines the values ​​of the two high bytes of the absolute address (bits 16-31). These two high-order bytes of the address will be used as the address offset for all data records following this record. Record Example:
: 0200000400FFFB
Where:

  • 02 Number of data bytes
  • 0000 is always 0
  • 04 Record type 04 (extended linear address record)
  • 00FF High address offset word (0x00FF0000)
  • FB Checksum

Write end of file

Intel HEX format files must have a File End Record (EOF). Example record:
: 00000001FF where:

  • 00 Number of bytes of recording
  • 0000 The field is ignored. It does not matter what is written there, but usually always 0
  • 01 Record Type 01 (End of File)
  • FF Checksum calculated as 01h + NOT (00h + 00h + 00h + 01h).

Examples

Example 1

  : 10 0100 00 214601360121470136007EFE09D21901 40
 : 10 0110 00 2146017EB7C20001FF5F160021480119 88
 : 10 0120 00 194E79234623965778239EDA3F01B2CA A7
 : 10 0130 00 3F0156702B5E712B722B732146013421 C7
 : 00 0000 01 FF

     Start recording      The number of data bytes in this record (row)      The address where the data of this record is placed      Record type      Data      Write checksum

Example 2

Example of a single data record:
: 10246200464C5549442050524F46494C4500464C33 where

  • 10 Number of data bytes (16 bytes)
  • 2462 The memory address where the record will be placed.
  • 00 Type of record - data.
  • 464C ... 464C Data
  • 33 Write checksum

Example 3

  : 020000021000EC
 : 10C20000E0A5E6F6FDFFE0AEE00FE6FCFDFFE6FD93
 : 10C21000FFFFF6F50EFE4B66F2FA0CFEF2F40EFE90
 : 10C22000F04EF05FF06CF07DCA0050C2F086F097DF
 : 10C23000F04AF054BCF5204830592D02E018BB03F9
 : 020000020000FC
 : 04000000FA00000200
 : 00000001FF 

See also

SREC - file format used by Motorola

Links

  • Intel HEX File Format Specification
  • Intel HEX-record Format
Source - https://ru.wikipedia.org/w/index.php?title=Intel_HEX&oldid=99122556


More articles:

  • Metal (Annihilator album)
  • Verkhnemaktaminskoye rural settlement
  • Kichuy rural settlement
  • Mametyevskoye Rural Settlement
  • Arc Protection
  • Seleckis, Ivar
  • Tandrevold Ingrid
  • The nitrogen cycle
  • Tatiana Park
  • Etudes about Vrubel

All articles

Clever Geek | 2019