summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-08-04 00:21:05 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-08-04 00:21:05 +0300
commitbf47b71b787657eca1d489f92517aa60c9a38008 (patch)
treebb311c9215bb436f33a8102eced0fd352935788e /esp8266
parenta621333a4c4fcc161f076980c9147faa555de5de (diff)
downloadmicropython-bf47b71b787657eca1d489f92517aa60c9a38008.tar.gz
micropython-bf47b71b787657eca1d489f92517aa60c9a38008.zip
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.
Diffstat (limited to 'esp8266')
-rw-r--r--esp8266/makeimg.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/esp8266/makeimg.py b/esp8266/makeimg.py
index 834f778c84..091854fa4d 100644
--- a/esp8266/makeimg.py
+++ b/esp8266/makeimg.py
@@ -1,15 +1,21 @@
import sys
import struct
+import hashlib
SEGS_MAX_SIZE = 0x9000
assert len(sys.argv) == 4
+md5 = hashlib.md5()
+
with open(sys.argv[3], 'wb') as fout:
with open(sys.argv[1], 'rb') as f:
data_flash = f.read()
fout.write(data_flash)
+ # First 4 bytes include flash size, etc. which may be changed
+ # by esptool.py, etc.
+ md5.update(data_flash[4:])
print('flash ', len(data_flash))
with open(sys.argv[2], 'rb') as f:
@@ -18,10 +24,17 @@ with open(sys.argv[3], 'wb') as fout:
pad = b'\xff' * (SEGS_MAX_SIZE - len(data_flash))
assert len(pad) >= 4
fout.write(pad[:-4])
- fout.write(struct.pack("I", SEGS_MAX_SIZE + len(data_rom)))
+ md5.update(pad[:-4])
+ len_data = struct.pack("I", SEGS_MAX_SIZE + len(data_rom))
+ fout.write(len_data)
+ md5.update(len_data)
print('padding ', len(pad))
fout.write(data_rom)
+ md5.update(data_rom)
print('irom0text', len(data_rom))
+ fout.write(md5.digest())
+
print('total ', SEGS_MAX_SIZE + len(data_rom))
+ print('md5 ', md5.hexdigest())