Skip to content

Commit cb57dc4

Browse files
committed
WIP
Fixes an issue with linking errors because out is not defined. Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
1 parent bcbb4ef commit cb57dc4

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

subsys/nrf_security/configs/psa_crypto_config.h.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
#cmakedefine MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
2525
#cmakedefine MBEDTLS_PLATFORM_SNPRINTF_ALT
2626

27+
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && defined(__NRF_TFM__)
28+
int nrf_security_tfm_printf(const char *fmt, ...);
29+
#define MBEDTLS_PLATFORM_STD_PRINTF nrf_security_tfm_printf
30+
#endif
31+
2732
/* TF-M */
2833
#cmakedefine MBEDTLS_PSA_CRYPTO_SPM
2934

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/*
8+
* To be used as MBEDTLS_PLATFORM_STD_PRINTF inside the TF-M secure image.
9+
* Without this, taking the address of libc printf (the mbedtls default) pulls
10+
* picolibc's stdio into tfm_s.
11+
*
12+
* When TF-M is built without secure log output (TFM_SP_LOG_RAW_ENABLED=OFF),
13+
* tfm_hal_output_sp_log() is not provided and tfm_vprintf_unpriv() cannot be
14+
* linked. In that case fall back to a silent no-op.
15+
*/
16+
17+
#include <stdarg.h>
18+
19+
#ifdef NRF_SECURITY_TFM_HAS_SP_LOG
20+
#include "tfm_vprintf_unpriv.h"
21+
#endif
22+
23+
int nrf_security_tfm_printf(const char *fmt, ...)
24+
{
25+
#ifdef NRF_SECURITY_TFM_HAS_SP_LOG
26+
va_list args;
27+
int ret;
28+
29+
va_start(args, fmt);
30+
ret = tfm_vprintf_unpriv(fmt, args);
31+
va_end(args);
32+
33+
return ret;
34+
#else
35+
(void)fmt;
36+
return 0;
37+
#endif
38+
}
39+
40+
41+
42+

subsys/nrf_security/src/utils/nrf_security_utils.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ target_include_directories(psa_crypto_library_config
2121
)
2222

2323
if(BUILD_INSIDE_TFM)
24+
target_sources(nrf_security_utils
25+
PRIVATE
26+
${CMAKE_CURRENT_LIST_DIR}/nrf_security_tfm_printf.c
27+
)
28+
29+
# tfm_vprintf_unpriv() ultimately calls tfm_hal_output_sp_log(), which is
30+
# only provided when TF-M is built with TFM_SP_LOG_RAW_ENABLED=ON (i.e. a
31+
# secure UART is enabled). When logging is silenced, compile the wrapper
32+
# as a no-op to avoid an undefined reference at link time.
33+
if(TFM_SP_LOG_RAW_ENABLED)
34+
set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/nrf_security_tfm_printf.c
35+
APPEND PROPERTY COMPILE_DEFINITIONS NRF_SECURITY_TFM_HAS_SP_LOG)
36+
endif()
37+
2438
# This gives access to cmsis, nrfx and mdk. Link tfm_log_unpriv to
2539
# resolve the tfm_log_unpriv() symbol forward-declared by the
2640
# Zephyr-compat <zephyr/sys/__assert.h> shim (the replacement

0 commit comments

Comments
 (0)