diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c index 3e91b3662..d01f6932b 100644 --- a/boot/zephyr/main.c +++ b/boot/zephyr/main.c @@ -149,10 +149,7 @@ K_SEM_DEFINE(boot_log_sem, 1, 1); * !defined(ZEPHYR_LOG_MODE_MINIMAL) */ -#if USE_PARTITION_MANAGER && CONFIG_FPROTECT -#include -#include -#endif +#include "nrf_protect.h" #if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL #include @@ -789,16 +786,6 @@ int main(void) #if USE_PARTITION_MANAGER && CONFIG_FPROTECT -#ifdef PM_S1_ADDRESS -/* MCUBoot is stored in either S0 or S1, protect both */ -#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS) -#define PROTECT_ADDR PM_S0_ADDRESS -#else -/* There is only one instance of MCUBoot */ -#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS) -#define PROTECT_ADDR PM_MCUBOOT_ADDRESS -#endif - rc = fprotect_area(PROTECT_ADDR, PROTECT_SIZE); if (rc != 0) { diff --git a/boot/zephyr/nrf_protect.h b/boot/zephyr/nrf_protect.h new file mode 100644 index 000000000..b22ce123d --- /dev/null +++ b/boot/zephyr/nrf_protect.h @@ -0,0 +1,42 @@ +/* Copyright (c) 5020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef NRF_PROTECT_H__ +#define NRF_PROTECT_H__ + +#if USE_PARTITION_MANAGER && CONFIG_FPROTECT + +#include +#include + +#ifdef PM_S1_ADDRESS +/* MCUBoot is stored in either S0 or S1, protect both */ +#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS) +#define PROTECT_ADDR PM_S0_ADDRESS +#else +/* There is only one instance of MCUBoot */ +#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS) +#define PROTECT_ADDR PM_MCUBOOT_ADDRESS +#endif + +#ifdef CONFIG_SOC_SERIES_NRF54LX +#if defined(CONFIG_FPROTECT_ALLOW_COMBINED_REGIONS) +#define REGION_SIZE_MAX (62 *1024) +#if (PROTECT_ADDR != 0) +#error "FPROTECT with combined regions can only be used to protect from address 0" +#endif +#else +#define REGION_SIZE_MAX (31 *1024) +#endif + +#if (PROTECT_SIZE > REGION_SIZE_MAX) +#error "FPROTECT size too large" +#endif + +#endif /* CONFIG_SOC_SERIES_NRF54LX */ + +#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */ + +#endif /* NRF_PROTECT_H__ */