Skip to content

Commit

Permalink
Add wasp-reloader as a git submodule.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JF002 committed Dec 22, 2020
1 parent 3c83d8a commit 28531b7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ libftdi1*.bz2
libusb*/
hidapi*/
.idea/*

/reloader/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "reloader"]
path = reloader
url = [email protected]:daniel-thompson/wasp-reloader.git
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ The goal of this firmware is to provide a mean for the user to OTA a new firmwar

- Install `newt` tool
- Clone the project and `cd` into it
- Init and update submodules : `git submodule update --init --recursive`
- Configure mynewt : `newt upgrade`
- Build : `scripts/nrf52/build-boot.sh`. The firmware is generated in `bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf`
- 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`

## About the code

Expand Down
50 changes: 50 additions & 0 deletions scripts/hex2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson

import binascii
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(' uint32_t crc32;')
print(' const uint8_t *data;')
print('};')
print()

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]):
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(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},')
print('};')

ihex = intelhex.IntelHex()
ihex.loadhex(sys.argv[1])
generate_c(ihex)
12 changes: 9 additions & 3 deletions scripts/nrf52/build-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ newt build nrf52_boot
# Show the size.
newt size -v nrf52_boot

# 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.*"
cp bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.lst logs
cp bin/targets/nrf52_boot/app/boot/mynewt/mynewt.elf.map logs
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
scripts/hex2c.py bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf.hex > reloader/src/boards/pinetime/bootloader.h
make -C reloader BOARD=pinetime

set +x
echo "Bootloader firmware (elf) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.elf"
echo "Bootloader firmware (bin) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.bin"
echo "Bootloader firmware (hex) : bin/targets/nrf52_boot/app/@mcuboot/boot/mynewt/mynewt.hex"
echo "Reloader (DFU) : reloader/build-pinetime/reloader-mcuboot.zip"

0 comments on commit 28531b7

Please sign in to comment.