Skip to content

Commit 15dbf4f

Browse files
committed
Basic handling of TAMPC
Signed-off-by: Vidar Lillebø <[email protected]>
1 parent bc01a4c commit 15dbf4f

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

platform/ext/target/nordic_nrf/common/core/faults.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,15 @@ __attribute__((naked)) void MPC00_IRQHandler(void)
110110
);
111111
}
112112
#endif
113+
114+
#ifdef NRF_TAMPC
115+
__attribute__((naked)) void TAMPC_IRQHandler(void)
116+
{
117+
EXCEPTION_INFO();
118+
119+
__ASM volatile(
120+
"BL TAMPC_Handler \n"
121+
"B . \n"
122+
);
123+
}
124+
#endif

platform/ext/target/nordic_nrf/common/core/target_cfg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include "target_cfg.h"
20+
#include "native_drivers/spu.h"
21+
#include "nrf54l15_enga_global.h"
2022
#include "region_defs.h"
2123
#include "tfm_plat_defs.h"
2224
#include "tfm_peripherals_config.h"
@@ -1134,6 +1136,9 @@ enum tfm_plat_err_t spu_periph_init_cfg(void)
11341136
/* Configure trace to be secure, as the security implications of non-secure trace are not understood */
11351137
spu_peripheral_config_secure(NRF_TAD_S_BASE, SPU_LOCK_CONF_LOCKED);
11361138

1139+
1140+
spu_peripheral_config_secure(NRF_RESET_S_BASE, SPU_LOCK_CONF_LOCKED);
1141+
11371142
/* Configure these HW features, which are not in the MDK, to be
11381143
* secure, as the security implications of them being non-secure
11391144
* are not understood

platform/ext/target/nordic_nrf/common/core/tfm_hal_platform_common.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "tfm_plat_defs.h"
1212
#include "uart_stdout.h"
1313

14+
int init_tampc(void);
15+
1416
extern const struct memory_region_limits memory_regions;
1517
enum tfm_hal_status_t tfm_hal_platform_common_init(void)
1618
{
@@ -46,6 +48,12 @@ enum tfm_hal_status_t tfm_hal_platform_common_init(void)
4648
return TFM_HAL_ERROR_GENERIC;
4749
}
4850

51+
/***/
52+
plat_err = init_tampc();
53+
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
54+
return TFM_HAL_ERROR_GENERIC;
55+
}
56+
4957
return TFM_HAL_SUCCESS;
5058
}
5159

platform/ext/target/nordic_nrf/common/nrf54l15/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target_include_directories(platform_s
2222
target_sources(platform_s
2323
PRIVATE
2424
${HAL_NORDIC_PATH}/nrfx/mdk/system_nrf54l.c
25+
tampc.c
2526
)
2627

2728
target_compile_definitions(platform_s
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
/***
3+
4+
5+
*/
6+
7+
#include "nrf54l15_enga_application.h"
8+
#include "nrf54l15_enga_global.h"
9+
#include "nrf54l15_enga_types.h"
10+
#include "tfm_hal_platform.h"
11+
#include "tfm_plat_defs.h"
12+
#include <hal/nrf_tampc.h>
13+
#include <helpers/nrfx_reset_reason.h>
14+
15+
bool boot_reason_sectamper;
16+
17+
#define RESET_BY_PERIPHERAL false
18+
#define TAMPER_EVENT_HANDLER tfm_core_panic
19+
20+
int init_tampc(void) {
21+
22+
#if 0
23+
if (((volatile uint32_t *)0x5010E600)[0] & NRFX_RESET_REASON_SECTAMPER_MASK) {
24+
((volatile uint32_t *)0x5010E600)[0] = NRFX_RESET_REASON_SECTAMPER_MASK;
25+
boot_reason_sectamper = true;
26+
}
27+
#endif
28+
29+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR);
30+
nrf_tampc_int_enable(NRF_TAMPC, NRF_TAMPC_ALL_INTS_MASK);
31+
32+
nrf_tampc_protector_ctrl_value_set(
33+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, true);
34+
nrf_tampc_protector_ctrl_value_set(
35+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, true);
36+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_RESETEN_INT,
37+
RESET_BY_PERIPHERAL);
38+
39+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
40+
NVIC_ClearTargetState(TAMPC_IRQn);
41+
NVIC_EnableIRQ(TAMPC_IRQn);
42+
43+
return TFM_PLAT_ERR_SUCCESS;
44+
}
45+
46+
void TAMPC_Handler(void) {
47+
SPMLOG_ERRMSG("TAMPC Exception:\r\n");
48+
49+
if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR)) {
50+
SPMLOG_ERRMSG("\tWrite error.\r\n");
51+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR);
52+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
53+
tfm_core_panic();
54+
}
55+
56+
if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER)) {
57+
SPMLOG_ERRMSG("\tTamper event.\r\n");
58+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER);
59+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
60+
TAMPER_EVENT_HANDLER();
61+
}
62+
}

0 commit comments

Comments
 (0)