Skip to content

Commit 6a9f0de

Browse files
tomchynordicjm
authored andcommitted
[nrf fromlist] mcumgr: Prevent FW loader from self-destruction
The FW loader reports and manages exactly two slots: - slot 0: this is the slot for the application code to update - slot 1: this is the slot, in which the FW loader is placed The slot 1 is reported, so tools can fetch metadata about the FW loader installed on the device. Unfortunately, currently SMP-based FW loader allows to issue slot erase command for the slot 1, effectively erasing the FW loader code that is being executed. This change correctly identifies the slot 1 as an active one, marking it as used and blocking erase operation on that slot. Upstream PR #: 100689 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 346e646 commit 6a9f0de

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,13 @@ img_mgmt_state_any_pending(void)
361361
int
362362
img_mgmt_slot_in_use(int slot)
363363
{
364-
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
365-
return 0;
366-
#else
367364
int image = img_mgmt_slot_to_image(slot);
368365
int active_slot = img_mgmt_active_slot(image);
369366

370367
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \
371368
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD) && \
372-
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT)
369+
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT) && \
370+
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
373371
enum img_mgmt_next_boot_type type = NEXT_BOOT_TYPE_NORMAL;
374372
int nbs = img_mgmt_get_next_boot_slot(image, &type);
375373

@@ -391,7 +389,6 @@ img_mgmt_slot_in_use(int slot)
391389
#endif
392390

393391
return (active_slot == slot);
394-
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */
395392
}
396393

397394
/**

0 commit comments

Comments
 (0)