From dc4ea4ab6205bcdb27278367f7d5147b56cf78b8 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 26 Apr 2020 19:21:28 +0100 Subject: [PATCH] reloader: OTA flashing tool for wasp-os --- .gitmodules | 3 +++ Makefile | 2 ++ TODO.md | 6 +++--- reloader | 1 + tools/hex2c.py | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 160000 reloader create mode 100755 tools/hex2c.py diff --git a/.gitmodules b/.gitmodules index 20c2c34..91d8d9e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "tools/ota-dfu"] path = tools/ota-dfu url = https://github.com/daniel-thompson/ota-dfu-python +[submodule "reloader"] + path = reloader + url = https://github.com/daniel-thompson/wasp-reloader diff --git a/Makefile b/Makefile index f0fd8ff..50063a8 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,8 @@ bootloader: bootloader/_build-$(BOARD)_nrf52832/$(BOARD)_nrf52832_bootloader-*-nosd.hex \ bootloader/lib/softdevice/s132_nrf52_6.1.1/s132_nrf52_6.1.1_softdevice.hex \ -o bootloader.hex + python3 tools/hex2c.py bootloader.hex > \ + reloader/src/boards/$(BOARD)/bootloader.h softdevice: micropython/ports/nrf/drivers/bluetooth/download_ble_stack.sh diff --git a/TODO.md b/TODO.md index 52b3698..c3a77ca 100644 --- a/TODO.md +++ b/TODO.md @@ -46,7 +46,7 @@ applications. ### Bootloader - * [ ] OTA bootloader update + * [X] OTA bootloader update * [ ] Stay in bootloader after battery run down * [ ] Implement power off support (no splash screen) * [ ] RTC time measurement whilst in bootloader @@ -64,14 +64,14 @@ applications. * [X] Button driver (interrupt based) * [X] Touch sensor driver * [X] Event driven application framework - * [ ] Stopwatch app + * [X] Stopwatch app * [X] Settings app * [X] PC-hosted simulation platform * [.] Documentation - [X] Sphinx framework and integration with github.io - [ ] Document bootloader protocols - [ ] Write full docstring documentation for all WASP components - * [ ] Application Launcher + * [X] Application Launcher * [X] Debug notifications * [o] Multi-colour RLE images - [X] Optimized "2-bit" RLE encoder and decoder diff --git a/reloader b/reloader new file mode 160000 index 0000000..5e9a1c8 --- /dev/null +++ b/reloader @@ -0,0 +1 @@ +Subproject commit 5e9a1c85509130af123735aa550ef36b53f772b7 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 ') + 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)