2018-03-11 14:58:11 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from hashlib import sha256
|
|
|
|
|
2019-04-23 19:23:52 +00:00
|
|
|
fn = "bootloader.dat"
|
2018-03-11 14:58:11 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
data = open(fn, "rb").read()
|
2018-03-11 14:58:11 +00:00
|
|
|
if len(data) > 32768:
|
2019-04-18 14:27:27 +00:00
|
|
|
raise Exception("bootloader has to be smaller than 32768 bytes")
|
2018-03-11 14:58:11 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
data += b"\x00" * (32768 - len(data))
|
2018-03-11 14:58:11 +00:00
|
|
|
|
|
|
|
h = sha256(sha256(data).digest()).digest()
|
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
bl_hash = ", ".join("0x%02x" % x for x in bytearray(h))
|
|
|
|
bl_data = ", ".join("0x%02x" % x for x in bytearray(data))
|
2018-03-11 14:58:11 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
with open("bl_data.h", "wt") as f:
|
|
|
|
f.write("static const uint8_t bl_hash[32] = {%s};\n" % bl_hash)
|
|
|
|
f.write("static const uint8_t bl_data[32768] = {%s};\n" % bl_data)
|