Skip to content

Commit 5c93263

Browse files
committed
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. Signed-off-by: Markus Lassila <[email protected]>
1 parent 9c78f7d commit 5c93263

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

modules/trusted-firmware-m/Kconfig.tfm.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config PM_PARTITION_SIZE_TFM_SRAM
1515
# assigning 0x16000 of RAM to TFM will not leave enough RAM for
1616
# Matter. So we use 0x13000 of RAM on 54L.
1717
default 0x13000 if SOC_SERIES_NRF54LX
18-
default 0x16000 if SOC_SERIES_NRF91X
18+
default 0x16000 if SOC_SERIES_NRF91X || SOC_SERIES_NRF53X
1919
default 0x30000
2020
help
2121
Memory set aside for the TFM_SRAM partition.

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

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

2081
static enum tfm_plat_err_t verify_debug_disabled(void)
2182
{
@@ -71,10 +132,18 @@ enum tfm_plat_err_t tfm_plat_provisioning_perform(void)
71132
* that secure boot is already enabled at this stage
72133
*/
73134

135+
/* Application debug should already be disabled */
74136
if (verify_debug_disabled() != TFM_PLAT_ERR_SUCCESS) {
75137
return TFM_PLAT_ERR_SYSTEM_ERR;
76138
}
77139

140+
#ifdef NRF53_SERIES
141+
/* Disable network core debug in here */
142+
if (disable_netcore_debug() != TFM_PLAT_ERR_SUCCESS) {
143+
return TFM_PLAT_ERR_SYSTEM_ERR;
144+
}
145+
#endif
146+
78147
/* Transition to the SECURED lifecycle state */
79148
if (tfm_attest_update_security_lifecycle_otp(TFM_SLC_SECURED) != 0) {
80149
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__ */

0 commit comments

Comments
 (0)