Skip to content

Commit 106d673

Browse files
committed
[nrf noup] boot: zephyr: Protect only the bootloader
When using fprotect_area(), only protect the areas assigned to bootloader. Don't assume there is nothing between bootloader and primary slot. This allows placing TF-M storage between bootloader and MCUboot primary slot. Signed-off-by: Seppo Takalo <[email protected]>
1 parent 81e6fc3 commit 106d673

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

boot/zephyr/main.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,19 @@ int main(void)
635635

636636
#ifdef PM_S1_ADDRESS
637637
/* MCUBoot is stored in either S0 or S1, protect both */
638-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS)
639-
#define PROTECT_ADDR PM_S0_ADDRESS
638+
#define PROTECT_START PM_S0_ADDRESS
639+
#define PROTECT_END PM_S1_END_ADDRESS
640640
#else
641641
/* There is only one instance of MCUBoot */
642-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS)
643-
#define PROTECT_ADDR PM_MCUBOOT_ADDRESS
642+
#define PROTECT_START PM_MCUBOOT_ADDRESS
643+
#define PROTECT_END PM_MCUBOOT_END_ADDRESS
644644
#endif
645645

646-
rc = fprotect_area(PROTECT_ADDR, PROTECT_SIZE);
646+
uint32_t start = ALIGN_DOWN(PROTECT_START, CONFIG_FPROTECT_BLOCK_SIZE);
647+
uint32_t end = ALIGN_UP(PROTECT_END, CONFIG_FPROTECT_BLOCK_SIZE);
648+
uint32_t size = end - start;
649+
650+
rc = fprotect_area(start, size);
647651

648652
if (rc != 0) {
649653
BOOT_LOG_ERR("Protect mcuboot flash failed, cancel startup.");

0 commit comments

Comments
 (0)