Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf47b71

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 containflash parameters and may be changed by flashing tool or MicroPython flashauto-config.
1 parenta621333 commitbf47b71

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
importsys
22
importstruct
3+
importhashlib
34

45
SEGS_MAX_SIZE=0x9000
56

67
assertlen(sys.argv)==4
78

9+
md5=hashlib.md5()
10+
811
withopen(sys.argv[3],'wb')asfout:
912

1013
withopen(sys.argv[1],'rb')asf:
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
withopen(sys.argv[2],'rb')asf:
@@ -18,10 +24,17 @@
1824
pad=b'\xff'* (SEGS_MAX_SIZE-len(data_flash))
1925
assertlen(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)

[8]ページ先頭

©2009-2025 Movatter.jp