Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrf noup] dfu: boot: mcuboot_shell: Prevent erasing active areas #2114

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions subsys/dfu/boot/mcuboot_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
#endif
#endif

#if USE_PARTITION_MANAGER
#include <flash_map_pm.h>

#ifdef CONFIG_NCS_IS_VARIANT_IMAGE
#define ACTIVE_IMAGE_ID PM_MCUBOOT_SECONDARY_ID
#else
#define ACTIVE_IMAGE_ID PM_MCUBOOT_PRIMARY_ID
#endif
#endif

struct area_desc {
const char *name;
unsigned int id;
Expand Down Expand Up @@ -93,6 +103,35 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc,
id = strtoul(argv[1], NULL, 0);

/* Check if this is the parent (MCUboot) or own slot and if so, deny the request */
#if USE_PARTITION_MANAGER
#ifdef PM_MCUBOOT_ID
if (id == PM_MCUBOOT_ID || id == PM_MCUBOOT_PAD_ID) {
shell_error(sh, "Cannot erase boot partition");
return -EACCES;
}
#endif

#ifdef PM_APP_ID
if (id == PM_APP_ID) {
shell_error(sh, "Cannot erase this area");
return -EACCES;
}
#endif

#ifdef PM_MCUBOOT_PRIMARY_APP_ID
if (id == PM_MCUBOOT_PRIMARY_APP_ID) {
shell_error(sh, "Cannot erase this area");
return -EACCES;
}
#endif

#ifdef ACTIVE_IMAGE_ID
if (id == ACTIVE_IMAGE_ID) {
shell_error(sh, "Cannot erase active partitions");
return -EACCES;
}
#endif
#else
#if FIXED_PARTITION_EXISTS(boot_partition)
if (id == FIXED_PARTITION_ID(boot_partition)) {
shell_error(sh, "Cannot erase boot partition");
Expand All @@ -105,6 +144,7 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc,
shell_error(sh, "Cannot erase active partitions");
return -EACCES;
}
#endif
#endif

err = boot_erase_img_bank(id);
Expand Down
Loading