From 02fa1cb670001a88b78768cdc3fec827ee3021d2 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Sat, 28 Sep 2024 21:09:44 +0200 Subject: [PATCH] [nrf fromlist] susbys/dfu/img_util: support ERASE PROGRESSIVELY for non-flash mem Added support for devices don't require explicit pager erase. For these device flattening of mcuboot image status is relevant. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/79152 Signed-off-by: Andrzej Puzdrowski (cherry picked from commit 30f066ab503d80603935317c5b2034b70bd50840) --- subsys/dfu/img_util/flash_img.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/subsys/dfu/img_util/flash_img.c b/subsys/dfu/img_util/flash_img.c index 9de47250670..6d1a21d7887 100644 --- a/subsys/dfu/img_util/flash_img.c +++ b/subsys/dfu/img_util/flash_img.c @@ -56,9 +56,27 @@ int flash_img_buffered_write(struct flash_img_context *ctx, const uint8_t *data, #ifdef CONFIG_IMG_ERASE_PROGRESSIVELY ssize_t status_offset = boot_get_trailer_status_offset( ctx->flash_area->fa_size); - rc = stream_flash_erase_page(&ctx->stream, - ctx->flash_area->fa_off + - status_offset); + +#ifdef CONFIG_STREAM_FLASH_ERASE + const struct flash_parameters *fparams = + flash_get_parameters(flash_area_get_device(ctx->flash_area)); + + if ((flash_params_get_erase_cap(fparams) & FLASH_ERASE_C_EXPLICIT)) { + /* use pistine-page-erase procedure for a device which needs it */ + rc = stream_flash_erase_page(&ctx->stream, + ctx->flash_area->fa_off + + status_offset); + } else +#endif + { + if (status_offset > stream_flash_bytes_written(&ctx->stream)) { + rc = flash_area_flatten(ctx->flash_area, status_offset, + ctx->flash_area->fa_off - status_offset); + } else { + rc = 0; + } + } + if (rc) { return rc; }