diff --git a/platform/ext/target/nordic_nrf/common/core/faults.c b/platform/ext/target/nordic_nrf/common/core/faults.c index 912c5106a..40cf4d6d9 100644 --- a/platform/ext/target/nordic_nrf/common/core/faults.c +++ b/platform/ext/target/nordic_nrf/common/core/faults.c @@ -110,3 +110,15 @@ __attribute__((naked)) void MPC00_IRQHandler(void) ); } #endif + +#ifdef NRF_TAMPC +__attribute__((naked)) void TAMPC_IRQHandler(void) +{ + EXCEPTION_INFO(); + + __ASM volatile( + "BL TAMPC_Handler \n" + "B . \n" + ); +} +#endif diff --git a/platform/ext/target/nordic_nrf/common/core/target_cfg.c b/platform/ext/target/nordic_nrf/common/core/target_cfg.c index da8f9dd1e..52c4fd2a3 100644 --- a/platform/ext/target/nordic_nrf/common/core/target_cfg.c +++ b/platform/ext/target/nordic_nrf/common/core/target_cfg.c @@ -17,6 +17,8 @@ */ #include "target_cfg.h" +#include "native_drivers/spu.h" +#include "nrf54l15_enga_global.h" #include "region_defs.h" #include "tfm_plat_defs.h" #include "tfm_peripherals_config.h" diff --git a/platform/ext/target/nordic_nrf/common/core/tfm_hal_platform_common.c b/platform/ext/target/nordic_nrf/common/core/tfm_hal_platform_common.c index 51026e3e2..423602fbc 100644 --- a/platform/ext/target/nordic_nrf/common/core/tfm_hal_platform_common.c +++ b/platform/ext/target/nordic_nrf/common/core/tfm_hal_platform_common.c @@ -11,6 +11,8 @@ #include "tfm_plat_defs.h" #include "uart_stdout.h" +int init_tampc(void); + extern const struct memory_region_limits memory_regions; enum tfm_hal_status_t tfm_hal_platform_common_init(void) { @@ -46,6 +48,12 @@ enum tfm_hal_status_t tfm_hal_platform_common_init(void) return TFM_HAL_ERROR_GENERIC; } + /***/ + plat_err = init_tampc(); + if (plat_err != TFM_PLAT_ERR_SUCCESS) { + return TFM_HAL_ERROR_GENERIC; + } + return TFM_HAL_SUCCESS; } diff --git a/platform/ext/target/nordic_nrf/common/nrf54l15/CMakeLists.txt b/platform/ext/target/nordic_nrf/common/nrf54l15/CMakeLists.txt index e093190b3..7eb27b019 100644 --- a/platform/ext/target/nordic_nrf/common/nrf54l15/CMakeLists.txt +++ b/platform/ext/target/nordic_nrf/common/nrf54l15/CMakeLists.txt @@ -22,6 +22,7 @@ target_include_directories(platform_s target_sources(platform_s PRIVATE ${HAL_NORDIC_PATH}/nrfx/mdk/system_nrf54l.c + tampc.c ) target_compile_definitions(platform_s diff --git a/platform/ext/target/nordic_nrf/common/nrf54l15/tampc.c b/platform/ext/target/nordic_nrf/common/nrf54l15/tampc.c new file mode 100644 index 000000000..d5337c8ba --- /dev/null +++ b/platform/ext/target/nordic_nrf/common/nrf54l15/tampc.c @@ -0,0 +1,77 @@ + +/*** + + +*/ + +#include "nrf54l15_enga_application.h" +#include "nrf54l15_enga_global.h" +#include "nrf54l15_enga_types.h" +#include "tfm_hal_platform.h" +#include "tfm_plat_defs.h" +#include +#include + +bool boot_reason_sectamper; + +#define RESET_BY_PERIPHERAL false +#define TAMPER_EVENT_HANDLER tfm_core_panic + +#define TAMPC_REASON (((volatile uint32_t *)0x4010E600)[0]) +void tampc_enable(void); +void tampc_disable(void); + +int init_tampc(void) { + + if (TAMPC_REASON & NRFX_RESET_REASON_SECTAMPER_MASK) { + TAMPC_REASON = NRFX_RESET_REASON_SECTAMPER_MASK; + boot_reason_sectamper = true; + } + + nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER); + nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR); + + tampc_enable(); + nrf_tampc_int_enable(NRF_TAMPC, NRF_TAMPC_ALL_INTS_MASK); + + nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_RESETEN_INT, + RESET_BY_PERIPHERAL); + + NVIC_ClearPendingIRQ(TAMPC_IRQn); + NVIC_ClearTargetState(TAMPC_IRQn); + NVIC_EnableIRQ(TAMPC_IRQn); + + return TFM_PLAT_ERR_SUCCESS; +} + +void tampc_enable(void) { + nrf_tampc_protector_ctrl_value_set( + NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, true); + nrf_tampc_protector_ctrl_value_set( + NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, true); +} + +void tampc_disable(void) { + nrf_tampc_protector_ctrl_value_set( + NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, false); + nrf_tampc_protector_ctrl_value_set( + NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, false); +} + +void TAMPC_Handler(void) { + SPMLOG_ERRMSG("TAMPC Exception:\r\n"); + + if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR)) { + SPMLOG_ERRMSG("\tWrite error.\r\n"); + nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR); + NVIC_ClearPendingIRQ(TAMPC_IRQn); + tfm_core_panic(); + } + + if (nrf_tampc_event_check(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER)) { + SPMLOG_ERRMSG("\tTamper event.\r\n"); + nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER); + NVIC_ClearPendingIRQ(TAMPC_IRQn); + TAMPER_EVENT_HANDLER(); + } +}