storage/stream_flash: Support for devices without explicit erase

Support for devices not requiring erase with Stream Flash API.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2024-03-01 20:49:48 +00:00 committed by Henrik Brix Andersen
parent 7894474cf9
commit 95dfd1210d
2 changed files with 14 additions and 0 deletions

View File

@ -11,8 +11,10 @@ menuconfig STREAM_FLASH
Enable support of stream to flash API
if STREAM_FLASH
config STREAM_FLASH_ERASE
bool "Perform erase operations"
depends on FLASH_HAS_EXPLICIT_ERASE
help
If disabled an external actor must erase the flash area being written
to.

View File

@ -76,9 +76,18 @@ static int settings_direct_loader(const char *key, size_t len,
int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off)
{
#if IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
int rc;
struct flash_pages_info page;
#if IS_ENABLED(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
/* There are both types of devices */
const struct flash_parameters *fparams = flash_get_parameters(ctx->fdev);
/* Stream flash does not rely on erase, it does it when device needs it */
if (!(flash_params_get_erase_cap(fparams) & FLASH_ERASE_C_EXPLICIT)) {
return 0;
}
#endif
rc = flash_get_page_info_by_offs(ctx->fdev, off, &page);
if (rc != 0) {
LOG_ERR("Error %d while getting page info", rc);
@ -100,6 +109,9 @@ int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off)
}
return rc;
#else
return 0;
#endif
}
#endif /* CONFIG_STREAM_FLASH_ERASE */