Skip to content

Commit 965545c

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

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-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: 2 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"

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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
#define TAMPC_REASON (((volatile uint32_t *)0x4010E600)[0])
21+
void tampc_enable(void);
22+
void tampc_disable(void);
23+
24+
int init_tampc(void) {
25+
26+
if (TAMPC_REASON & NRFX_RESET_REASON_SECTAMPER_MASK) {
27+
TAMPC_REASON = NRFX_RESET_REASON_SECTAMPER_MASK;
28+
boot_reason_sectamper = true;
29+
}
30+
31+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER);
32+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR);
33+
34+
tampc_enable();
35+
nrf_tampc_int_enable(NRF_TAMPC, NRF_TAMPC_ALL_INTS_MASK);
36+
37+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_RESETEN_INT,
38+
RESET_BY_PERIPHERAL);
39+
40+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
41+
NVIC_ClearTargetState(TAMPC_IRQn);
42+
NVIC_EnableIRQ(TAMPC_IRQn);
43+
44+
return TFM_PLAT_ERR_SUCCESS;
45+
}
46+
47+
void tampc_enable(void) {
48+
nrf_tampc_protector_ctrl_value_set(
49+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, true);
50+
nrf_tampc_protector_ctrl_value_set(
51+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, true);
52+
}
53+
54+
void tampc_disable(void) {
55+
nrf_tampc_protector_ctrl_value_set(
56+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, false);
57+
nrf_tampc_protector_ctrl_value_set(
58+
NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, false);
59+
}
60+
61+
void TAMPC_Handler(void) {
62+
SPMLOG_ERRMSG("TAMPC Exception:\r\n");
63+
64+
if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR)) {
65+
SPMLOG_ERRMSG("\tWrite error.\r\n");
66+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR);
67+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
68+
tfm_core_panic();
69+
}
70+
71+
if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER)) {
72+
SPMLOG_ERRMSG("\tTamper event.\r\n");
73+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER);
74+
NVIC_ClearPendingIRQ(TAMPC_IRQn);
75+
TAMPER_EVENT_HANDLER();
76+
}
77+
}

0 commit comments

Comments
 (0)