mgmt/MCUmgr/grp/img: Improvement in image erase logic
The erase logic has been switched to using img_mgmt_get_opposite_slot and the img_mgmt_get_other_slot has been removed. The commit adds CONFIG_MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING Kconfig options, default set to n, that allows to make pending slot erasable. The option only allows erase on pending slot that is not revert slot. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
21c3263b95
commit
58b22bc4a9
3 changed files with 26 additions and 20 deletions
|
@ -82,6 +82,15 @@ config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_ANY
|
||||||
broken and may not boot in other slot; instead application should
|
broken and may not boot in other slot; instead application should
|
||||||
have means to test and confirm the image.
|
have means to test and confirm the image.
|
||||||
|
|
||||||
|
if !MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
|
||||||
|
config MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING
|
||||||
|
bool "Allow to erase pending slot"
|
||||||
|
help
|
||||||
|
Allows erasing secondary slot which is marked for test or confirmed; this allows
|
||||||
|
erasing slots that have been set for next boot but the device has not
|
||||||
|
reset yet, so has not yet been swapped.
|
||||||
|
endif
|
||||||
|
|
||||||
config MCUMGR_GRP_IMG_DIRECT_UPLOAD
|
config MCUMGR_GRP_IMG_DIRECT_UPLOAD
|
||||||
bool "Allow direct image upload"
|
bool "Allow direct image upload"
|
||||||
help
|
help
|
||||||
|
|
|
@ -322,24 +322,6 @@ static void img_mgmt_reset_upload(void)
|
||||||
img_mgmt_release_lock();
|
img_mgmt_release_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
img_mgmt_get_other_slot(void)
|
|
||||||
{
|
|
||||||
int slot = img_mgmt_active_slot(img_mgmt_active_image());
|
|
||||||
|
|
||||||
switch (slot) {
|
|
||||||
case 1:
|
|
||||||
return 0;
|
|
||||||
#if CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 2
|
|
||||||
case 2:
|
|
||||||
return 3;
|
|
||||||
case 3:
|
|
||||||
return 2;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command handler: image erase
|
* Command handler: image erase
|
||||||
*/
|
*/
|
||||||
|
@ -351,7 +333,7 @@ img_mgmt_erase(struct smp_streamer *ctxt)
|
||||||
zcbor_state_t *zse = ctxt->writer->zs;
|
zcbor_state_t *zse = ctxt->writer->zs;
|
||||||
zcbor_state_t *zsd = ctxt->reader->zs;
|
zcbor_state_t *zsd = ctxt->reader->zs;
|
||||||
bool ok;
|
bool ok;
|
||||||
uint32_t slot = img_mgmt_get_other_slot();
|
uint32_t slot = img_mgmt_get_opposite_slot(img_mgmt_active_slot(img_mgmt_active_image()));
|
||||||
size_t decoded = 0;
|
size_t decoded = 0;
|
||||||
|
|
||||||
struct zcbor_map_decode_key_val image_erase_decode[] = {
|
struct zcbor_map_decode_key_val image_erase_decode[] = {
|
||||||
|
|
|
@ -233,9 +233,24 @@ img_mgmt_slot_in_use(int slot)
|
||||||
int active_slot = img_mgmt_active_slot(image);
|
int active_slot = img_mgmt_active_slot(image);
|
||||||
|
|
||||||
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
|
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
|
||||||
if (slot == img_mgmt_get_next_boot_slot(image, NULL)) {
|
enum img_mgmt_next_boot_type type = NEXT_BOOT_TYPE_NORMAL;
|
||||||
|
int nbs = img_mgmt_get_next_boot_slot(image, &type);
|
||||||
|
|
||||||
|
if (slot == nbs && type == NEXT_BOOT_TYPE_REVERT) {
|
||||||
|
LOG_DBG("(%d) Refused erase revert", slot);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((slot == nbs && type == NEXT_BOOT_TYPE_TEST) ||
|
||||||
|
(active_slot != nbs && type == NEXT_BOOT_TYPE_NORMAL)) {
|
||||||
|
#if defined(CONFIG_MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING)
|
||||||
|
LOG_DBG("(%d) Allowed erase pending", slot);
|
||||||
|
/* Pass through to return (active_slot == slot) */
|
||||||
|
#else
|
||||||
|
LOG_DBG("(%d) Refused erase pending", slot);
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (active_slot == slot);
|
return (active_slot == slot);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue