|
@@ -1,11 +1,18 @@
|
|
|
# mk_update.py
|
|
|
#
|
|
|
-# Convert a raw firmware binary into an update file for our bootloader:
|
|
|
-# N bytes: <raw binary data>
|
|
|
-# 2 bytes: 'GW'
|
|
|
-# 2 bytes: major, minor
|
|
|
-# 2 bytes: 0, 0
|
|
|
-# 2 bytes: CRC16-CCITT, seed 0xFFFF, stored big endian
|
|
|
+# Convert a raw firmware binary into an update file for our bootloader.
|
|
|
+#
|
|
|
+# Update Format (Little endian, unless otherwise stated):
|
|
|
+# Catalogue Header:
|
|
|
+# 2 bytes: <length> (excludes Catalogue Header)
|
|
|
+# 2 bytes: <hw_type>
|
|
|
+# Payload:
|
|
|
+# N bytes: <raw binary data>
|
|
|
+# Footer:
|
|
|
+# 2 bytes: 'GW'
|
|
|
+# 2 bytes: major, minor
|
|
|
+# 2 bytes: <hw_type>
|
|
|
+# 2 bytes: CRC16-CCITT, seed 0xFFFF (big endian, excludes Catalogue Header)
|
|
|
#
|
|
|
# Written & released by Keir Fraser <keir.xen@gmail.com>
|
|
|
#
|
|
@@ -13,20 +20,22 @@
|
|
|
# See the file COPYING for more details, or visit <http://unlicense.org>.
|
|
|
|
|
|
import crcmod.predefined
|
|
|
-import struct, sys
|
|
|
+import re, struct, sys
|
|
|
|
|
|
from greaseweazle import version
|
|
|
|
|
|
def main(argv):
|
|
|
in_f = open(argv[1], "rb")
|
|
|
out_f = open(argv[2], "wb")
|
|
|
+ hw_type = int(re.match("f(\d)", argv[3]).group(1))
|
|
|
in_dat = in_f.read()
|
|
|
in_len = len(in_dat)
|
|
|
assert (in_len & 3) == 0, "input is not longword padded"
|
|
|
crc16 = crcmod.predefined.Crc('crc-ccitt-false')
|
|
|
+ out_f.write(struct.pack("<2H", in_len + 8, hw_type))
|
|
|
out_f.write(in_dat)
|
|
|
crc16.update(in_dat)
|
|
|
- in_dat = struct.pack("2s4B", b'GW', version.major, version.minor, 0, 0)
|
|
|
+ in_dat = struct.pack("<2s2BH", b'GW', version.major, version.minor, hw_type)
|
|
|
out_f.write(in_dat)
|
|
|
crc16.update(in_dat)
|
|
|
in_dat = struct.pack(">H", crc16.crcValue)
|