diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-26 18:21:28 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-26 18:21:28 (GMT) |
| commit | dc4ea4ab6205bcdb27278367f7d5147b56cf78b8 (patch) | |
| tree | 75f4e312f2ad624025d6b71603f1b1be4feec896 /tools | |
| parent | 17a8cfc34638d14167d33c1f2b094813446e5c5b (diff) | |
reloader: OTA flashing tool for wasp-os
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/hex2c.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/hex2c.py b/tools/hex2c.py new file mode 100755 index 0000000..eb4f34d --- /dev/null +++ b/tools/hex2c.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (C) 2020 Daniel Thompson + +import intelhex +import sys + +def generate_c(ihex): + print('/* this file is auto-generated - DO NOT EDIT */') + print() + print('#include <stdint.h>') + print() + print('struct segment {') + print(' uint32_t start;'); + print(' uint32_t end;'); + print(' const uint8_t *data;') + print('};') + print() + + for i, segment in enumerate(ihex.segments()): + print(f'static const uint8_t segment{i}[] = {{', end='') + + for j in range(segment[0], segment[1]): + if 0 == j % 12: + print('\n ', end='') + print(f' 0x{ihex[j]:02x},', end='') + + 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},') + print('};') + +ihex = intelhex.IntelHex() +ihex.loadhex(sys.argv[1]) +generate_c(ihex) |
