Skip to content

Commit bf47b71

Browse files
committed
esp8266/makeimg.py: Append md5 hash to the generated binary.
md5 is calculated over the entire file, except first 4 bytes, which contain flash parameters and may be changed by flashing tool or MicroPython flash auto-config.
1 parent a621333 commit bf47b71

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

esp8266/makeimg.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import sys
22
import struct
3+
import hashlib
34

45
SEGS_MAX_SIZE = 0x9000
56

67
assert len(sys.argv) == 4
78

9+
md5 = hashlib.md5()
10+
811
with open(sys.argv[3], 'wb') as fout:
912

1013
with open(sys.argv[1], 'rb') as f:
1114
data_flash = f.read()
1215
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:])
1319
print('flash ', len(data_flash))
1420

1521
with open(sys.argv[2], 'rb') as f:
@@ -18,10 +24,17 @@
1824
pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
1925
assert len(pad) >= 4
2026
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)
2231
print('padding ', len(pad))
2332

2433
fout.write(data_rom)
34+
md5.update(data_rom)
2535
print('irom0text', len(data_rom))
2636

37+
fout.write(md5.digest())
38+
2739
print('total ', SEGS_MAX_SIZE + len(data_rom))
40+
print('md5 ', md5.hexdigest())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy