Parse Intel HEX File

Medium Python Packaging Asked at Lattice Semiconductor
Solve this problem

Write a Python parser for Intel HEX records that returns a flat address-to-byte map, rejecting any record whose checksum does not verify.

Constraints

  • Support record types 00 (data), 01 (EOF) and 04 (extended linear address).
  • Checksum is the two's complement of the sum of all bytes in the record.
  • Raise ValueError on a bad checksum or an unknown record type.
  • Return a dict mapping absolute address to byte value.
  • Do not use the intelhex package.
Starter codePython
1def parse_hex(lines):2    """Return {address: byte} for an Intel HEX file given as a list of lines."""3    # TODO4    return {}