Skip to content

Commit f147e8b

Browse files
nordicjmfabiobaltieri
authored andcommitted
dfu: boot: mcuboot_shell: Prevent erasing MCUboot/app flash areas
Prevents the user from potentially bricking a device by erasing the MCUboot or currently running application flash areas with the mcuboot erase command Signed-off-by: Jamie McCrae <[email protected]>
1 parent ed61040 commit f147e8b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

subsys/dfu/boot/mcuboot_shell.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2020 Grinn
3+
* Copyright (c) 2023 Nordic Semiconductor ASA
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -91,6 +92,21 @@ static int cmd_mcuboot_erase(const struct shell *sh, size_t argc,
9192

9293
id = strtoul(argv[1], NULL, 0);
9394

95+
/* Check if this is the parent (MCUboot) or own slot and if so, deny the request */
96+
#if FIXED_PARTITION_EXISTS(boot_partition)
97+
if (id == FIXED_PARTITION_ID(boot_partition)) {
98+
shell_error(sh, "Cannot erase boot partition");
99+
return -EACCES;
100+
}
101+
#endif
102+
103+
#if DT_FIXED_PARTITION_EXISTS(DT_CHOSEN(zephyr_code_partition))
104+
if (id == DT_FIXED_PARTITION_ID(DT_CHOSEN(zephyr_code_partition))) {
105+
shell_error(sh, "Cannot erase active partitions");
106+
return -EACCES;
107+
}
108+
#endif
109+
94110
err = boot_erase_img_bank(id);
95111
if (err) {
96112
shell_error(sh, "failed to erase bank %u", id);

0 commit comments

Comments
 (0)