fill.py 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. #
  3. """Fill unused areas of 32k ROM image with a recognizable pattern.
  4. Each 16 byte chunk is filled with:
  5. Address (2 bytes)
  6. 0x00
  7. 0x80
  8. 0x51
  9. 0x00
  10. "8051dumper"
  11. """
  12. import argparse
  13. import intelhex
  14. if __name__ == '__main__':
  15. parser = argparse.ArgumentParser(
  16. prog='fill.py',
  17. description=__doc__,
  18. formatter_class=argparse.RawDescriptionHelpFormatter)
  19. parser.add_argument('infile', metavar='INFILE')
  20. parser.add_argument('outfile', metavar='OUTFILE')
  21. args = parser.parse_args()
  22. fw_image = intelhex.IntelHex(args.infile)
  23. fill = list(b'\x00\x00\x00\x80\x51\x008051dumper' * int(32768/16))
  24. for n in range(0, len(fill), 16):
  25. fill[n] = n>>8
  26. fill[n+1] = n & 0xFF
  27. filled_image = intelhex.IntelHex()
  28. filled_image.frombytes(bytes(fill))
  29. filled_image.merge(fw_image, overlap='replace')
  30. filled_image.write_hex_file(args.outfile)