Skip to content

Commit feb2c0e

Browse files
committed
platform: nordic: Configure the TAMPC for nRF54L series
Configure the TAMPC peripheral in the nRF54L series to fire an interrupt and result to a TF-M core panic when a Cracen or a slow/fast domain tampering is detected. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent 44bbc98 commit feb2c0e

File tree

8 files changed

+169
-1
lines changed

8 files changed

+169
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ target_sources(platform_s
102102
nrfx_glue.c
103103
native_drivers/mpu_armv8m_drv.c
104104
native_drivers/spu.c
105+
$<$<BOOL:${NRF_TAMPC_ENABLE}>:${CMAKE_CURRENT_SOURCE_DIR}/native_drivers/tampc.c>
105106
$<$<BOOL:${TFM_EXCEPTION_INFO_DUMP}>:${CMAKE_CURRENT_SOURCE_DIR}/nrf_exception_info.c>
106107
$<$<OR:$<BOOL:${TFM_S_REG_TEST}>,$<BOOL:${TFM_NS_REG_TEST}>>:${CMAKE_CURRENT_SOURCE_DIR}/plat_test.c>
107108
$<$<BOOL:${TEST_PSA_API}>:${CMAKE_CURRENT_SOURCE_DIR}/pal_plat_test.c>
@@ -237,6 +238,13 @@ if(NRF_SECURE_APPROTECT)
237238
)
238239
endif()
239240

241+
if(NRF_TAMPC_ENABLE)
242+
target_compile_definitions(tfm_spm
243+
PRIVATE
244+
NRF_TAMPC_ENABLE
245+
)
246+
endif()
247+
240248
#========================= Files for building NS side platform ================#
241249

242250
configure_file(config_nordic_nrf_spe.cmake.in

platform/ext/target/nordic_nrf/common/core/config.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(BL2 ON CACHE BOOL "Whether to b
3838
set(NRF_NS_SECONDARY ${BL2} CACHE BOOL "Enable non-secure secondary partition")
3939
set(NRF_APPROTECT OFF CACHE BOOL "Enable approtect")
4040
set(NRF_SECURE_APPROTECT OFF CACHE BOOL "Enable secure approtect")
41+
set(NRF_TAMPC_ENABLE ON CACHE BOOL "Enable the tamper controller (TAMPC)")
4142

4243
# Platform-specific configurations
4344
set(CONFIG_TFM_USE_TRUSTZONE ON)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,20 @@ void MPC00_IRQHandler(void)
128128
MPC_Handler();
129129
}
130130
#endif
131+
132+
#ifdef NRF_TAMPC
133+
__attribute__((naked)) void TAMPC_IRQHandler(void)
134+
{
135+
EXCEPTION_INFO();
136+
137+
#ifdef TFM_EXCEPTION_INFO_DUMP
138+
nrf_exception_info_store_context();
139+
#endif
140+
141+
tfm_core_panic();
142+
143+
__ASM volatile(
144+
"B . \n"
145+
);
146+
}
147+
#endif
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA.
3+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
20+
#ifndef __TAMPC_H__
21+
#define __TAMPC_H__
22+
23+
#include "target_cfg.h"
24+
#include <nrfx.h>
25+
#include <hal/nrf_tampc.h>
26+
#include <stddef.h>
27+
#include <stdint.h>
28+
#include <stdbool.h>
29+
30+
void tampc_enable_interrupts(void)
31+
{
32+
nrf_tampc_int_enable(NRF_TAMPC, NRF_TAMPC_ALL_INTS_MASK);
33+
}
34+
35+
static void tampc_clear_events(void)
36+
{
37+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_TAMPER);
38+
nrf_tampc_event_clear(NRF_TAMPC, NRF_TAMPC_EVENT_WRITE_ERROR);
39+
}
40+
41+
static void tampc_clear_statuses(void)
42+
{
43+
/* The datasheet states that they detectors must be reset before the status is cleared. */
44+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_CRACEN, false);
45+
nrf_tampc_protector_status_clear(NRF_TAMPC, NRF_TAMPC_PROTECT_CRACEN);
46+
47+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, false);
48+
nrf_tampc_protector_status_clear(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST);
49+
50+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, false);
51+
nrf_tampc_protector_status_clear(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW);
52+
}
53+
54+
void tampc_configuration(void)
55+
{
56+
57+
tampc_clear_events();
58+
tampc_clear_statuses();
59+
60+
/* Make sure that the CRACEN detector and the glitch detectors are enabled and lock
61+
* their configuration.
62+
*/
63+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_CRACEN, true);
64+
nrf_tampc_protector_ctrl_lock_set(NRF_TAMPC, NRF_TAMPC_PROTECT_CRACEN, true);
65+
66+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, true);
67+
nrf_tampc_protector_ctrl_lock_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_FAST, true);
68+
69+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, true);
70+
nrf_tampc_protector_ctrl_lock_set(NRF_TAMPC, NRF_TAMPC_PROTECT_GLITCH_DOMAIN_SLOW, true);
71+
72+
/* The INTRESETEN reset value is enabled on reset, in order to use the TAMPC interrupt
73+
* and not reset the device immediately the INTRESETEN is set to 0 here.
74+
*/
75+
nrf_tampc_protector_ctrl_value_set(NRF_TAMPC, NRF_TAMPC_PROTECT_RESETEN_INT, false);
76+
nrf_tampc_protector_ctrl_lock_set(NRF_TAMPC, NRF_TAMPC_PROTECT_RESETEN_INT, false);
77+
78+
/* The active shield is not configured here yet, this will be added later. */
79+
}
80+
81+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA.
3+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
20+
#ifndef __TAMPC_H__
21+
#define __TAMPC_H__
22+
23+
24+
#include "target_cfg.h"
25+
#include <nrfx.h>
26+
#include <hal/nrf_tampc.h>
27+
#include <stddef.h>
28+
#include <stdint.h>
29+
#include <stdbool.h>
30+
31+
/**
32+
* \brief Enable TAMPC interrupts
33+
*
34+
* Enable interrupts in the INTENSET register of TAMPC.
35+
*/
36+
void tampc_enable_interrupts(void);
37+
38+
/**
39+
* \brief TAMPC configuration
40+
*
41+
* Configures the TAMPC peripheral to monitor for Cracen and slow/fast domain hardware
42+
* attacks and disables the default reset behavior in order to hanlde the event in the
43+
* interrupt handler. It also locks the configuration of the CTRL registers
44+
* so that they cannot be altered until reset.
45+
*
46+
*/
47+
void tampc_configuration(void);
48+
49+
#endif

platform/ext/target/nordic_nrf/common/core/startup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void SPU30_IRQHandler(void);
4444
void MPC00_IRQHandler(void);
4545

4646
void CRACEN_IRQHandler(void);
47+
void TAMPC_IRQHandler(void);
4748

4849
/*
4950
* The default irq handler is used as a backup in case of

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ DEFAULT_IRQ_HANDLER(SAADC_IRQHandler)
8989
DEFAULT_IRQ_HANDLER(NFCT_IRQHandler)
9090
DEFAULT_IRQ_HANDLER(TEMP_IRQHandler)
9191
DEFAULT_IRQ_HANDLER(GPIOTE20_1_IRQHandler)
92-
DEFAULT_IRQ_HANDLER(TAMPC_IRQHandler)
9392
DEFAULT_IRQ_HANDLER(I2S20_IRQHandler)
9493
DEFAULT_IRQ_HANDLER(QDEC20_IRQHandler)
9594
DEFAULT_IRQ_HANDLER(QDEC21_IRQHandler)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <spu.h>
3232
#include <nrfx.h>
33+
#include <tampc.h>
3334

3435
#include <hal/nrf_gpio.h>
3536
#include <hal/nrf_spu.h>
@@ -456,6 +457,10 @@ enum tfm_plat_err_t spu_periph_init_cfg(void)
456457
gpiote_channel_configuration();
457458
gpio_configuration();
458459

460+
#if defined(NRF_TAMPC_ENABLE)
461+
tampc_configuration();
462+
#endif
463+
459464
nrf_cache_enable(NRF_ICACHE);
460465

461466
nrfx_err_t nrfx_err = rramc_configuration();
@@ -488,6 +493,7 @@ enum tfm_plat_err_t nvic_interrupt_target_state_cfg(void)
488493

489494
NVIC_ClearTargetState(NRFX_IRQ_NUMBER_GET(NRF_CRACEN));
490495
NVIC_ClearTargetState(MPC00_IRQn);
496+
NVIC_ClearTargetState(NRFX_IRQ_NUMBER_GET(NRF_TAMPC));
491497

492498
#ifdef SECURE_UART1
493499
/* IRQ for the selected secure UART has to target S state */
@@ -520,5 +526,11 @@ enum tfm_plat_err_t nvic_interrupt_enable(void)
520526
* therefore omitted here.
521527
*/
522528

529+
#if defined(NRF_TAMPC_ENABLE)
530+
tampc_enable_interrupts();
531+
NVIC_ClearPendingIRQ(NRFX_IRQ_NUMBER_GET(NRF_TAMPC));
532+
NVIC_EnableIRQ(NRFX_IRQ_NUMBER_GET(NRF_TAMPC));
533+
#endif
534+
523535
return TFM_PLAT_ERR_SUCCESS;
524536
}

0 commit comments

Comments
 (0)