From 9dd793ff1951d1781765dabf0a61143a3b6cd972 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Wed, 4 Nov 2020 19:06:03 +0000 Subject: [PATCH] hex2c.py: Adopt a maximum chunk size Large segments will be chunked into 32K blocks to they can be handled seperate. Creating a maximum chunk size allows us to perform a few tricks in the reloader by allowing us to overwrite parts of the reloader whilst it is running! Signed-off-by: Daniel Thompson --- tools/hex2c.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/hex2c.py b/tools/hex2c.py index fa4762c..74f8431 100755 --- a/tools/hex2c.py +++ b/tools/hex2c.py @@ -20,7 +20,16 @@ def generate_c(ihex): print('};') print() - for i, segment in enumerate(ihex.segments()): + segments = [] + chunk = 32 * 1024 + for (start, end) in ihex.segments(): + while start + chunk < end: + segments.append((start, start + chunk)) + start += chunk + if start < end: + segments.append((start, end)) + + for i, segment in enumerate(segments): print(f'static const uint8_t segment{i}[] = {{', end='') for j in range(segment[0], segment[1]): @@ -30,7 +39,7 @@ def generate_c(ihex): print('\n};\n') print(f'const struct segment segments[] = {{') - for i, segment in enumerate(ihex.segments()): + for i, segment in enumerate(segments): 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},')