Skip to content

sys/riotboot/flashwrite: unaligned write when skipping RIOTBOOT_MAGIC on stm32wb #15917

@fjmolinas

Description

@fjmolinas

Description

While testing #15914 I realized that riotboot/flashwrite has been broken on stm32wb for a while. It seems to be caused by the following sections:

#if CONFIG_RIOTBOOT_FLASHWRITE_RAW /* Guards access to state::firstblock_buf */
void * addr = flashpage_addr(state->flashpage);
if (addr == riotboot_slot_get_hdr(state->target_slot) &&
state->offset == RIOTBOOT_FLASHPAGE_BUFFER_SIZE) {
/* Skip flashing the first block, store it for later to flash it
* during the flashwrite_finish function */
memcpy(state->firstblock_buf,
state->flashpage_buf, RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
}
else {
flashpage_write((uint8_t*)addr + flashpage_pos,
state->flashpage_buf,
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
}
#else

The offset is initially set to 4 and when the required alignment is 8. Weirdly enough I only get this error with stm32wb and not with stm32l4.

Steps to reproduce the issue

Any application using riotboot/flashwrite so examples/suit_udpate or tests/riotboot_flashwrite. #15559 can be used to reproduce in any case:

  • sudo ./dist/tools/ethos/setup_network.sh riot0 2001:db8::/64
  • make -C <examples/suit_update or tests/riotboot_flashwrite> flash test-with-config

Expected results

Test passes

Actual results

          inet6 addr: fe80::2  scope: link  VAL
          inet6 group: ff02::2
          inet6 group: ff02::1
          inet6 group: ff02::1:fff0:17c1
          inet6 group: ff02::1:ff00:2
          
> _flashwrite_handler(): received data: offset=0 len=64 blockwise=1 more=1
_flashwrite_handler(): init len=64
riotboot_flashwrite: initializing update to target slot 1
riotboot_flashwrite: processing bytes 4-63
cpu/stm32/periph/flashpage.c:208 => 0x80017f5
*** RIOT kernel panic:
FAILED ASSERTION.

*** halted.

Metadata

Metadata

Labels

Area: OTAArea: Over-the-air updatesArea: cpuArea: CPU/MCU portsPlatform: ARMPlatform: This PR/issue effects ARM-based platformsType: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions