Revert last 5 patches related to logging as they are still unstable
Revert "Log: Restore an interface target for logging header"
This reverts commit 2e796c5a813054de97f20492382a428894fdbacc.
Revert "Log: Add __assert_func and __assert_puts"
This reverts commit 6bceab814be8a968e74735dd45fe440bf6ea79b4.
Revert "LIB: Move TEST_LOG to use tfm_log"
This reverts commit 9798351a12f881a1cca66b60f4ad72167916847d.
Revert "LIB: Move NS test apps to use printf"
This reverts commit ebf5261a57d2a1ed91fc334a53fada7b59255ae4.
Revert "LIB: Move tfm_log.h to tfm_tests_log_msg.h"
This reverts commit 290b88f90c0d2a5dc275a1748690047f374ef6f1.
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: Icd0dabddb5c191728e18c81611648ce2eb81680c
diff --git a/app_broker/CMakeLists.txt b/app_broker/CMakeLists.txt
index 3228ea8..caad0cf 100644
--- a/app_broker/CMakeLists.txt
+++ b/app_broker/CMakeLists.txt
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -40,20 +40,6 @@
# lib path
set(APP_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/../lib)
-# TFM NS logging interface
-add_library(tfm_ns_log_msg_interface INTERFACE)
-
-target_include_directories(tfm_ns_log_msg_interface
- INTERFACE
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../lib/log>
- $<INSTALL_INTERFACE:${SPE_INSTALL_INTERFACE_INC}
-)
-
-target_compile_definitions(tfm_ns_log_msg_interface
- INTERFACE
- $<$<NOT:$<BOOL:${TFM_NS_LOG_DISABLE}>>:TFM_NS_LOG>
-)
-
# OS wrapper library consists of the wrapper layer of RTOSes, such as RTX
add_library(os_wrapper STATIC)
@@ -138,6 +124,29 @@
)
endif()
+# TF-M NS logging
+add_library(tfm_ns_log STATIC EXCLUDE_FROM_ALL)
+
+target_sources(tfm_ns_log
+ PRIVATE
+ ${APP_LIB_DIR}/log/tfm_log_raw.c
+)
+
+target_include_directories(tfm_ns_log
+ PUBLIC
+ ${APP_LIB_DIR}/log/
+)
+
+target_compile_definitions(tfm_ns_log
+ INTERFACE
+ $<$<NOT:$<BOOL:${TFM_NS_LOG_DISABLE}>>:TFM_NS_LOG>
+)
+
+target_link_libraries(tfm_ns_log
+ PRIVATE
+ platform_ns
+)
+
################## Update plaform_ns with NS settings #################
target_include_directories(platform_ns
@@ -165,8 +174,6 @@
)
target_link_libraries(tfm_api_ns
- INTERFACE
- tfm_ns_log_msg_interface
PRIVATE
$<$<BOOL:${TFM_NS_MAILBOX_API}>:tfm_api_ns_mailbox>
$<$<NOT:$<BOOL:${TFM_NS_MAILBOX_API}>>:tfm_api_ns_tz>
@@ -179,14 +186,12 @@
target_sources(tfm_test_broker
PRIVATE
- assert.c
main_ns.c
)
target_include_directories(tfm_test_broker
PUBLIC
.
- ${APP_LIB_DIR}/log/
)
target_link_libraries(tfm_test_broker
@@ -196,6 +201,7 @@
PUBLIC
RTX_OS
tfm_api_ns
+ tfm_ns_log
$<$<BOOL:${TFM_NS_MAILBOX_API}>:ns_multi_core>
)
diff --git a/app_broker/assert.c b/app_broker/assert.c
deleted file mode 100644
index 648fd6f..0000000
--- a/app_broker/assert.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include <stddef.h>
-#include <assert.h>
-#include "tfm_tests_log_msg.h"
-
-#ifndef __ARMCC_VERSION
-void __assert_func(const char *file, int line, const char *func, const char *reason)
-{
- LOG_MSG("Assertion failed: (%s), file %s, line %d\r\n", reason, file, line);
-
- while (1) {
- ;
- }
-}
-#else /* __ARMCC_VERSION */
-void __assert_puts(const char *msg)
-{
- LOG_MSG("%s\r\n", msg);
-
- while (1) {
- ;
- }
-}
-#endif /* __ARMCC_VERSION*/
diff --git a/app_broker/main_ns.c b/app_broker/main_ns.c
index fc9c3b8..a387803 100644
--- a/app_broker/main_ns.c
+++ b/app_broker/main_ns.c
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
* Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
*
@@ -19,7 +19,7 @@
#include "tfm_multi_core_api.h"
#include "tfm_ns_mailbox.h"
#endif
-#include "tfm_tests_log_msg.h"
+#include "tfm_log.h"
#include "uart_stdout.h"
#if (CONFIG_TFM_FLOAT_ABI >= 1)
#include "cmsis.h"
diff --git a/erpc/server/app/erpc_app.c b/erpc/server/app/erpc_app.c
index 264b873..341a0f0 100644
--- a/erpc/server/app/erpc_app.c
+++ b/erpc/server/app/erpc_app.c
@@ -1,11 +1,11 @@
/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ * Copyright (c) 2017-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include "tfm_tests_log_msg.h"
+#include "tfm_log.h"
#include "erpc_server_start.h"
#include "config_erpc_target.h"
diff --git a/erpc/tfm_reg_tests/CMakeLists.txt b/erpc/tfm_reg_tests/CMakeLists.txt
index 888c248..bb7688d 100644
--- a/erpc/tfm_reg_tests/CMakeLists.txt
+++ b/erpc/tfm_reg_tests/CMakeLists.txt
@@ -151,6 +151,10 @@
# Config check in case additional test configs passed in via command line.
include(${TFM_REG_TEST_ROOT}/config/check_config.cmake)
+# Dummy tfm_ns_log for the tfm_test_framework_ns library
+add_library(tfm_ns_log INTERFACE)
+
+set(USE_STDIO ON)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../lib/ext/qcbor ${CMAKE_BINARY_DIR}/lib/ext/qcbor)
add_subdirectory(${TFM_REG_TEST_ROOT}/ns_regression ${CMAKE_BINARY_DIR}/ns_regression)
diff --git a/lib/log/tfm_tests_log_msg.h b/lib/log/tfm_log.h
similarity index 64%
rename from lib/log/tfm_tests_log_msg.h
rename to lib/log/tfm_log.h
index deee64f..5d5e649 100644
--- a/lib/log/tfm_tests_log_msg.h
+++ b/lib/log/tfm_log.h
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,12 +8,12 @@
#ifndef __TFM_LOG_H__
#define __TFM_LOG_H__
-#include <stdio.h>
+#include "tfm_log_raw.h"
/* Functions and macros in this file is for 'thread mode' usage. */
#ifdef TFM_NS_LOG
-#define LOG_MSG(...) printf(__VA_ARGS__)
+#define LOG_MSG(...) tfm_log_printf(__VA_ARGS__)
#else
#define LOG_MSG(...)
#endif
diff --git a/lib/log/tfm_log_raw.c b/lib/log/tfm_log_raw.c
new file mode 100644
index 0000000..61f75ca
--- /dev/null
+++ b/lib/log/tfm_log_raw.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "uart_stdout.h"
+
+#define PRINT_BUFF_SIZE 32
+#define NUM_BUFF_SIZE 12
+
+struct formatted_buffer_t {
+ size_t pos;
+ char buf[PRINT_BUFF_SIZE];
+};
+
+const char hex_digits_lo[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+const char hex_digits_up[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+static void _tfm_flush_formatted_buffer(struct formatted_buffer_t *pb,
+ uint8_t data)
+{
+ pb->buf[pb->pos++] = data;
+ if (pb->pos >= PRINT_BUFF_SIZE) {
+ pb->pos = 0;
+ /* uart flush and print here. */
+ stdio_output_string(pb->buf, PRINT_BUFF_SIZE);
+ }
+}
+
+static int _tfm_string_output(struct formatted_buffer_t *pb,
+ const char *str)
+{
+ int count = 0;
+
+ while (*str) {
+ _tfm_flush_formatted_buffer(pb, *str++);
+ count++;
+ }
+
+ return count;
+}
+
+static int _tfm_dec_num_output(struct formatted_buffer_t *pb,
+ int32_t num, uint8_t sign)
+{
+ int count = 0;
+ uint8_t num_buff[NUM_BUFF_SIZE] = {0};
+ uint32_t number = (uint32_t)num;
+ uint32_t k = 0;
+
+ if (sign == 'd' && num < 0) {
+ _tfm_flush_formatted_buffer(pb, '-');
+ count++;
+ number = -num;
+ }
+
+ do {
+ num_buff[k++] = '0' + number % 10;
+ number /= 10;
+ } while (number);
+
+ while (k) {
+ _tfm_flush_formatted_buffer(pb, num_buff[--k]);
+ count++;
+ }
+
+ return count;
+}
+
+static int _tfm_hex_num_output(struct formatted_buffer_t *pb, uint32_t num,
+ const char *hex_digits)
+{
+ int count = 0;
+ uint8_t num_buff[NUM_BUFF_SIZE] = {0};
+ uint32_t k = 0;
+
+ do {
+ num_buff[k++] = hex_digits[num & 0x0f];
+ num >>= 4;
+ } while (num);
+
+ while (k) {
+ _tfm_flush_formatted_buffer(pb, num_buff[--k]);
+ count++;
+ }
+
+ return count;
+}
+
+static int _tfm_log_vprintf(const char *fmt, va_list ap)
+{
+ int count = 0;
+ struct formatted_buffer_t outputbuf;
+
+ outputbuf.pos = 0;
+
+ while (*fmt) {
+ if (*fmt == '%') {
+ switch (*(++fmt)) {
+ case 'd':
+ case 'i':
+ count += _tfm_dec_num_output(&outputbuf,
+ va_arg(ap, int32_t), 'd');
+ break;
+ case 'u':
+ count += _tfm_dec_num_output(&outputbuf,
+ va_arg(ap, int32_t), 'u');
+ break;
+ case 'x':
+ count += _tfm_hex_num_output(&outputbuf, va_arg(ap, uint32_t),
+ hex_digits_lo);
+ break;
+ case 'X':
+ count += _tfm_hex_num_output(&outputbuf, va_arg(ap, uint32_t),
+ hex_digits_up);
+ break;
+ case 'p':
+ count += _tfm_string_output(&outputbuf, "0x");
+ count += _tfm_hex_num_output(&outputbuf, va_arg(ap, uint32_t),
+ hex_digits_lo);
+ break;
+ case 's':
+ count += _tfm_string_output(&outputbuf, va_arg(ap, char*));
+ break;
+ case 'c':
+ _tfm_flush_formatted_buffer(&outputbuf,
+ (uint8_t)va_arg(ap, int32_t));
+ count++;
+ break;
+ case '%':
+ _tfm_flush_formatted_buffer(&outputbuf, '%');
+ count++;
+ break;
+ default:
+ count += _tfm_string_output(&outputbuf, "[Unsupported Tag]");
+ continue;
+ }
+ fmt++;
+ } else {
+ _tfm_flush_formatted_buffer(&outputbuf, *fmt++);
+ count++;
+ }
+ }
+
+ /* End of printf, flush buf */
+ if (outputbuf.pos) {
+ count += stdio_output_string(outputbuf.buf, outputbuf.pos);
+ }
+
+ return count;
+}
+
+int tfm_log_printf(const char *fmt, ...)
+{
+ int count = 0;
+ va_list ap;
+
+ va_start(ap, fmt);
+ count = _tfm_log_vprintf(fmt, ap);
+ va_end(ap);
+
+ return count;
+}
diff --git a/lib/log/tfm_log_raw.h b/lib/log/tfm_log_raw.h
new file mode 100644
index 0000000..7a5a942
--- /dev/null
+++ b/lib/log/tfm_log_raw.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_LOG_RAW_H__
+#define __TFM_LOG_RAW_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Prints log messages
+ *
+ * \param[in] fmt Formatted string
+ * \param[in] ... Viriable length argument
+ *
+ * \return Number of chars printed
+ *
+ * \note This function has the similar input argument format as
+ * the 'printf' function. But it supports only some basic
+ * formats like 'sdicpuxX' and '%'. It will output
+ * "[Unsupported Tag]" when none of the above formats match
+ *
+ * \details The following output formats are supported.
+ * %s - string
+ * %d - decimal signed integer (same for %i)
+ * %u - decimal unsigned integer
+ * %x - hex in lowercase
+ * %X - hex in uppercase
+ * %p - hex address of a pointer in lowercase
+ * %c - character
+ * %% - the '%' symbol
+ */
+int tfm_log_printf(const char *fmt, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_LOG_RAW_H__ */
diff --git a/tests_psa_arch/test_app.c b/tests_psa_arch/test_app.c
index db40bdf..74f98ec 100644
--- a/tests_psa_arch/test_app.c
+++ b/tests_psa_arch/test_app.c
@@ -1,12 +1,12 @@
/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ * Copyright (c) 2017-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include "test_app.h"
-#include "tfm_tests_log_msg.h"
+#include "tfm_log.h"
#include "os_wrapper/thread.h"
/**
diff --git a/tests_reg/test/bl1/bl1_1/CMakeLists.txt b/tests_reg/test/bl1/bl1_1/CMakeLists.txt
index 1d08110..ce0a33d 100644
--- a/tests_reg/test/bl1/bl1_1/CMakeLists.txt
+++ b/tests_reg/test/bl1/bl1_1/CMakeLists.txt
@@ -11,11 +11,30 @@
add_library(bl1_1_tests STATIC)
-target_link_libraries(tfm_test_framework_common
+set(LOG_SOURCE_ROOT ${TFM_TESTS_ROOT_DIR}/lib/log)
+
+add_library(bl1_1_log INTERFACE)
+
+target_sources(bl1_1_log
+ INTERFACE
+ ${LOG_SOURCE_ROOT}/tfm_log_raw.c
+)
+
+target_include_directories(bl1_1_log
+ INTERFACE
+ ${LOG_SOURCE_ROOT}
+)
+
+target_link_libraries(bl1_1_log
INTERFACE
platform_bl1_1_interface
)
+target_link_libraries(tfm_test_framework_common
+ INTERFACE
+ bl1_1_log
+)
+
add_subdirectory(suites/crypto)
add_subdirectory(suites/random)
add_subdirectory(suites/integration)
diff --git a/tests_reg/test/bl2/mcuboot/CMakeLists.txt b/tests_reg/test/bl2/mcuboot/CMakeLists.txt
index 48f2deb..17c7ab6 100644
--- a/tests_reg/test/bl2/mcuboot/CMakeLists.txt
+++ b/tests_reg/test/bl2/mcuboot/CMakeLists.txt
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -10,11 +10,31 @@
# It links platform_ns which is not built by SPE build.
# So a dedicated library is duplicated here, and it links the platform_s instead of platform_ns.
+# TO-DO: find a better approach to reference the directory
+set(LOG_SOURCE_ROOT ${TFM_TESTS_ROOT_DIR}/lib/log)
+
+add_library(mcuboot_test_log INTERFACE)
add_library(mcuboot_test_framework_common INTERFACE)
+target_sources(mcuboot_test_log
+ INTERFACE
+ ${LOG_SOURCE_ROOT}/tfm_log_raw.c
+)
+
+target_include_directories(mcuboot_test_log
+ INTERFACE
+ ${LOG_SOURCE_ROOT}
+)
+
+target_link_libraries(mcuboot_test_log
+ INTERFACE
+ platform_bl2
+)
+
target_link_libraries(mcuboot_test_framework_common
INTERFACE
tfm_test_framework_common
+ mcuboot_test_log
)
add_subdirectory(suites/integration)
diff --git a/tests_reg/test/framework/test_log.h b/tests_reg/test/framework/test_log.h
index 303793b..4c14c60 100644
--- a/tests_reg/test/framework/test_log.h
+++ b/tests_reg/test/framework/test_log.h
@@ -13,17 +13,7 @@
#elif defined USE_STDIO
#include <stdio.h>
#else
-/*
- * Depending on how the tests are compiled, they may
- * pick up the LOG_LEVEL definition from other components. These other values
- * will have no effect on logging in the tests as we always call the tfm_log
- * function. In the case that we do not have a definition, just set
- * it to VERBOSE
- */
-#ifndef LOG_LEVEL
-#define LOG_LEVEL LOG_LEVEL_VERBOSE
-#endif
-#include "tfm_log.h"
+#include "tfm_log_raw.h"
#endif /* USE_SP_LOG */
#ifdef __cplusplus
@@ -35,7 +25,7 @@
#elif defined USE_STDIO
#define TEST_LOG(...) printf(__VA_ARGS__)
#else
-#define TEST_LOG(...) tfm_log(LOG_MARKER_RAW __VA_ARGS__)
+#define TEST_LOG(...) tfm_log_printf(__VA_ARGS__)
#endif /* USE_SP_LOG */
#ifdef __cplusplus
diff --git a/tests_reg/test/ns_regression/CMakeLists.txt b/tests_reg/test/ns_regression/CMakeLists.txt
index 4da9a37..543d746 100644
--- a/tests_reg/test/ns_regression/CMakeLists.txt
+++ b/tests_reg/test/ns_regression/CMakeLists.txt
@@ -41,13 +41,14 @@
INTERFACE
DOMAIN_NS=1
$<$<BOOL:${CONFIG_TFM_ERPC_TEST_FRAMEWORK}>:CONFIG_TFM_ERPC_TEST_FRAMEWORK=1>
- USE_STDIO
+ $<$<BOOL:${USE_STDIO}>:USE_STDIO>
)
target_link_libraries(tfm_test_framework_ns
INTERFACE
tfm_test_framework_common
tfm_api_ns
+ tfm_ns_log
)
target_sources(tfm_ns_tests
diff --git a/tests_reg/test_app.c b/tests_reg/test_app.c
index 7ab6017..2d2df21 100644
--- a/tests_reg/test_app.c
+++ b/tests_reg/test_app.c
@@ -1,12 +1,12 @@
/*
- * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ * Copyright (c) 2017-2023, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include "test_app.h"
-#include "tfm_tests_log_msg.h"
+#include "tfm_log.h"
#ifdef TFM_NS_REG_TEST
#include "non_secure_suites.h"
#endif