2014-11-27 15:30:33 -05:00
|
|
|
import sys
|
2016-08-03 17:19:09 -04:00
|
|
|
import struct
|
2016-08-03 17:21:05 -04:00
|
|
|
import hashlib
|
2014-11-27 15:30:33 -05:00
|
|
|
|
2016-04-03 08:40:53 -04:00
|
|
|
SEGS_MAX_SIZE = 0x9000
|
|
|
|
|
2014-11-27 15:30:33 -05:00
|
|
|
assert len(sys.argv) == 4
|
|
|
|
|
2016-08-03 17:21:05 -04:00
|
|
|
md5 = hashlib.md5()
|
|
|
|
|
2014-11-27 15:30:33 -05:00
|
|
|
with open(sys.argv[3], 'wb') as fout:
|
|
|
|
|
|
|
|
with open(sys.argv[1], 'rb') as f:
|
|
|
|
data_flash = f.read()
|
|
|
|
fout.write(data_flash)
|
2016-08-03 17:21:05 -04:00
|
|
|
# First 4 bytes include flash size, etc. which may be changed
|
|
|
|
# by esptool.py, etc.
|
|
|
|
md5.update(data_flash[4:])
|
2014-11-27 15:30:33 -05:00
|
|
|
print('flash ', len(data_flash))
|
|
|
|
|
2016-08-03 17:19:09 -04:00
|
|
|
with open(sys.argv[2], 'rb') as f:
|
|
|
|
data_rom = f.read()
|
|
|
|
|
2016-04-03 08:40:53 -04:00
|
|
|
pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
|
2016-08-03 17:19:09 -04:00
|
|
|
assert len(pad) >= 4
|
|
|
|
fout.write(pad[:-4])
|
2016-08-03 17:21:05 -04:00
|
|
|
md5.update(pad[:-4])
|
|
|
|
len_data = struct.pack("I", SEGS_MAX_SIZE + len(data_rom))
|
|
|
|
fout.write(len_data)
|
|
|
|
md5.update(len_data)
|
2014-11-27 15:30:33 -05:00
|
|
|
print('padding ', len(pad))
|
|
|
|
|
2016-08-03 17:19:09 -04:00
|
|
|
fout.write(data_rom)
|
2016-08-03 17:21:05 -04:00
|
|
|
md5.update(data_rom)
|
2016-08-03 17:19:09 -04:00
|
|
|
print('irom0text', len(data_rom))
|
2014-11-27 15:30:33 -05:00
|
|
|
|
2016-08-03 17:21:05 -04:00
|
|
|
fout.write(md5.digest())
|
|
|
|
|
2016-04-03 08:40:53 -04:00
|
|
|
print('total ', SEGS_MAX_SIZE + len(data_rom))
|
2016-08-03 17:21:05 -04:00
|
|
|
print('md5 ', md5.hexdigest())
|