|
1 | 1 | importsys |
2 | 2 | importstruct |
| 3 | +importhashlib |
3 | 4 |
|
4 | 5 | SEGS_MAX_SIZE=0x9000 |
5 | 6 |
|
6 | 7 | assertlen(sys.argv)==4 |
7 | 8 |
|
| 9 | +md5=hashlib.md5() |
| 10 | + |
8 | 11 | withopen(sys.argv[3],'wb')asfout: |
9 | 12 |
|
10 | 13 | withopen(sys.argv[1],'rb')asf: |
11 | 14 | data_flash=f.read() |
12 | 15 | fout.write(data_flash) |
| 16 | +# First 4 bytes include flash size, etc. which may be changed |
| 17 | +# by esptool.py, etc. |
| 18 | +md5.update(data_flash[4:]) |
13 | 19 | print('flash ',len(data_flash)) |
14 | 20 |
|
15 | 21 | withopen(sys.argv[2],'rb')asf: |
|
18 | 24 | pad=b'\xff'* (SEGS_MAX_SIZE-len(data_flash)) |
19 | 25 | assertlen(pad)>=4 |
20 | 26 | fout.write(pad[:-4]) |
21 | | -fout.write(struct.pack("I",SEGS_MAX_SIZE+len(data_rom))) |
| 27 | +md5.update(pad[:-4]) |
| 28 | +len_data=struct.pack("I",SEGS_MAX_SIZE+len(data_rom)) |
| 29 | +fout.write(len_data) |
| 30 | +md5.update(len_data) |
22 | 31 | print('padding ',len(pad)) |
23 | 32 |
|
24 | 33 | fout.write(data_rom) |
| 34 | +md5.update(data_rom) |
25 | 35 | print('irom0text',len(data_rom)) |
26 | 36 |
|
| 37 | +fout.write(md5.digest()) |
| 38 | + |
27 | 39 | print('total ',SEGS_MAX_SIZE+len(data_rom)) |
| 40 | +print('md5 ',md5.hexdigest()) |