Skip to content

Commit de4695b

Browse files
committed
fixup! fixup! fixup! sys/{riotboot,suit}: allow updates without boot header
1 parent f2b7182 commit de4695b

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

sys/riotboot/flashwrite.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state,
132132
flashpage_avail -= to_copy;
133133
if ((!flashpage_avail) || (!more)) {
134134
#if CONFIG_RIOTBOOT_FLASHWRITE_RAW /* Guards access to state::firstblock_buf */
135-
void *addr = flashpage_addr(state->flashpage);
136135
if (!state->offset) {
137136
/* Skip flashing the first block, store it for later to flash it
138137
* during the flashwrite_finish function, when payload contains the boot header */
139138
memcpy(state->firstblock_buf,
140139
state->flashpage_buf, RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
141140
}
142141
else {
142+
void *addr = flashpage_addr(state->flashpage);
143143
flashpage_write((uint8_t *)addr + flashpage_pos,
144144
state->flashpage_buf,
145145
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
@@ -209,18 +209,14 @@ int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
209209
uint8_t *slot_start = (uint8_t *)riotboot_slot_get_hdr(state->target_slot);
210210
const uint8_t *data = bytes;
211211
size_t remaining = len;
212-
size_t to_copy;
212+
size_t to_copy = MIN(remaining, sizeof(state->flashpage_buf));
213213

214214
if (!state->skip_len) {
215215
#if IS_ACTIVE(CONFIG_RIOTBOOT_FLASHWRITE_RAW)
216216
/* If there is a skip_len, the first block contains the header and must be
217217
* re-flashed to include the magic number and checksum. */
218-
to_copy = MIN(remaining, sizeof(state->firstblock_buf));
219218
memcpy(state->firstblock_buf, data, to_copy);
220-
flashpage_write(slot_start, state->firstblock_buf,
221-
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
222-
data += to_copy;
223-
remaining -= to_copy;
219+
memcpy(state->flashpage_buf, state->firstblock_buf, sizeof(state->flashpage_buf));
224220
#endif
225221
}
226222
while (remaining) {

sys/suit/storage/flashwrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int _flashwrite_write(suit_storage_t *storage,
8282
fw->writer.offset = RIOTBOOT_HDR_LEN;
8383
fw->writer.skip_len = RIOTBOOT_HDR_LEN;
8484
}
85-
memset(fw->writer.flashpage_buf, 0xff, sizeof(fw->writer.flashpage_buf));
85+
memset(fw->writer.flashpage_buf, FLASHPAGE_ERASE_STATE, sizeof(fw->writer.flashpage_buf));
8686
}
8787
else if (offset != fw->writer.offset - fw->writer.skip_len) {
8888
LOG_ERROR("Unexpected offset: %u - expected: %u\n", (unsigned)offset,

0 commit comments

Comments
 (0)