Skip to content

Commit 1ce3591

Browse files
de-nordicrghaddab
authored andcommitted
[nrf fromtree] storage/stream_flash: Support for devices without explicit erase
Support for devices not requiring erase with Stream Flash API. Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 95dfd12)
1 parent fa1b670 commit 1ce3591

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

subsys/storage/stream/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ menuconfig STREAM_FLASH
1111
Enable support of stream to flash API
1212

1313
if STREAM_FLASH
14+
1415
config STREAM_FLASH_ERASE
1516
bool "Perform erase operations"
17+
depends on FLASH_HAS_EXPLICIT_ERASE
1618
help
1719
If disabled an external actor must erase the flash area being written
1820
to.

subsys/storage/stream/stream_flash.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,18 @@ static int settings_direct_loader(const char *key, size_t len,
7676

7777
int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off)
7878
{
79+
#if IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
7980
int rc;
8081
struct flash_pages_info page;
82+
#if IS_ENABLED(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
83+
/* There are both types of devices */
84+
const struct flash_parameters *fparams = flash_get_parameters(ctx->fdev);
8185

86+
/* Stream flash does not rely on erase, it does it when device needs it */
87+
if (!(flash_params_get_erase_cap(fparams) & FLASH_ERASE_C_EXPLICIT)) {
88+
return 0;
89+
}
90+
#endif
8291
rc = flash_get_page_info_by_offs(ctx->fdev, off, &page);
8392
if (rc != 0) {
8493
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)
100109
}
101110

102111
return rc;
112+
#else
113+
return 0;
114+
#endif
103115
}
104116

105117
#endif /* CONFIG_STREAM_FLASH_ERASE */

0 commit comments

Comments
 (0)