3.2.2 Postprocessing the Intel Hex file

In most cases this won't be needed but the Intel Hex file which is generated by SDCC might include lines of varying length and the addresses within the file are not guaranteed to be strictly ascending. If your toolchain or a bootloader does not like this you can use the tool packihx which is part of the SDCC distribution:

packihx sourcefile.ihx >sourcefile.hex

The separately available srecord package additionally allows to set undefined locations to a predefined value, to insert checksums of various flavours (crc, add, xor) and to perform other manipulations (convert, split, crop, offset, ...).

srec_cat  sourcefile.ihx -intel  -o sourcefile.hex -intel

An example for a more complex command linetypeset@protect @@footnote SF@gobble@opt the command backfills unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte block is zero. If the program counter on an mcs51 runs wild the backfill pattern 0x12 will be interpreted as an lcall to address 0x1212 (where an emergency routine could sit). could look like:

srec_cat sourcefile.ihx -intel  -fill 0x12 0x0000 0xfffe -little-endian-checksum-negative 0xfffe 0x02 0x02  -o sourcefile.hex -intel

The srecord package is available at http://sourceforge.net/projects/srecord/.