diff --git a/sys/include/riotboot/flashwrite.h b/sys/include/riotboot/flashwrite.h index 2591b375c6..2d777f958c 100644 --- a/sys/include/riotboot/flashwrite.h +++ b/sys/include/riotboot/flashwrite.h @@ -132,6 +132,14 @@ static inline int riotboot_flashwrite_init(riotboot_flashwrite_t *state, */ int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len, bool more); +/** + * @brief Force flush the buffer onto the flash + * + * @param[in,out] state ptr to previously used update state + * + * @returns 0 on success, <0 otherwise + */ +int riotboot_flashwrite_flush(riotboot_flashwrite_t *state); /** * @brief Finish a firmware update (raw version) diff --git a/sys/riotboot/flashwrite.c b/sys/riotboot/flashwrite.c index e51cb341b8..c86ea04202 100644 --- a/sys/riotboot/flashwrite.c +++ b/sys/riotboot/flashwrite.c @@ -57,6 +57,15 @@ int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot, return 0; } +int riotboot_flashwrite_flush(riotboot_flashwrite_t *state) +{ + if (flashpage_write_and_verify(state->flashpage, state->flashpage_buf) != FLASHPAGE_OK) { + LOG_WARNING(LOG_PREFIX "error writing flashpage %u!\n", state->flashpage); + return -1; + } + return 0; +} + int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state, const uint8_t *bytes, size_t len, bool more) {