.HEX
Intel HEX firmware
Introduction
Intel HEX is a text format for binary data that is to be written into memory, most often the firmware for a microcontroller. Each line is one record: a run of bytes, written as hexadecimal digits, with the address they belong at and a checksum. Because it is plain text with addresses, a HEX file can describe memory with gaps in it and survive being sent over links that only carry text.
Toolchains for AVR, PIC, ARM Cortex-M and many other chips produce it. The SDCC
compiler names its output .ihx.
Software
- Arduino IDE, which builds and uploads them (Windows, macOS, Linux)
- AVRDUDE (Windows, macOS, Linux)
- STM32CubeProgrammer (Windows, macOS, Linux)
- GNU Binutils, whose
objcopyconverts to and from binary (Windows, macOS, Linux) - SRecord (Windows, macOS, Linux)
Structure
Every record is one line that starts with a colon. After it come pairs of hexadecimal digits: the number of data bytes, a 16-bit address, the record type, the data bytes and a checksum. The checksum is chosen so that all the bytes of the record, added together, come to zero in their lowest eight bits.
Six record types exist. Type 00 is data and 01 marks the end
of the file. Because a record address is only 16 bits, types 02 and
04 set an upper part that applies to the records after them, giving 20-bit
or 32-bit addresses. Types 03 and 05 give the start address.
:10010000214601360121470136007EFE09D2190140
:100110002146017E17C20001FF5F16002148011928
:00000001FF
0start code:1 character1byte count, the number of data bytes2 digits3address4 digits7record type: 00 data, 01 end, 02 to 05 addresses2 digits9data2 digits per byte…checksum2 digits