makeimg.py 753 B

12345678910111213141516171819202122232425
  1. import sys
  2. OFFSET_BOOTLOADER = 0x1000
  3. OFFSET_PARTITIONS = 0x8000
  4. OFFSET_APPLICATION = 0x10000
  5. files_in = [
  6. ('bootloader', OFFSET_BOOTLOADER, sys.argv[1]),
  7. ('partitions', OFFSET_PARTITIONS, sys.argv[2]),
  8. ('application', OFFSET_APPLICATION, sys.argv[3]),
  9. ]
  10. file_out = sys.argv[4]
  11. cur_offset = OFFSET_BOOTLOADER
  12. with open(file_out, 'wb') as fout:
  13. for name, offset, file_in in files_in:
  14. assert offset >= cur_offset
  15. fout.write(b'\xff' * (offset - cur_offset))
  16. cur_offset = offset
  17. with open(file_in, 'rb') as fin:
  18. data = fin.read()
  19. fout.write(data)
  20. cur_offset += len(data)
  21. print('%-12s% 8d' % (name, len(data)))
  22. print('%-12s% 8d' % ('total', cur_offset))