summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-06-09 20:30:21 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-06-09 20:31:55 (GMT)
commit0678128c26ec498168327358485d2905dd4665f4 (patch)
treed71a7d80ae946d091ba1b356df033cf68039b5a8 /tools
parentccaf12750ba39fe0bc1fa6d2425ef2d1831ded9a (diff)
tools: hex2c: Add crc32s for each segment
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hex2c.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/hex2c.py b/tools/hex2c.py
index eb4f34d..fa4762c 100755
--- a/tools/hex2c.py
+++ b/tools/hex2c.py
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson
+import binascii
import intelhex
import sys
@@ -14,6 +15,7 @@ def generate_c(ihex):
print('struct segment {')
print(' uint32_t start;');
print(' uint32_t end;');
+ print(' uint32_t crc32;')
print(' const uint8_t *data;')
print('};')
print()
@@ -29,7 +31,9 @@ def generate_c(ihex):
print('\n};\n')
print(f'const struct segment segments[] = {{')
for i, segment in enumerate(ihex.segments()):
- print(f' 0x{segment[0]:08x}, 0x{segment[1]:08x}, segment{i},')
+ sg = ihex.tobinarray(start=segment[0], end=segment[1]-1)
+ crc = binascii.crc32(sg)
+ print(f' 0x{segment[0]:08x}, 0x{segment[1]:08x}, 0x{crc:08x}, segment{i},')
print('};')
ihex = intelhex.IntelHex()