Skip to content

Commit cf67fee

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Replace SPM log with tfm_log
Replace the existing SPM log library with the new tfm_log library. This patch aims to maintain existing behaviour by using a format specifier which matches the existing implementation. Change-Id: I5871b5429e4f051fdede87063bfe3ebbe49847f9 Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit af54602) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent b6b3f17 commit cf67fee

File tree

41 files changed

+308
-456
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

+308
-456
lines changed

config/build_type/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ config CONFIG_TFM_HALT_ON_CORE_PANIC
1515
default y
1616

1717
choice SPM_LOG_LEVEL
18-
default SPM_LOG_LEVEL_DEBUG
18+
default LOG_LEVEL_VERBOSE
1919
endchoice
2020

2121
choice PARTITION_LOG_LEVEL

config/build_type/Kconfig.minsizerel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config MCUBOOT_LOG_LEVEL
1111
endif
1212

1313
choice SPM_LOG_LEVEL
14-
default SPM_LOG_LEVEL_SILENCE
14+
default LOG_LEVEL_NONE
1515
endchoice
1616

1717
choice PARTITION_LOG_LEVEL

config/build_type/Kconfig.release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ config MCUBOOT_LOG_LEVEL
1717
endif
1818

1919
choice SPM_LOG_LEVEL
20-
default SPM_LOG_LEVEL_SILENCE
20+
default LOG_LEVEL_NONE
2121
endchoice
2222

2323
choice PARTITION_LOG_LEVEL

config/build_type/debug.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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")
10-
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_DEBUG CACHE STRING "Set debug SPM log level as Debug level")
10+
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_VERBOSE CACHE STRING "Set debug SPM log level as Debug level")
1111
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#-------------------------------------------------------------------------------
77

88
set(MCUBOOT_LOG_LEVEL "OFF" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
9-
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set minsizerel SPM log level as Silence level")
9+
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set minsizerel SPM log level as Silence level")
1010
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
set(MBEDCRYPTO_BUILD_TYPE minsizerel CACHE STRING "Build type of Mbed Crypto library")
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]")
11-
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set release SPM log level as Silence level")
11+
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set release SPM log level as Silence level")
1212
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
#-------------------------------------------------------------------------------
77

8-
set(TFM_SPM_LOG_LEVEL TFM_SPM_LOG_LEVEL_SILENCE CACHE STRING "Set default SPM log level as INFO level")
8+
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set default SPM log level as INFO level")
99
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
@@ -18,7 +18,7 @@ endif()
1818

1919
# SP log relies on SPM log.
2020
# Enable SPM log when SPM log level is higher than silence or SP log is active.
21-
if ((NOT ${TFM_SPM_LOG_LEVEL} STREQUAL TFM_SPM_LOG_LEVEL_SILENCE)
21+
if ((NOT ${TFM_SPM_LOG_LEVEL} STREQUAL LOG_LEVEL_NONE)
2222
OR TFM_SP_LOG_RAW_ENABLED)
2323
set(TFM_SPM_LOG_RAW_ENABLED ON)
2424
endif()

docs/design_docs/tfm_log_system_design_document.rst

Lines changed: 38 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -45,92 +45,57 @@ Level Control
4545
-------------
4646
Three log levels for SPM log system are defined:
4747

48-
- TFM_SPM_LOG_LEVEL_DEBUG
49-
- TFM_SPM_LOG_LEVEL_INFO
50-
- TFM_SPM_LOG_LEVEL_ERROR
51-
- TFM_SPM_LOG_LEVEL_SILENCE
48+
- LOG_LEVEL_NONE
49+
- LOG_LEVEL_ERROR
50+
- LOG_LEVEL_NOTICE
51+
- LOG_LEVEL_WARNING
52+
- LOG_LEVEL_INFO
53+
- LOG_LEVEL_VERBOSE
5254

5355
Then a macro ``TFM_SPM_LOG_LEVEL`` is defined as an indicator, it should
54-
be equal to one of the four log levels.
56+
be equal to one of the six log levels.
5557

5658
API Definition
5759
--------------
58-
The following three APIs LOG APIs output the given 'msg' with hexadecimal
59-
formatted 'val' together. These APIs provide constrained ability to output
60-
numbers inside SPM. The 'msg' can be skipped with giving an empty string like
61-
"". And these APIs supports constant 'msg' string only, giving a runtime string
62-
as parameter 'msg' would potentially cause a runtime error.
60+
The following APIs output the string with optional format specifiers.
61+
The _RAW forms of the macros, output the string directly, without
62+
adding a prefix identifying the log level of the print:
6363

64-
SPMLOG_DBGMSGVAL(msg, val);
64+
VERBOSE_RAW(...);
65+
VERBOSE(...);
6566

66-
SPMLOG_INFMSGVAL(msg, val);
67+
INFO_RAW(...);
68+
INFO(...);
6769

68-
SPMLOG_ERRMSGVAL(msg, val);
70+
WARN(...);
71+
WARN_RAW(...);
6972

70-
A C-function needs to work as an underlayer for these APIs as string formatting
71-
is required. Check 'spm_log_msgval' for details.
72-
73-
.. code-block:: c
73+
NOTICE(...);
74+
NOTICE_RAW(...);
7475

75-
/**
76-
* brief Output the given message plus one value as hexadecimal. The message
77-
* can be skipped if the 'msg' is 'NULL' or 'len' equals 0. The
78-
* formatted hexadecimal string for 'value' has a '0x' prefix and
79-
* leading zeros are not stripped. This function rely on HAL API
80-
* 'tfm_hal_output_spm_log' to output the formatted string.
81-
*
82-
* \param[in] msg A string message
83-
* \param[in] len The length of the message
84-
* \param[in] value A value need to be output
85-
*
86-
* \retval >=0 Number of chars output.
87-
* \retval <0 TFM HAL error code.
88-
*/
89-
int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value)
90-
91-
The following three APIs output a message in string.
92-
93-
SPMLOG_DBGMSG(msg);
94-
95-
SPMLOG_INFMSG(msg);
96-
97-
SPMLOG_ERRMSG(msg);
76+
ERROR(...);
77+
ERROR_RAW(...);
9878

9979
Here is a table about the effective APIs with different SPM log level.
10080

101-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
102-
| | TFM_SPM_LOG_LEVEL_DEBUG | TFM_SPM_LOG_LEVEL_INFO | TFM_SPM_LOG_LEVEL_ERROR | TFM_SPM_LOG_LEVEL_SILENCE |
103-
+==================+=========================+===========================+===========================+=============================+
104-
| SPMLOG_DBGMSGVAL | Yes | No | No | No |
105-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
106-
| SPMLOG_INFMSGVAL | Yes | Yes | No | No |
107-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
108-
| SPMLOG_ERRMSGVAL | Yes | Yes | Yes | No |
109-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
110-
| SPMLOG_DBGMSG | Yes | No | No | No |
111-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
112-
| SPMLOG_INFMSG | Yes | Yes | No | No |
113-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
114-
| SPMLOG_ERRMSG | Yes | Yes | Yes | No |
115-
+------------------+-------------------------+---------------------------+---------------------------+-----------------------------+
116-
117-
HAL API
118-
-------
119-
Define HAL API for SPM log system:
120-
121-
.. code-block:: c
122-
123-
/* SPM log HAL API */
124-
int32_t tfm_hal_output_spm_log(const char *str, uint32_t len);
125-
126-
Take debug message as an example:
127-
128-
.. code-block:: c
129-
130-
/* For debug message */
131-
#define SPMLOG_DBGMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
132-
/* For debug message with a value */
133-
#define SPMLOG_DBGMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
81+
+--------------------+--------+------+-------+------+
82+
| | DEBUG | INFO | ERROR | NONE |
83+
+====================+========+======+=======+======+
84+
| VERBOSE_RAW | Yes | No | No | No |
85+
| VERBOSE | | | | |
86+
+--------------------+--------+------+-------+------+
87+
| INFO_RAW | Yes | Yes | No | No |
88+
| INFO | | | | |
89+
+--------------------+--------+------+-------+------+
90+
| NOTICE_RAW | Yes | Yes | No | No |
91+
| NOTICE | | | | |
92+
+--------------------+--------+------+-------+------+
93+
| WARN_RAW | Yes | Yes | No | No |
94+
| WARN | | | | |
95+
+--------------------+--------+------+-------+------+
96+
| ERROR_RAW | Yes | Yes | Yes | No |
97+
| ERROR | | | | |
98+
+--------------------+--------+------+-------+------+
13499

135100
Partition Log System
136101
====================

lib/tfm_log/inc/tfm_log.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,23 @@
6161
# define INFO_RAW(...) no_tfm_log(LOG_MARKER_RAW __VA_ARGS__)
6262
#endif
6363

64+
/* FixMe: psa_arch_tests currently defines a VERBOSE macro in the build
65+
* system to specify the verbosity of its logging. Usually this would be
66+
* fine as the psa_arch_tests do not use tfm_log at all. However, because of
67+
* the redefinition of 'assert.h' in the SPM, we end up indirectly including
68+
* tfm_log.h via various system headers. This should be fixed by reworking
69+
* the SPM 'assert.h' implementation but for now, avoid redefining the
70+
* VERBOSE macro
71+
*/
72+
#ifndef VERBOSE
6473
#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
6574
# define VERBOSE(...) tfm_log(LOG_MARKER_VERBOSE __VA_ARGS__)
6675
# define VERBOSE_RAW(...) tfm_log(LOG_MARKER_RAW __VA_ARGS__)
6776
#else
6877
# define VERBOSE(...) no_tfm_log(LOG_MARKER_VERBOSE __VA_ARGS__)
6978
# define VERBOSE_RAW(...) no_tfm_log(LOG_MARKER_RAW __VA_ARGS__)
7079
#endif
80+
#endif /* VERBOSE */
7181

7282
#if defined(__ICCARM__)
7383
#pragma __printf_args

platform/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,26 @@ target_link_libraries(platform_s
9999
tfm_fih_headers
100100
cmsis_stack_override
101101
cmsis
102+
tfm_log_headers
103+
tfm_vprintf_headers
102104
$<$<BOOL:${CONFIG_TFM_BACKTRACE_ON_CORE_PANIC}>:tfm_log_unpriv>
103105
$<$<BOOL:${CONFIG_TFM_BACKTRACE_ON_CORE_PANIC}>:tfm_log>
104106
$<$<BOOL:${CONFIG_TFM_BACKTRACE_ON_CORE_PANIC}>:tfm_backtrace>
105107
PRIVATE
106108
tfm_config
107-
tfm_spm_defs # For tfm_spm_log.h
109+
tfm_spm_defs
108110
$<$<BOOL:${TFM_PARTITION_CRYPTO}>:platform_crypto_keys>
109111
$<$<BOOL:${PLATFORM_DEFAULT_ATTEST_HAL}>:tfm_sprt>
110112
$<$<BOOL:${TFM_PARTITION_CRYPTO}>:crypto_service_mbedcrypto>
111113
$<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:tfm_attestation_defs>
112114
$<$<NOT:$<STREQUAL:${TFM_FIH_PROFILE},OFF>>:tfm_fih>
115+
tfm_log
113116
psa_crypto_library_config
114117
)
115118

116119
target_compile_definitions(platform_s
117120
PUBLIC
118-
TFM_SPM_LOG_LEVEL=${TFM_SPM_LOG_LEVEL}
121+
LOG_LEVEL=${TFM_SPM_LOG_LEVEL}
119122
$<$<BOOL:${TFM_SPM_LOG_RAW_ENABLED}>:TFM_SPM_LOG_RAW_ENABLED>
120123
$<$<BOOL:${CONFIG_TFM_BACKTRACE_ON_CORE_PANIC}>:CONFIG_TFM_BACKTRACE_ON_CORE_PANIC>
121124
$<$<BOOL:${CONFIG_TFM_BACKTRACE_ON_CORE_PANIC}>:LOG_LEVEL=LOG_LEVEL_ERROR>
@@ -133,8 +136,8 @@ target_compile_definitions(platform_s
133136
$<$<BOOL:${PLATFORM_DEFAULT_OTP}>:PLATFORM_DEFAULT_OTP>
134137
$<$<BOOL:${PLATFORM_DEFAULT_ROTPK}>:PLATFORM_DEFAULT_ROTPK>
135138
$<$<BOOL:${PLATFORM_DEFAULT_NV_COUNTERS}>:PLATFORM_DEFAULT_NV_COUNTERS>
136-
$<$<AND:$<BOOL:${TFM_LOG_FATAL_ERRORS}>,$<NOT:$<STREQUAL:${TFM_SPM_LOG_LEVEL},"TFM_SPM_LOG_LEVEL_SILENCE">>>:LOG_FATAL_ERRORS>
137-
$<$<AND:$<BOOL:${TFM_LOG_NONFATAL_ERRORS}>,$<NOT:$<STREQUAL:${TFM_SPM_LOG_LEVEL},"TFM_SPM_LOG_LEVEL_SILENCE">>>:LOG_NONFATAL_ERRORS>
139+
$<$<AND:$<BOOL:${TFM_LOG_FATAL_ERRORS}>,$<NOT:$<STREQUAL:${TFM_SPM_LOG_LEVEL},"LOG_LEVEL_NONE">>>:LOG_FATAL_ERRORS>
140+
$<$<AND:$<BOOL:${TFM_LOG_NONFATAL_ERRORS}>,$<NOT:$<STREQUAL:${TFM_SPM_LOG_LEVEL},"LOG_LEVEL_NONE">>>:LOG_NONFATAL_ERRORS>
138141
PRIVATE
139142
$<$<BOOL:${SYMMETRIC_INITIAL_ATTESTATION}>:SYMMETRIC_INITIAL_ATTESTATION>
140143
$<$<BOOL:${TFM_DUMMY_PROVISIONING}>:TFM_DUMMY_PROVISIONING>

0 commit comments

Comments
 (0)