Skip to content

Commit 28531b7

Browse files
committed
Add wasp-reloader as a git submodule.
Convert the .bin file in hex and then in .h file for the reloader. Build the reloader to generate the DFU file that will allow to upgrade the bootloader on a PineTime
1 parent 3c83d8a commit 28531b7

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ libftdi1*.bz2
4747
libusb*/
4848
hidapi*/
4949
.idea/*
50+
51+
/reloader/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "reloader"]
2+
path = reloader
3+
url = [email protected]:daniel-thompson/wasp-reloader.git

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ The goal of this firmware is to provide a mean for the user to OTA a new firmwar
6868

6969
- Install `newt` tool
7070
- Clone the project and `cd` into it
71+
- Init and update submodules : `git submodule update --init --recursive`
7172
- Configure mynewt : `newt upgrade`
72-
- Build : `scripts/nrf52/build-boot.sh`. The firmware is generated in `bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf`
73+
- Build : `scripts/nrf52/build-boot.sh`. The firmware is generated in `bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf` and the DFU file for the reloader : `reloader/build-pinetime/reloader-mcuboot.zip`
7374

7475
## About the code
7576

scripts/hex2c.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-License-Identifier: LGPL-3.0-or-later
4+
# Copyright (C) 2020 Daniel Thompson
5+
6+
import binascii
7+
import intelhex
8+
import sys
9+
10+
def generate_c(ihex):
11+
print('/* this file is auto-generated - DO NOT EDIT */')
12+
print()
13+
print('#include <stdint.h>')
14+
print()
15+
print('struct segment {')
16+
print(' uint32_t start;');
17+
print(' uint32_t end;');
18+
print(' uint32_t crc32;')
19+
print(' const uint8_t *data;')
20+
print('};')
21+
print()
22+
23+
segments = []
24+
chunk = 32 * 1024
25+
for (start, end) in ihex.segments():
26+
while start + chunk < end:
27+
segments.append((start, start + chunk))
28+
start += chunk
29+
if start < end:
30+
segments.append((start, end))
31+
32+
for i, segment in enumerate(segments):
33+
print(f'static const uint8_t segment{i}[] = {{', end='')
34+
35+
for j in range(segment[0], segment[1]):
36+
if 0 == j % 12:
37+
print('\n ', end='')
38+
print(f' 0x{ihex[j]:02x},', end='')
39+
40+
print('\n};\n')
41+
print(f'const struct segment segments[] = {{')
42+
for i, segment in enumerate(segments):
43+
sg = ihex.tobinarray(start=segment[0], end=segment[1]-1)
44+
crc = binascii.crc32(sg)
45+
print(f' 0x{segment[0]:08x}, 0x{segment[1]:08x}, 0x{crc:08x}, segment{i},')
46+
print('};')
47+
48+
ihex = intelhex.IntelHex()
49+
ihex.loadhex(sys.argv[1])
50+
generate_c(ihex)

scripts/nrf52/build-boot.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ newt build nrf52_boot
1313
# Show the size.
1414
newt size -v nrf52_boot
1515

16-
# Copy the disassembler and linker map to the logs folder. For Stub Bootloader, select "bin/targets/nrf52_boot/app/apps/boot_stub/boot_stub.elf.*"
17-
cp bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.lst logs
18-
cp bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.map logs
16+
arm-none-eabi-objcopy -I binary -O ihex bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.bin bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.hex
17+
scripts/hex2c.py bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.hex > reloader/src/boards/pinetime/bootloader.h
18+
make -C reloader BOARD=pinetime
19+
20+
set +x
21+
echo "Bootloader firmware (elf) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf"
22+
echo "Bootloader firmware (bin) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.bin"
23+
echo "Bootloader firmware (hex) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.hex"
24+
echo "Reloader (DFU) : reloader/build-pinetime/reloader-mcuboot.zip"

0 commit comments

Comments
 (0)