Skip to content

Commit e2f37c6

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 1a9ec93 commit e2f37c6

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
@@ -150,10 +150,7 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
150150
* !defined(CONFIG_LOG_MODE_MINIMAL)
151151
*/
152152

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

158155
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
159156
#include <nrf_cleanup.h>
@@ -848,16 +845,6 @@ int main(void)
848845

849846
#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
850847

851-
#ifdef PM_S1_ADDRESS
852-
/* MCUBoot is stored in either S0 or S1, protect both */
853-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_S0_ADDRESS)
854-
#define PROTECT_ADDR PM_S0_ADDRESS
855-
#else
856-
/* There is only one instance of MCUBoot */
857-
#define PROTECT_SIZE (PM_MCUBOOT_PRIMARY_ADDRESS - PM_MCUBOOT_ADDRESS)
858-
#define PROTECT_ADDR PM_MCUBOOT_ADDRESS
859-
#endif
860-
861848
rc = fprotect_area(PROTECT_ADDR, PROTECT_SIZE);
862849

863850
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)