Skip to content

Commit 1486252

Browse files
MarkusLassilarlubos
authored andcommitted
tfm: Lock Approtect in network core
With nRF53, allow the network core Approtect to be locked from TF-M. This is done when we are transitioning from provisioning LCS to secure LCS. NCSDK-17920 Signed-off-by: Markus Lassila <[email protected]>
1 parent 24323bc commit 1486252

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

modules/trusted-firmware-m/tfm_boards/common/nrf_provisioning.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,51 @@
1616
#include "nrf_provisioning.h"
1717
#include <identity_key.h>
1818
#include <tfm_spm_log.h>
19+
#include <pm_config.h>
20+
#if defined(NRF53_SERIES) && defined(PM_CPUNET_APP_ADDRESS)
21+
#include <dfu/pcd_common.h>
22+
#include <spu.h>
23+
#include <hal/nrf_reset.h>
24+
25+
#define DEBUG_LOCK_TIMEOUT_MS 3000
26+
#define USEC_IN_MSEC 1000
27+
#define USEC_IN_SEC 1000000
28+
29+
static enum tfm_plat_err_t disable_netcore_debug(void)
30+
{
31+
/* NRF_RESET to secure.
32+
* It will be configured to the original value after the provisioning is done.
33+
*/
34+
spu_peripheral_config_secure(NRF_RESET_S_BASE, SPU_LOCK_CONF_UNLOCKED);
35+
36+
/* Ensure that the network core is stopped. */
37+
nrf_reset_network_force_off(NRF_RESET, true);
38+
39+
/* Debug lock command will be read in b0n startup. */
40+
pcd_write_cmd_lock_debug();
41+
42+
/* Start the network core. */
43+
nrf_reset_network_force_off(NRF_RESET, false);
44+
45+
/* Wait 1 second for the network core to start up. */
46+
NRFX_DELAY_US(USEC_IN_SEC);
47+
48+
/* Wait for the debug lock to complete. */
49+
for (int i = 0; i < DEBUG_LOCK_TIMEOUT_MS; i++) {
50+
if (!pcd_read_cmd_lock_debug()) {
51+
break;
52+
}
53+
NRFX_DELAY_US(USEC_IN_MSEC);
54+
}
55+
56+
if (!pcd_read_cmd_done()) {
57+
SPMLOG_ERRMSG("Failed to lock debug in network core.");
58+
return TFM_PLAT_ERR_SYSTEM_ERR;
59+
}
60+
61+
return TFM_PLAT_ERR_SUCCESS;
62+
}
63+
#endif /* NRF53_SERIES && PM_CPUNET_APP_ADDRESS */
1964

2065
static enum tfm_plat_err_t verify_debug_disabled(void)
2166
{
@@ -71,10 +116,18 @@ enum tfm_plat_err_t tfm_plat_provisioning_perform(void)
71116
* that secure boot is already enabled at this stage
72117
*/
73118

119+
/* Application debug should already be disabled */
74120
if (verify_debug_disabled() != TFM_PLAT_ERR_SUCCESS) {
75121
return TFM_PLAT_ERR_SYSTEM_ERR;
76122
}
77123

124+
#if defined(NRF53_SERIES) && defined(PM_CPUNET_APP_ADDRESS)
125+
/* Disable network core debug in here */
126+
if (disable_netcore_debug() != TFM_PLAT_ERR_SUCCESS) {
127+
return TFM_PLAT_ERR_SYSTEM_ERR;
128+
}
129+
#endif
130+
78131
/* Transition to the SECURED lifecycle state */
79132
if (tfm_attest_update_security_lifecycle_otp(TFM_SLC_SECURED) != 0) {
80133
return TFM_PLAT_ERR_SYSTEM_ERR;

modules/trusted-firmware-m/tfm_boards/partition/region_defs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@
151151

152152
#ifdef PM_MCUBOOT_ADDRESS
153153
#define REGION_MCUBOOT_ADDRESS PM_MCUBOOT_ADDRESS
154-
#define REGION_MCUBOOT_END_ADDRESS PM_MCUBOOT_END_ADDRESS
154+
#define REGION_MCUBOOT_LIMIT PM_MCUBOOT_END_ADDRESS - 1
155155
#endif
156156
#ifdef PM_B0_ADDRESS
157157
#define REGION_B0_ADDRESS PM_B0_ADDRESS
158-
#define REGION_B0_END_ADDRESS PM_B0_END_ADDRESS
158+
#define REGION_B0_LIMIT PM_B0_END_ADDRESS - 1
159159
#endif
160160
#ifdef PM_S0_ADDRESS
161161
#define REGION_S0_ADDRESS PM_S0_ADDRESS
162-
#define REGION_S0_END_ADDRESS PM_S0_END_ADDRESS
162+
#define REGION_S0_LIMIT PM_S0_END_ADDRESS - 1
163163
#endif
164164
#ifdef PM_S1_ADDRESS
165165
#define REGION_S1_ADDRESS PM_S1_ADDRESS
166-
#define REGION_S1_END_ADDRESS PM_S1_END_ADDRESS
166+
#define REGION_S1_LIMIT PM_S1_END_ADDRESS - 1
167167
#endif
168168
#ifdef PM_PCD_SRAM_ADDRESS
169169
#define REGION_PCD_SRAM_ADDRESS PM_PCD_SRAM_ADDRESS
170-
#define REGION_PCD_SRAM_END_ADDRESS PM_PCD_SRAM_END_ADDRESS
170+
#define REGION_PCD_SRAM_LIMIT PM_PCD_SRAM_END_ADDRESS - 1
171171
#endif
172172

173173
#endif /* __REGION_DEFS_H__ */

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ manifest:
153153
- name: trusted-firmware-m
154154
repo-path: sdk-trusted-firmware-m
155155
path: modules/tee/tf-m/trusted-firmware-m
156-
revision: 899f0f54e76d41d70fac538f8a2d2cf171294a3b
156+
revision: 8c7fae3936da02b7db4f5c8aba174b252a2b326e
157157
- name: psa-arch-tests
158158
repo-path: sdk-psa-arch-tests
159159
path: modules/tee/tf-m/psa-arch-tests

0 commit comments

Comments
 (0)