Skip to content

Commit 2426292

Browse files
committed
[nrf noup] boot/zephyr: check for FPROTECT capability
Added run-time check for checking area setup to be protected meets device capability. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent b6b46a7 commit 2426292

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

boot/zephyr/main.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
149149
* !defined(ZEPHYR_LOG_MODE_MINIMAL)
150150
*/
151151

152-
#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
153-
#include <fprotect.h>
154-
#include <pm_config.h>
155-
#endif
152+
#include "nrf_protect.h"
156153

157154
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
158155
#include <nrf_cleanup.h>
@@ -789,16 +786,6 @@ int main(void)
789786

790787
#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
791788

792-
#ifdef PM_S1_ADDRESS
793-
/* MCUBoot is stored in either S0 or S1, protect both */
794-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS)
795-
#define PROTECT_ADDR PM_S0_ADDRESS
796-
#else
797-
/* There is only one instance of MCUBoot */
798-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS)
799-
#define PROTECT_ADDR PM_MCUBOOT_ADDRESS
800-
#endif
801-
802789
rc = fprotect_area(PROTECT_ADDR, PROTECT_SIZE);
803790

804791
if (rc != 0) {

boot/zephyr/nrf_protect.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (c) 5020 Nordic Semiconductor ASA
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef NRF_PROTECT_H__
7+
#define NRF_PROTECT_H__
8+
9+
#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
10+
11+
#include <pm_config.h>
12+
#include <fprotect.h>
13+
14+
#ifdef PM_S1_ADDRESS
15+
/* MCUBoot is stored in either S0 or S1, protect both */
16+
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS)
17+
#define PROTECT_ADDR PM_S0_ADDRESS
18+
#else
19+
/* There is only one instance of MCUBoot */
20+
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS)
21+
#define PROTECT_ADDR PM_MCUBOOT_ADDRESS
22+
#endif
23+
24+
#ifdef CONFIG_SOC_SERIES_NRF54LX
25+
#if defined(CONFIG_FPROTECT_ALLOW_COMBINED_REGIONS)
26+
#define REGION_SIZE_MAX (62 *1024)
27+
#if (PROTECT_ADDR != 0)
28+
#error "FPROTECT with combined regions can only be used to protect from address 0"
29+
#endif
30+
#else
31+
#define REGION_SIZE_MAX (31 *1024)
32+
#endif
33+
34+
#if (PROTECT_SIZE > REGION_SIZE_MAX)
35+
#error "FPROTECT size too large"
36+
#endif
37+
38+
#endif /* CONFIG_SOC_SERIES_NRF54LX */
39+
40+
#endif /* USE_PARTITION_MANAGER && CONFIG_FPROTECT */
41+
42+
#endif /* NRF_PROTECT_H__ */

0 commit comments

Comments
 (0)