Skip to content

Commit

Permalink
boards: Add particle-xenon with riotboot support
Browse files Browse the repository at this point in the history
Co-authored-by: Kaspar Schleiser <[email protected]>
  • Loading branch information
chrysn and kaspar030 committed Apr 8, 2024
1 parent 5d8f1ae commit c1f6d3b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
44 changes: 44 additions & 0 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ contexts:
flash-riotboot:
required_vars:
- FLASH_OFFSET
- FLASH_SLOT_OFFSET
cmd:
- riotboot-genhdr generate ${out} $$(date +%s) $(${FLASH_OFFSET} + ${FLASH_SLOT_OFFSET}) ${FLASH_SLOT_OFFSET} - > ${out}.hdr.bin
- ${OBJCOPY} -Obinary ${out} ${out}.bin
Expand Down Expand Up @@ -520,6 +521,17 @@ modules:
FEATURES:
- riot-rs/wifi-esp

- name: runner-riotboot-dfu
required_vars:
- FLASH_OFFSET
- FLASH_SLOT_OFFSET
- FLASH_SIZE_TOTAL
- FLASH_SLOT
- FLASH_NUM_SLOTS
env:
global:
CARGO_RUNNER: "${SCRIPTS}/runner-riotboot.sh\\ ${FLASH_OFFSET}\\ ${FLASH_SLOT_OFFSET}\\ ${FLASH_SIZE_TOTAL}\\ ${FLASH_SLOT}\\ ${FLASH_NUM_SLOTS}"

builders:
# host builder (for housekeeping tasks)
- name: host
Expand Down Expand Up @@ -594,6 +606,38 @@ builders:
- name: particle-xenon
parent: nrf52840

- name: _particle-xenon-riotboot-dfu
parent: particle-xenon
env:
# Bootloader size. This is why the board is riotboot-dfu: The version
# without DFU needs less flash for the bootloader.
FLASH_OFFSET: "0x4000"
# Size of image header
FLASH_SLOT_OFFSET: "0x400"
# This is default for nrf52/build.rs anyway, but runner-riotbuild needs
# the information explicitly.
FLASH_NUM_SLOTS: "2"
# FIXME: This information ("The nrf52840 has 1024KiB of flash") is
# duplicated between here and src/riot-rs-boards/nrf52/build.rs.
FLASH_SIZE_TOTAL: "1048576"
CARGO_ENV:
- NRF52_FLASH_OFFSET=${FLASH_OFFSET}
- NRF52_FLASH_SLOT_OFFSET=${FLASH_SLOT_OFFSET}
- NRF52_FLASH_SLOT=${FLASH_SLOT}
- NRF52_FLASH_NUM_SLOTS=${FLASH_NUM_SLOTS}
selects:
- runner-riotboot-dfu

- name: particle-xenon-riotboot-dfu-slot0
parent: _particle-xenon-riotboot-dfu
env:
FLASH_SLOT: "0"

- name: particle-xenon-riotboot-dfu-slot1
parent: _particle-xenon-riotboot-dfu
env:
FLASH_SLOT: "1"

- name: rpi-pico
parent: rp2040
env:
Expand Down
37 changes: 37 additions & 0 deletions scripts/runner-riotboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

# Take an image built merely with the right offsets (and possibly higher leve
# riotboot functionality such as reboot-into-bootloader), send it through
# riotboot-genhdr, and flash it using dfu-util.
#
# It may be practical to split this into a build-image-from-elf and a
# flash-image step using laze, but right now this works.

set -e

FLASH_OFFSET="$1"
FLASH_SLOT_OFFSET="$2"
FLASH_SIZE_TOTAL="$3"
FLASH_SLOT="$4"
FLASH_NUM_SLOTS="$5"
BUILT_ELF="$6"

IMAGE="${BUILT_ELF}.img"
VERSION=$(date +%s)

# FIXME: How do we best access this, if not by asking the user to get a RIOT
# checkout and place its dist/tools/riotboot_gen_hdr/bin/ in the PATH?
GENHDR=genhdr

objcopy "${BUILT_ELF}" -Obinary "${BUILT_ELF}.bin"

${GENHDR} generate \
"${BUILT_ELF}.bin" \
${VERSION} \
$((${FLASH_OFFSET} + (${FLASH_SIZE_TOTAL} - ${FLASH_OFFSET}) / ${FLASH_NUM_SLOTS} * ${FLASH_SLOT} + ${FLASH_SLOT_OFFSET})) \
${FLASH_SLOT_OFFSET} \
"${BUILT_ELF}.riotboot"

cat "${BUILT_ELF}.riotboot" "${BUILT_ELF}.bin" > "${IMAGE}"

dfu-util --device 1209:7d02 --alt ${FLASH_SLOT} --download "${IMAGE}"
3 changes: 3 additions & 0 deletions src/riot-rs-boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ particle-xenon = { optional = true, path = "particle-xenon" }
# Allows to have no boards selected, useful to run platform-independent tooling
no-boards = []
rpi-pico-w = ["rpi-pico/rpi-pico-w"]

particle-xenon-riotboot-dfu-slot0 = [ "particle-xenon" ]
particle-xenon-riotboot-dfu-slot1 = [ "particle-xenon" ]

0 comments on commit c1f6d3b

Please sign in to comment.