5.11.4 Normalize hex file

A hex file is normalized when line addresses are in incremental order and data is buffered to be one size (16 bytes), where possible.

For example, the following lines (records) are from the file myfile.hex, output from the MPLAB XC16 C compiler/linker:

:0801f800361e0000361e000057
:020000040000fa
:10020800361e0000361e0000361e0000361e000096

When this file is normalized, the file data looks like this:

:10022800361E0000361E0000361E0000361E000076
:10023800361E0000361E0000361E0000361E000066
:10024800361E0000361E0000361E0000361E000056

which is of the format:

:bbaaaarrdd...ddcc

where:

: Start record
bb Byte count
aaaa Address
rr Record type
dd Data
cc Checksum

In MPLAB X IDE, the application Hexmate is used to normalize Intel hex files. When the Normalize hex file option is checked, the following is called after a build:

hexmate myfile.hex -omyfile.hex

Essentially Hexmate unpacks the entire hex file and arranges the data at the addresses specified by the hex file. It then repackages the resulting memory image into a new hex file. In the resulting file, all the data is in ascending order and contiguous. If there is a gap in the addresses, then there will also be a gap in the output file (there is no filling of unused addresses).

For more information on using Hexmate, see MPLAB XC8 documentation or Hexmate User’s Guide (DS-50003033) on the Microchip website.

A normalized hex file is useful for programming code (such as a bootloader) over a serial connection, as the variation of record bytes is minimized.