Skip to content

Commit b6b3f17

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Move partitions to use new logging API
Make use of the new unprivileged logging API throughout the secure partitions. This mainly does drop in replacements for the existing macros to the new LOG_UNPRIV macros. Note that as part of this change, we replace the existing remove tfm_sp_log_raw.c which implemented the vprintf standard library function. This function is still by some platforms and external libraries in TF-M and therefore we add a new implementation which makes use of the implementation in the new unpriv logging library. Change-Id: I58c7f71fabab0984fe42560c6c20ca313bd5aa60 Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit 1f2c7fd) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent bfa979e commit b6b3f17

File tree

41 files changed

+261
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+261
-490
lines changed

config/build_type/Kconfig.debug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2023, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -19,5 +19,5 @@ choice SPM_LOG_LEVEL
1919
endchoice
2020

2121
choice PARTITION_LOG_LEVEL
22-
default PARTITION_LOG_LEVEL_DEBUG
22+
default LOG_LEVEL_VERBOSE
2323
endchoice

config/build_type/Kconfig.minsizerel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2023, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -15,5 +15,5 @@ choice SPM_LOG_LEVEL
1515
endchoice
1616

1717
choice PARTITION_LOG_LEVEL
18-
default PARTITION_LOG_LEVEL_SILENCE
18+
default LOG_LEVEL_NONE
1919
endchoice

config/build_type/Kconfig.release

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2023, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -21,5 +21,5 @@ choice SPM_LOG_LEVEL
2121
endchoice
2222

2323
choice PARTITION_LOG_LEVEL
24-
default PARTITION_LOG_LEVEL_SILENCE
24+
default LOG_LEVEL_NONE
2525
endchoice

config/build_type/debug.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -8,6 +8,6 @@
88
set(MBEDCRYPTO_BUILD_TYPE relwithdebinfo CACHE STRING "Build type of Mbed Crypto library")
99
set(BL1_2_BUILD_TYPE relwithdebinfo CACHE STRING "Build type of BL1_2")
1010
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_DEBUG CACHE STRING "Set debug SPM log level as Debug level")
11-
set(TFM_PARTITION_LOG_LEVEL TFM_PARTITION_LOG_LEVEL_DEBUG CACHE STRING "Set debug SP log level as Debug level")
11+
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_VERBOSE CACHE STRING "Set debug SP log level as Debug level")
1212

1313
set(CONFIG_TFM_HALT_ON_CORE_PANIC ON CACHE BOOL "On fatal errors in the secure firmware, halt instead of rebooting.")

config/build_type/minsizerel.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66
#-------------------------------------------------------------------------------
77

88
set(MCUBOOT_LOG_LEVEL "OFF" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
99
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set minsizerel SPM log level as Silence level")
10-
set(TFM_PARTITION_LOG_LEVEL TFM_PARTITION_LOG_LEVEL_SILENCE CACHE STRING "Set minsizerel SP log level as Silence level")
10+
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set minsizerel SP log level as Silence level")
1111
set(TFM_BL1_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "The level of BL1 logging to uart")

config/build_type/release.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -9,5 +9,5 @@ set(MBEDCRYPTO_BUILD_TYPE minsizerel CACHE STRING "Build type o
99
set(BL1_2_BUILD_TYPE minsizerel CACHE STRING "Build type of BL1_2")
1010
set(MCUBOOT_LOG_LEVEL "OFF" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
1111
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set release SPM log level as Silence level")
12-
set(TFM_PARTITION_LOG_LEVEL TFM_PARTITION_LOG_LEVEL_SILENCE CACHE STRING "Set release SP log level as Silence level")
12+
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set release SP log level as Silence level")
1313
set(TFM_BL1_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "The level of BL1 logging to uart")

config/tfm_secure_log.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2021, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66
#-------------------------------------------------------------------------------
77

88
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set default SPM log level as INFO level")
9-
set(TFM_PARTITION_LOG_LEVEL TFM_PARTITION_LOG_LEVEL_SILENCE CACHE STRING "Set default Secure Partition log level as INFO level")
9+
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set default Secure Partition log level as INFO level")
1010

1111
# Secure regression tests also require SP log function
1212
# Enable SP log raw dump when SP log level is higher than silence or TF-M
1313
# regression test is enabled.
14-
if ((NOT ${TFM_PARTITION_LOG_LEVEL} STREQUAL TFM_PARTITION_LOG_LEVEL_SILENCE)
14+
if ((NOT ${TFM_PARTITION_LOG_LEVEL} STREQUAL LOG_LEVEL_NONE)
1515
OR TFM_S_REG_TEST OR TFM_NS_REG_TEST)
1616
set(TFM_SP_LOG_RAW_ENABLED ON)
1717
endif()

docs/design_docs/tfm_log_system_design_document.rst

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,21 @@ Take debug message as an example:
135135
Partition Log System
136136
====================
137137
Partition log outputting required rich formatting in particular cases. There is
138-
a customized print inside TF-M(``printf``), and it is wrapped as macro.
138+
a customized print inside TF-M(``tfm_log_unpriv``), and it is wrapped as macro.
139139

140140
Level Control
141141
-------------
142142
Three log levels for partition log system are defined:
143143

144-
- TFM_PARTITION_LOG_LEVEL_DEBUG
145-
- TFM_PARTITION_LOG_LEVEL_INFO
146-
- TFM_PARTITION_LOG_LEVEL_ERROR
147-
- TFM_PARTITION_LOG_LEVEL_SILENCE
144+
- LOG_LEVEL_NONE
145+
- LOG_LEVEL_ERROR
146+
- LOG_LEVEL_NOTICE
147+
- LOG_LEVEL_WARNING
148+
- LOG_LEVEL_INFO
149+
- LOG_LEVEL_VERBOSE
148150

149151
Then a macro ``TFM_PARTITION_LOG_LEVEL`` is defined as an indicator. It should
150-
be equal to one of the four log levels and it is an overall setting for all
152+
be equal to one of the six log levels and it is an overall setting for all
151153
partitions.
152154

153155
Log Format
@@ -160,30 +162,48 @@ log APIs use a format outputting to output various type of data:
160162
%d - decimal signed integer
161163
%u - decimal unsigned integer
162164
%x - hex(hexadecimal)
163-
%c - char(character)
164165
%s - string
165166
166167
API Definition
167168
--------------
168169
Define partition log APIs:
169170

170-
LOG_DBGFMT(...);
171+
VERBOSE_UNPRIV_RAW(...);
172+
VERBOSE_UNPRIV(...);
171173

172-
LOG_INFFMT(...);
174+
INFO_UNPRIV_RAW(...);
175+
INFO_UNPRIV(...);
173176

174-
LOG_ERRFMT(...);
177+
WARN_UNPRIV(...);
178+
WARN_UNPRIV_RAW(...);
179+
180+
NOTICE_UNPRIV(...);
181+
NOTICE_UNPRIV_RAW(...);
182+
183+
ERROR_UNPRIV(...);
184+
ERROR_UNPRIV_RAW(...);
175185

176186
Here is a table about the effective APIs with different partition log level.
177187

178-
+------------+-------------------------------+---------------------------------+---------------------------------+---------------------------------+
179-
| | TFM_PARTITION_LOG_LEVEL_DEBUG | TFM_PARTITION_LOG_LEVEL_INFO | TFM_PARTITION_LOG_LEVEL_ERROR | TFM_PARTITION_LOG_LEVEL_SILENCE |
180-
+============+===============================+=================================+=================================+=================================+
181-
| LOG_DBGFMT | Yes | No | No | No |
182-
+------------+-------------------------------+---------------------------------+---------------------------------+---------------------------------+
183-
| LOG_INFFMT | Yes | Yes | No | No |
184-
+------------+-------------------------------+---------------------------------+---------------------------------+---------------------------------+
185-
| LOG_ERRFMT | Yes | Yes | Yes | No |
186-
+------------+-------------------------------+---------------------------------+---------------------------------+---------------------------------+
188+
+--------------------+--------+------+-------+------+
189+
| | DEBUG | INFO | ERROR | NONE |
190+
+====================+========+======+=======+======+
191+
| VERBOSE_UNPRIV_RAW | Yes | No | No | No |
192+
| VERBOSE_UNPRIV | | | | |
193+
+--------------------+--------+------+-------+------+
194+
| INFO_UNPRIV_RAW | Yes | Yes | No | No |
195+
| INFO_UNPRIV | | | | |
196+
+--------------------+--------+------+-------+------+
197+
| NOTICE_UNPRIV_RAW | Yes | Yes | No | No |
198+
| NOTICE_UNPRIV | | | | |
199+
+--------------------+--------+------+-------+------+
200+
| WARN_UNPRIV_RAW | Yes | Yes | No | No |
201+
| WARN_UNPRIV | | | | |
202+
+--------------------+--------+------+-------+------+
203+
| ERROR_UNPRIV_RAW | Yes | Yes | Yes | No |
204+
| ERROR_UNPRIV | | | | |
205+
+--------------------+--------+------+-------+------+
206+
187207

188208
HAL API
189209
-------
@@ -206,4 +226,4 @@ These log device interfaces are abstracted into HAL APIs.
206226

207227
--------------
208228

209-
*Copyright (c) 2020, Arm Limited. All rights reserved.*
229+
*SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors*

lib/tfm_log_unpriv/inc/tfm_log_unpriv.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313

1414
#include "tfm_vprintf.h"
1515

16+
/*
17+
* FixMe: Note that this library is for logging from unprivileged App RoT partitions
18+
* that cannot access the UART. Logging is therefore routed through to the SPM
19+
* via an SVC. There is no harm in also using this for PSA RoT partitions as well but
20+
* this should not be necessary and will be a performance hit.
21+
*
22+
* Uses of this library throughout PSA RoT partitions should be vetting and possibly
23+
* changed to use tfm_log.h which writes directly to the UART.
24+
*/
25+
1626
/*
1727
* If the log output is too low then this macro is used in place of tfm_log_unpriv()
1828
* below. The intent is to get the compiler to evaluate the function call for

platform/ext/accelerator/cc312/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -25,7 +25,7 @@ target_include_directories(psa_crypto_library_config
2525
# CC log level is controlled indirectly through the SP log level. When SP log is
2626
# disabled we can assume that the CC log should also be turned off. Otherwise,
2727
# enable only if debugging information may be needed.
28-
if(${TFM_PARTITION_LOG_LEVEL} STREQUAL TFM_PARTITION_LOG_LEVEL_SILENCE)
28+
if(${TFM_PARTITION_LOG_LEVEL} STREQUAL LOG_LEVEL_NONE)
2929
set(CC_LOG_ENABLED OFF)
3030
else()
3131
set(CC_LOG_ENABLED $<CONFIG:Debug,relwithdebinfo>)

0 commit comments

Comments
 (0)