Skip to content

Commit 750323f

Browse files
de-nordicrghaddab
authored andcommitted
[nrf fromtree] mgmt/mcumgr: Replace use of flash_area_erase with flash_area_flatten
The commit replaces flash_area_erase with flash_area_flatten. The function is used in to places: 1) in image management commands IMG_MGMT_ID_UPLOAD and IMG_MGMT_ID_ERASE: to erase an image in secondary slot or to scramble trailer part of image, which could be misunderstood by MCUboot as valid image operation request; 2) in command ZEPHYR_MGMT_GRP_BASIC_CMD_ERASE_STORAGE to erase/scramble data partition. Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit bce06a6)
1 parent c4dd120 commit 750323f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int img_mgmt_erase_slot(int slot)
294294
rc = img_mgmt_flash_check_empty_inner(fa);
295295

296296
if (rc == 0) {
297-
rc = flash_area_erase(fa, 0, fa->fa_size);
297+
rc = flash_area_flatten(fa, 0, fa->fa_size);
298298

299299
if (rc != 0) {
300300
LOG_ERR("Failed to erase flash area: %d", rc);
@@ -473,7 +473,7 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
473473

474474
size_t erase_size = page.start_offset + page.size - fa->fa_off;
475475

476-
rc = flash_area_erase(fa, 0, erase_size);
476+
rc = flash_area_flatten(fa, 0, erase_size);
477477

478478
if (rc != 0) {
479479
LOG_ERR("image slot erase of 0x%zx bytes failed (err %d)", erase_size,
@@ -498,7 +498,7 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
498498
off = page.start_offset - fa->fa_off;
499499
erase_size = fa->fa_size - off;
500500

501-
rc = flash_area_erase(fa, off, erase_size);
501+
rc = flash_area_flatten(fa, off, erase_size);
502502
if (rc != 0) {
503503
LOG_ERR("image slot trailer erase of 0x%zx bytes failed (err %d)",
504504
erase_size, rc);

subsys/mgmt/mcumgr/grp/zephyr_basic/src/basic_mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int storage_erase(void)
3131
LOG_ERR("Failed to get flash area device");
3232
rc = ZEPHYRBASIC_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL;
3333
} else {
34-
rc = flash_area_erase(fa, 0, fa->fa_size);
34+
rc = flash_area_flatten(fa, 0, fa->fa_size);
3535

3636
if (rc < 0) {
3737
LOG_ERR("Failed to erase flash area");

0 commit comments

Comments
 (0)