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>
diff --git a/secure_fw/spm/CMakeLists.txt b/secure_fw/spm/CMakeLists.txt
index fd6c2d5..8af0bee 100644
--- a/secure_fw/spm/CMakeLists.txt
+++ b/secure_fw/spm/CMakeLists.txt
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
# Copyright (c) 2021-2023 Cypress Semiconductor Corporation (an Infineon
# company) or an affiliate of Cypress Semiconductor Corporation. All rights
# reserved.
@@ -48,7 +48,6 @@
PRIVATE
core/tfm_boot_data.c
core/utilities.c
- $<$<NOT:$<STREQUAL:${TFM_SPM_LOG_LEVEL},TFM_SPM_LOG_LEVEL_SILENCE>>:core/spm_log.c>
core/arch/tfm_arch.c
core/main.c
core/spm_ipc.c
diff --git a/secure_fw/spm/Kconfig b/secure_fw/spm/Kconfig
index aa4c3a8..9c81c8b 100644
--- a/secure_fw/spm/Kconfig
+++ b/secure_fw/spm/Kconfig
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -111,27 +111,35 @@
choice SPM_LOG_LEVEL
prompt "SPM Log Level"
- default SPM_LOG_LEVEL_SILENCE
+ default LOG_LEVEL_NONE
- config SPM_LOG_LEVEL_DEBUG
- bool "Debug"
+ config LOG_LEVEL_VERBOSE
+ bool "Verbose"
- config SPM_LOG_LEVEL_INFO
+ config LOG_LEVEL_INFO
bool "Info"
- config SPM_LOG_LEVEL_ERROR
+ config LOG_LEVEL_WARNING
+ bool "Warning"
+
+ config LOG_LEVEL_NOTICE
+ bool "Notice"
+
+ config LOG_LEVEL_ERROR
bool "Error"
- config SPM_LOG_LEVEL_SILENCE
- bool "Silence"
+ config LOG_LEVEL_NONE
+ bool "None"
endchoice
config TFM_SPM_LOG_LEVEL
int
- default 3 if SPM_LOG_LEVEL_DEBUG
- default 2 if SPM_LOG_LEVEL_INFO
- default 1 if SPM_LOG_LEVEL_ERROR
- default 0 if SPM_LOG_LEVEL_SILENCE
+ default 50 if LOG_LEVEL_VERBOSE
+ default 40 if LOG_LEVEL_INFO
+ default 30 if LOG_LEVEL_WARN
+ default 20 if LOG_LEVEL_NOTICE
+ default 10 if LOG_LEVEL_ERROR
+ default 0 if LOG_LEVEL_NONE
endmenu
diff --git a/secure_fw/spm/core/main.c b/secure_fw/spm/core/main.c
index 277cdd6..d7271fb 100644
--- a/secure_fw/spm/core/main.c
+++ b/secure_fw/spm/core/main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2023, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -13,7 +13,7 @@
#include "spm.h"
#include "tfm_hal_isolation.h"
#include "tfm_hal_platform.h"
-#include "tfm_spm_log.h"
+#include "tfm_log.h"
#include "tfm_version.h"
#include "tfm_plat_otp.h"
#include "tfm_plat_provisioning.h"
@@ -54,7 +54,7 @@
* Print the TF-M version now that the platform has initialized
* the logging backend.
*/
- SPMLOG_INFMSG("\033[1;34mBooting TF-M "VERSION_FULLSTR"\033[0m\r\n");
+ INFO_RAW("\033[1;34mBooting TF-M "VERSION_FULLSTR"\033[0m\n");
plat_err = tfm_plat_otp_init();
if (plat_err != TFM_PLAT_ERR_SUCCESS) {
@@ -74,16 +74,16 @@
/* Configures architecture */
tfm_arch_config_extensions();
- SPMLOG_INFMSG("\033[1;34m[Sec Thread] Secure image initializing!\033[0m\r\n");
+ INFO_RAW("\033[1;34m[Sec Thread] Secure image initializing!\033[0m\n");
- SPMLOG_DBGMSGVAL("TF-M isolation level is: ", TFM_ISOLATION_LEVEL);
+ VERBOSE_RAW("TF-M isolation level is: 0x%08x\n", TFM_ISOLATION_LEVEL);
#if (CONFIG_TFM_FLOAT_ABI == 2)
- SPMLOG_INFMSG("TF-M Float ABI: Hard\r\n");
+ INFO_RAW("TF-M Float ABI: Hard\n");
#ifdef CONFIG_TFM_LAZY_STACKING
- SPMLOG_INFMSG("Lazy stacking enabled\r\n");
+ INFO_RAW("Lazy stacking enabled\n");
#else
- SPMLOG_INFMSG("Lazy stacking disabled\r\n");
+ INFO_RAW("Lazy stacking disabled\n");
#endif
#endif
diff --git a/secure_fw/spm/core/spm_log.c b/secure_fw/spm/core/spm_log.c
deleted file mode 100644
index b15f87d..0000000
--- a/secure_fw/spm/core/spm_log.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "tfm_spm_log.h"
-
-#define MAX_DIGIT_BITS 12 /* 8 char for number, 2 for '0x' and 2 for '\r\n' */
-const static char HEX_TABLE[] = {'0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
-
-/**
- * \brief Convert digit number into HEX format string, the string have '0x'
- * prefix and leading zeros are not stripped.
- *
- * \param[in] value A value need to be converted.
- * \param[in] msg A string message that the value converted to.
- *
- */
-
-static void to_hex(uint32_t value, char msg[])
-{
- int i = MAX_DIGIT_BITS - 1;
-
- msg[i--] = '\n';
- msg[i--] = '\r';
- for (; i > 1; i--, value >>= 4) {
- msg[i] = HEX_TABLE[value & 0xF];
- }
- msg[i--] = 'x';
- msg[i--] = '0';
-}
-
-int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value)
-{
- int32_t result_msg = 0, result_val;
- char value_str[MAX_DIGIT_BITS];
-
- if (msg && len) {
- result_msg = tfm_hal_output_spm_log(msg, len);
- if (result_msg < TFM_HAL_SUCCESS) {
- return result_msg;
- }
- }
-
- to_hex(value, value_str);
-
- result_val = tfm_hal_output_spm_log(value_str,
- MAX_DIGIT_BITS);
- if (result_val < TFM_HAL_SUCCESS) {
- return result_val;
- }
- return (result_msg + result_val);
-}
diff --git a/secure_fw/spm/core/stack_watermark.c b/secure_fw/spm/core/stack_watermark.c
index 738bf37..ae67a7f 100644
--- a/secure_fw/spm/core/stack_watermark.c
+++ b/secure_fw/spm/core/stack_watermark.c
@@ -13,7 +13,7 @@
#include "lists.h"
#include "load/spm_load_api.h"
#include "spm.h"
-#include "tfm_spm_log.h"
+#include "tfm_log.h"
/* Always output, regardless of log level.
* If you don't want output, don't build this code
diff --git a/secure_fw/spm/core/tfm_svcalls.c b/secure_fw/spm/core/tfm_svcalls.c
index 3de098d..4f179ab 100644
--- a/secure_fw/spm/core/tfm_svcalls.c
+++ b/secure_fw/spm/core/tfm_svcalls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2024, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -156,14 +156,14 @@
}
if (svc_idx >= (sizeof(psa_api_svc_func_table)/sizeof(psa_api_svc_func_t))) {
- SPMLOG_ERRMSGVAL("Invalid PSA API SVC requested: ", svc_number);
+ ERROR_RAW("Invalid PSA API SVC requested: 0x%08x\n", svc_number);
ctx[0] = (uint32_t)PSA_ERROR_GENERIC_ERROR;
return exc_return;
}
svc_func = psa_api_svc_func_table[svc_idx];
if (!svc_func) {
- SPMLOG_ERRMSGVAL("Corresponding SVC function is not included for number ", svc_number);
+ ERROR_RAW("Corresponding SVC function is not included for number 0x%08x\n", svc_number);
ctx[0] = (uint32_t)PSA_ERROR_GENERIC_ERROR;
return exc_return;
}
@@ -240,7 +240,7 @@
break;
#endif
default:
- SPMLOG_ERRMSGVAL("Unknown SPM SVC requested: ", svc_number);
+ ERROR_RAW("Unknown SPM SVC requested: 0x%08x\n", svc_number);
svc_args[0] = (uint32_t)PSA_ERROR_GENERIC_ERROR;
}
@@ -305,7 +305,7 @@
}
#endif
- SPMLOG_ERRMSGVAL("Unknown SVC number requested: ", svc_number);
+ ERROR_RAW("Unknown SVC number requested: 0x%08x\n", svc_number);
svc_args[0] = (uint32_t)PSA_ERROR_GENERIC_ERROR;
return exc_return;
diff --git a/secure_fw/spm/include/private/assert.h b/secure_fw/spm/include/private/assert.h
index 5f5174c..2a82da6 100644
--- a/secure_fw/spm/include/private/assert.h
+++ b/secure_fw/spm/include/private/assert.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2024, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,19 +8,17 @@
#define __TFM_PRIV_ASSERT_H__
#include <string.h>
-#include "tfm_spm_log.h"
+#include "tfm_log.h"
#ifndef NDEBUG
-#define SPM_ASSERT(cond) \
- do { \
- if (!(cond)) { \
- SPMLOG_INFMSG("Assert:"); \
- SPMLOG_INFMSG(__func__); \
- SPMLOG_INFMSGVAL(",", __LINE__); \
- while (1) { \
- ; \
- } \
- } \
+#define SPM_ASSERT(cond) \
+ do { \
+ if (!(cond)) { \
+ INFO_RAW("Assert: %s, %d\n", __func__, __LINE__); \
+ while (1) { \
+ ; \
+ } \
+ } \
} while (0)
#else
#define SPM_ASSERT(cond)
diff --git a/secure_fw/spm/include/tfm_spm_log.h b/secure_fw/spm/include/tfm_spm_log.h
deleted file mode 100644
index 2062cbc..0000000
--- a/secure_fw/spm/include/tfm_spm_log.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __TFM_SPM_LOG_H__
-#define __TFM_SPM_LOG_H__
-
-#include <stddef.h>
-#include <stdint.h>
-#include "tfm_hal_defs.h"
-#include "tfm_hal_spm_logdev.h"
-
-/* The SPM log levels */
-#define TFM_SPM_LOG_LEVEL_DEBUG 3 /* All log APIs output */
-#define TFM_SPM_LOG_LEVEL_INFO 2 /*
- * All log APIs output except SPMLOG_DBG
- * and SPMLOG_DBGMSGVAL
- */
-#define TFM_SPM_LOG_LEVEL_ERROR 1 /*
- * Only SPMLOG_ERRMSG and SPMLOG_ERRMSGVAL
- * APIs output.
- */
-#define TFM_SPM_LOG_LEVEL_SILENCE 0 /* All log APIs are suppressed */
-
-#ifndef TFM_SPM_LOG_LEVEL
-#error "TFM_SPM_LOG_LEVEL not defined!"
-#endif
-
-#if ((TFM_SPM_LOG_LEVEL > TFM_SPM_LOG_LEVEL_DEBUG) || \
- (TFM_SPM_LOG_LEVEL < TFM_SPM_LOG_LEVEL_SILENCE))
-#error "Incorrect TFM_SPM_LOG_LEVEL value!"
-#endif
-
-#if (TFM_SPM_LOG_LEVEL == TFM_SPM_LOG_LEVEL_DEBUG)
-#define SPMLOG_DBGMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
-#define SPMLOG_DBGMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
-#else
-#define SPMLOG_DBGMSGVAL(msg, val) (void)(val)
-#define SPMLOG_DBGMSG(msg)
-#endif
-
-#if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_INFO)
-#define SPMLOG_INFMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
-#define SPMLOG_INFMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
-#else
-#define SPMLOG_INFMSGVAL(msg, val) (void)(val)
-#define SPMLOG_INFMSG(msg)
-#endif
-
-#if (TFM_SPM_LOG_LEVEL >= TFM_SPM_LOG_LEVEL_ERROR)
-#define SPMLOG_ERRMSGVAL(msg, val) spm_log_msgval(msg, sizeof(msg), val)
-#define SPMLOG_ERRMSG(msg) tfm_hal_output_spm_log(msg, sizeof(msg))
-#else
-#define SPMLOG_ERRMSGVAL(msg, val) (void)(val)
-#define SPMLOG_ERRMSG(msg)
-#endif
-
-/**
- * \brief SPM output API to convert digit number into HEX string and call the
- * HAL API tfm_hal_output_spm_log.
- *
- * \param[in] msg A string message
- * \param[in] len The length of the message
- * \param[in] value A value need to be output
- *
- * \retval >=0 Number of chars output.
- * \retval <0 TFM HAL error code.
- */
-int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value);
-
-#endif /* __TFM_SPM_LOG_H__ */
diff --git a/secure_fw/spm/include/utilities.h b/secure_fw/spm/include/utilities.h
index 4f76081..36f9588 100644
--- a/secure_fw/spm/include/utilities.h
+++ b/secure_fw/spm/include/utilities.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,7 +8,7 @@
#define __TFM_UTILS_H__
#include <string.h>
-#include "tfm_spm_log.h"
+#include "tfm_log.h"
/*
* CPU spin here.
@@ -20,8 +20,7 @@
#define TO_CONTAINER(ptr, type, member) \
((type *)((unsigned long)(ptr) - offsetof(type, member)))
-/* FixMe: Replace ERROR_MSG() in platform code with a suitable API */
-#define ERROR_MSG(msg) SPMLOG_ERRMSG(msg "\r\n")
+#define ERROR_MSG(msg) ERROR_RAW(msg "\n")
/* Stringify preprocessors, no leading underscore. ('STRINGIFY') */
#define STRINGIFY_EXPAND(x) #x