Skip to content

Commit 9a3a46b

Browse files
committed
Adding python tool for extending a binary firmware file with the length and checksum as the start as required for OTA update
1 parent 67b82fb commit 9a3a46b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

extras/tools/bin2ota.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import crccheck
5+
6+
if len(sys.argv) != 3:
7+
print ("Usage: bin2ota.py sketch.bin sketch-ota.bin")
8+
sys.exit()
9+
10+
ifile = sys.argv[1]
11+
ofile = sys.argv[2]
12+
13+
# Read the binary file
14+
in_file = open(ifile, "rb")
15+
bin_data = bytearray(in_file.read())
16+
in_file.close()
17+
18+
# Calculate length and CRC32
19+
bin_data_len = len(bin_data)
20+
bin_data_crc = crccheck.crc.Crc32.calc(bin_data)
21+
22+
# Write to outfile
23+
out_file = open(ofile, "wb")
24+
out_file.write((bin_data_len).to_bytes(4,byteorder='little'))
25+
out_file.write((bin_data_crc).to_bytes(4,byteorder='little'))
26+
out_file.write(bin_data)
27+
out_file.close()

0 commit comments

Comments
 (0)