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 <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
8e89e38175
commit
9dd793ff19
1 changed files with 11 additions and 2 deletions
|
@ -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},')
|
||||
|
|
Loading…
Reference in a new issue