Fix tracing in libts
Libts deployments did not include posix_trace.c in the build and as
a result setting TRACE_LEVEL to any value above TRACE_LEVEL_NONE
resulted in a build error.
- Add the missing C file to the build to fix this error.
- Make the arm-linux version of libts to implement tracing
the same way as linux-pc.
Change-Id: I1db6117a0e8aa4955de063e7b22618d4a254973f
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
diff --git a/components/common/trace/include/trace.h b/components/common/trace/include/trace.h
index d9b6c07..4395e41 100644
--- a/components/common/trace/include/trace.h
+++ b/components/common/trace/include/trace.h
@@ -8,6 +8,12 @@
#include "compiler.h"
+#ifdef EXPORT_PUBLIC_INTERFACE_TRACE
+#define TRACE_EXPORTED __attribute__((__visibility__("default")))
+#else
+#define TRACE_EXPORTED
+#endif
+
#define TRACE_LEVEL_NONE (0)
#define TRACE_LEVEL_ERROR (1)
#define TRACE_LEVEL_INFO (2)
@@ -30,6 +36,7 @@
extern void (*trace_puts_interface)(const char *str);
void trace_puts(const char *str);
+TRACE_EXPORTED
void trace_printf(const char *func, int line, int level, const char *fmt, ...) __printf(4, 5);
#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
index 66fa31c..5285ead 100644
--- a/deployments/deployment.cmake
+++ b/deployments/deployment.cmake
@@ -62,6 +62,10 @@
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type.")
endif()
+if (COVERAGE)
+ set(CMAKE_BUILD_TYPE "DebugCoverage" CACHE STRING "Build type" FORCE)
+endif()
+
# List of supported build types. Needs to be in alignment with the toolchain file
set(TS_SUPPORTED_BUILD_TYPES "DEBUG" "MINSIZEREL" "MINSIZWITHDEBINFO" "RELEASE" "RELWITHDEBINFO" "DEBUGCOVERAGE" CACHE
STRING "List of supported build types.")
@@ -76,11 +80,8 @@
endif()
# Set postfix of libraries according the build type.
-if (UC_CMAKE_BUILD_TYPE STREQUAL "DEBUGCOVERAGE")
- set(CMAKE_${UC_CMAKE_BUILD_TYPE}_POSTFIX "c")
-elseif(UC_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
- set(CMAKE_${UC_CMAKE_BUILD_TYPE}_POSTFIX "d")
-endif()
+set(CMAKE_DEBUGCOVERAGE_POSTFIX "c")
+set(CMAKE_DEBUG_POSTFIX "d")
# Default protocol UUID used by TS SPs.
set(TS_RPC_UUID_CANON "bdcd76d7-825e-4751-963b-86d4f84943ac" CACHE STRING "Trusted Services PRC (protocol) UUID.")
diff --git a/deployments/libts/arm-linux/CMakeLists.txt b/deployments/libts/arm-linux/CMakeLists.txt
index 1c190a8..5416656 100644
--- a/deployments/libts/arm-linux/CMakeLists.txt
+++ b/deployments/libts/arm-linux/CMakeLists.txt
@@ -24,6 +24,13 @@
set(MM_COMM_BUFFER_SIZE "8*4*1024" CACHE STRING "Size of the MM communicate buffer in bytes")
#-------------------------------------------------------------------------------
+# For user-specific tracing set to TRACE_LEVEL_NONE and implement:
+# void trace_puts(const char *str)
+#-------------------------------------------------------------------------------
+
+set(TRACE_PREFIX "LIBTS" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+#-------------------------------------------------------------------------------
# Components that are specific to deployment in the arm-linux environment.
#
#-------------------------------------------------------------------------------
diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake
index eb3afc5..d0b728d 100644
--- a/deployments/libts/libts-import.cmake
+++ b/deployments/libts/libts-import.cmake
@@ -16,6 +16,10 @@
version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt" MAJOR _major MINOR _minor PATCH _patch)
set(_verstring "${_major}.${_minor}.${_patch}")
+if (COVERAGE)
+ set(LIBTS_BUILD_TYPE "DebugCoverage" CACHE STRING "Build type." FORCE)
+endif()
+
find_package(libts "${_verstring}" QUIET PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts)
if(NOT libts_FOUND)
if (CFG_FORCE_PREBUILT_LIBTS)
diff --git a/deployments/libts/libts.cmake b/deployments/libts/libts.cmake
index 0f1a022..20c3c0e 100644
--- a/deployments/libts/libts.cmake
+++ b/deployments/libts/libts.cmake
@@ -24,6 +24,10 @@
add_library(libts::ts ALIAS ts)
+if (COVERAGE)
+ set(LIBTS_BUILD_TYPE "DebugCoverage" CACHE STRING "Build type." FORCE)
+endif()
+
#-------------------------------------------------------------------------------
# Components that are common across all deployments
#
@@ -32,6 +36,8 @@
TARGET "ts"
BASE_DIR ${TS_ROOT}
COMPONENTS
+ "environments/${TS_ENV}"
+ "components/common/trace"
"components/rpc/common/caller"
"components/rpc/common/interface"
"components/service/locator"
@@ -45,6 +51,7 @@
# Enable exporting interface symbols for library public interface
target_compile_definitions(ts PRIVATE
+ EXPORT_PUBLIC_INTERFACE_TRACE
EXPORT_PUBLIC_INTERFACE_RPC_CALLER
EXPORT_PUBLIC_INTERFACE_RPC_SERVICE
EXPORT_PUBLIC_INTERFACE_SERVICE_LOCATOR
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index 300f77d..80ef7e4 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -22,6 +22,13 @@
target_include_directories(ts PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
#-------------------------------------------------------------------------------
+# For user-specific tracing set to TRACE_LEVEL_NONE and implement:
+# void trace_puts(const char *str)
+#-------------------------------------------------------------------------------
+
+set(TRACE_PREFIX "LIBTS" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+#-------------------------------------------------------------------------------
# External project source-level dependencies
#
#-------------------------------------------------------------------------------
@@ -63,7 +70,6 @@
"components/common/uuid"
"components/common/endian"
"components/common/utils"
- "components/common/trace"
"components/common/crc32"
"components/common/mbedtls"
"components/config/ramstore"
@@ -161,14 +167,6 @@
)
#-------------------------------------------------------------------------------
-# Configure added components
-#
-#-------------------------------------------------------------------------------
-# Force trace level to TRACE_LEVEL_NONE to disable trace messages. This is
-# needed till proper trace enablement for the linux-pc environment is done.
-target_compile_definitions(ts PUBLIC TRACE_LEVEL=0)
-
-#-------------------------------------------------------------------------------
# Extend with components that are common across all deployments of
# libts
#
diff --git a/environments/arm-linux/component.cmake b/environments/arm-linux/component.cmake
new file mode 100644
index 0000000..97229bd
--- /dev/null
+++ b/environments/arm-linux/component.cmake
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+if (NOT DEFINED TRACE_PREFIX)
+ message(FATAL_ERROR "mandatory parameter TRACE_PREFIX is not defined.")
+endif()
+
+# Default to trace output disabled
+set(TRACE_LEVEL "TRACE_LEVEL_NONE" CACHE STRING "Trace level")
+
+target_compile_definitions(${TGT} PRIVATE
+ TRACE_LEVEL=${TRACE_LEVEL}
+ TRACE_PREFIX="${TRACE_PREFIX}"
+)
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/posix_trace.c"
+ )
diff --git a/environments/arm-linux/posix_trace.c b/environments/arm-linux/posix_trace.c
new file mode 100644
index 0000000..f219b6d
--- /dev/null
+++ b/environments/arm-linux/posix_trace.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+ */
+
+#include <stdio.h>
+
+#include "trace.h"
+
+#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
+
+void trace_puts(const char *str)
+{
+ puts(str);
+}
+
+#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */