Skip to content

Commit 32af922

Browse files
committed
modules: trusted-fimware-m: Add memory configuration logs
The only way to extract the actual information about memory regions configured as non-secure is by debugging the code. This commit adds debug functions for printing SAU and MPC configuration of nRF54L devices. It also modifies the existing code printing configuration for MPU and SPU, aligning its implementation with SAU/MPC. A new KConfig option to activate this functionality has also been added. Ref: NCSDK-38986 Signed-off-by: Anton Zyma <anton.zyma@nordicsemi.no>
1 parent 696dfe2 commit 32af922

8 files changed

Lines changed: 118 additions & 5 deletions

File tree

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Security
145145
* Added:
146146

147147
* Support for the X25519 key pair storage in the :ref:`Key Management Unit (KMU) <ug_kmu_guides_supported_key_types>`.
148+
* The :kconfig:option:`CONFIG_TFM_LOG_NS_MEMORY_LAYOUT` to print the configuration of SAU and MPC during TF-M initialization of the nRF54L15 devices.
148149

149150
* Updated:
150151

modules/trusted-firmware-m/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ set_property(TARGET zephyr_property_target
8080
-DPROJECT_CONFIG_HEADER_FILE=${CMAKE_CURRENT_BINARY_DIR}/tfm_config.h
8181
-DTFM_EXTRA_CONFIG_PATH="${CMAKE_CURRENT_BINARY_DIR}/config_extra.cmake"
8282
-DPS_ROLLBACK_PROTECTION=${CONFIG_TFM_PS_ROLLBACK_PROTECTION}
83+
$<$<BOOL:${CONFIG_TFM_LOG_NS_MEMORY_LAYOUT}>:-DNRF_LOG_MEMORY_PROTECTION_SAU_MPC=ON>
8384
$<$<BOOL:${CONFIG_TFM_HW_INIT_RESET_ON_BOOT}>:-DNRF_HW_INIT_RESET_ON_BOOT=ON>
8485
$<$<BOOL:${CONFIG_TFM_ALLOW_NON_SECURE_RESET}>:-DNRF_ALLOW_NON_SECURE_RESET=ON>
8586
$<$<BOOL:${CONFIG_TFM_SECURE_UART0}>:-DNRF_SECURE_UART_INSTANCE=0>

modules/trusted-firmware-m/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,17 @@ config TFM_NFCT_PINS_AS_GPIOS
369369
TF-M configures these pins as GPIOS when the NFCT peripheral is not
370370
enabled in the device-tree of the target.
371371

372+
config TFM_LOG_NS_MEMORY_LAYOUT
373+
bool "Activate debug logs to print non-secure memory layout"
374+
depends on !TFM_LOG_LEVEL_SILENCE
375+
depends on SOC_SERIES_NRF54L
376+
help
377+
This option activates logic to print the configuration of SAU and MPC
378+
during TF-M initialization. It contains address ranges of the non-secure
379+
memory regions (both volatile and non-volatile). The rest of the memory
380+
is secure by default.
381+
This option is currently available for all nRF54L devices.
382+
372383
config TFM_SECURE_UART
373384
bool "TF-M configure UART instance as secure peripheral"
374385
default y if !TFM_LOG_LEVEL_SILENCE

modules/trusted-firmware-m/tfm_boards/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ if(${TFM_PARTITION_CRYPTO})
136136
target_link_libraries(platform_s PRIVATE tfm_psa_rot_partition_crypto)
137137
endif()
138138

139+
if(NRF_LOG_MEMORY_PROTECTION_SAU_MPC)
140+
target_compile_definitions(platform_s PUBLIC NRF_LOG_MEMORY_PROTECTION_SAU_MPC)
141+
target_sources(platform_s PRIVATE src/log_memory_protection_sau_mpc.c)
142+
endif()
143+
144+
if(NRF_LOG_MEMORY_PROTECTION_MPU_SPU)
145+
target_compile_definitions(platform_s PUBLIC NRF_LOG_MEMORY_PROTECTION_MPU_SPU)
146+
target_sources(platform_s PRIVATE src/log_memory_protection_mpu_spu.c)
147+
endif()
148+
139149
if(NRF_ALLOW_NON_SECURE_RESET)
140150
target_compile_definitions(platform_s PUBLIC NRF_ALLOW_NON_SECURE_RESET)
141151
endif()
@@ -205,10 +215,6 @@ if(TFM_PARTITION_PLATFORM)
205215
)
206216
endif()
207217

208-
if(LOG_MEMORY_PROTECTION)
209-
target_sources(platform_s PRIVATE src/log_memory_protection.c)
210-
endif()
211-
212218
if(PSA_CRYPTO_EXTERNAL_CORE)
213219
include(${TFM_BOARDS_NRF_DIR}/external_core.cmake)
214220
endif()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "exception_info.h"
3030
#include "tfm_arch.h"
3131

32+
#if defined(NRF_LOG_MEMORY_PROTECTION_SAU_MPC)
33+
#include <log_memory_protection.h>
34+
#endif /* NRF_LOG_MEMORY_PROTECTION_SAU_MPC */
35+
3236
#if defined(TFM_PARTITION_CRYPTO)
3337
static enum tfm_hal_status_t crypto_platform_init(void)
3438
{
@@ -155,5 +159,9 @@ enum tfm_hal_status_t tfm_hal_platform_init(void)
155159

156160
log_pin_security_configuration();
157161

162+
#if defined(NRF_LOG_MEMORY_PROTECTION_SAU_MPC)
163+
log_memory_protection_sau_mpc();
164+
#endif /* NRF_LOG_MEMORY_PROTECTION_SAU_MPC */
165+
158166
return TFM_HAL_SUCCESS;
159167
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef __LOG_MEMORY_PROTECTION_H
8+
#define __LOG_MEMORY_PROTECTION_H
9+
10+
void log_memory_protection_of_mpu(void);
11+
void log_memory_protection_of_spu_nsc(void);
12+
void log_memory_protection_of_spu_flash(void);
13+
void log_memory_protection_of_spu_ram(void);
14+
void log_memory_protection_of_spu(void);
15+
void log_memory_protection_mpu_spu(void);
16+
17+
void log_memory_protection_sau_mpc(void);
18+
19+
#endif /* __LOG_MEMORY_PROTECTION_H */

modules/trusted-firmware-m/tfm_boards/src/log_memory_protection.c renamed to modules/trusted-firmware-m/tfm_boards/src/log_memory_protection_mpu_spu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include <log_memory_protection.h>
78
#include <cmsis.h>
89
#include <tfm_spm_log.h>
910
#include <mpu_armv8m_drv.h>
@@ -98,7 +99,7 @@ void log_memory_protection_of_spu(void)
9899
log_memory_protection_of_spu_ram();
99100
}
100101

101-
void log_memory_protection(void)
102+
void log_memory_protection_mpu_spu(void)
102103
{
103104
log_memory_protection_of_mpu();
104105
log_memory_protection_of_spu();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <log_memory_protection.h>
8+
#include <cmsis.h>
9+
#include <hal/nrf_mpc.h>
10+
#include <tfm_spm_log.h>
11+
12+
static void log_memory_protection_sau(void)
13+
{
14+
uint32_t sau_regions_count = SAU->TYPE;
15+
uint32_t limit_address;
16+
17+
SPMLOG_INFMSG("SAU config:\r\n");
18+
for (uint32_t i = 0; i < sau_regions_count; i++) {
19+
SAU->RNR = i;
20+
21+
limit_address = SAU->RLAR;
22+
if (limit_address & SAU_RLAR_ENABLE_Msk) {
23+
if (limit_address & SAU_RLAR_NSC_Msk) {
24+
SPMLOG_INFMSG("NCS region\r\n");
25+
} else {
26+
SPMLOG_INFMSG("NS region\r\n");
27+
}
28+
limit_address &= ~(SAU_RLAR_ENABLE_Msk | SAU_RLAR_NSC_Msk);
29+
30+
SPMLOG_INFMSGVAL(" Base addr : ", SAU->RBAR);
31+
SPMLOG_INFMSGVAL(" Limit addr: ", limit_address);
32+
}
33+
}
34+
}
35+
36+
static void log_memory_protection_mpc(void)
37+
{
38+
/* On 54l the NRF_MPC00->REGION[]'s are fixed in HW and the
39+
* OVERRIDE indexes (that are useful to us) start at 0 and end
40+
* (inclusive) at 4.
41+
*/
42+
const uint32_t max_index = 4;
43+
uint32_t address;
44+
nrf_mpc_override_config_t config;
45+
46+
SPMLOG_INFMSG("MPC config:\r\n");
47+
for (uint32_t i = 0; i <= max_index; i++) {
48+
config = nrf_mpc_override_config_get(NRF_MPC00, i);
49+
if (config.enable) {
50+
SPMLOG_INFMSG("NS region\r\n");
51+
address = nrf_mpc_override_startaddr_get(NRF_MPC00, i);
52+
SPMLOG_INFMSGVAL(" Base addr: ", address);
53+
54+
address = nrf_mpc_override_endaddr_get(NRF_MPC00, i);
55+
SPMLOG_INFMSGVAL(" End addr : ", address);
56+
}
57+
}
58+
}
59+
60+
void log_memory_protection_sau_mpc(void)
61+
{
62+
SPMLOG_INFMSG("** NS memory layout config start **\r\n");
63+
log_memory_protection_sau();
64+
log_memory_protection_mpc();
65+
SPMLOG_INFMSG("** NS memory layout config end **\r\n");
66+
}

0 commit comments

Comments
 (0)