summaryrefslogtreecommitdiff
path: root/meta-arm/meta-arm-bsp/recipes-bsp/trusted-firmware-m/files/corstone1000/0006-Platform-corstone1000-Add-common-platform-logger.patch
blob: a7c17abff7cd26f3ca78b24be4f64afc71017a6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From 9545d9bb44f8fb5af438fb40cab7fefc95d5a9a4 Mon Sep 17 00:00:00 2001
From: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
Date: Thu, 22 Dec 2022 09:24:50 +0000
Subject: [PATCH 6/10] Platform:corstone1000: Add common platform logger

platform_log defines log messages macros to be used by the platform code
It allows defining the module name to be added at the beginning of the log
message.
Based on build type PLAT_LOG_LEVEL is defined.
In case of Debug/RelWithDebInfo PLAT_LOG_LEVEL is defined to Debug level
else it is defined to OFF.

usage in source file:
...
INFO("msg");
ERROR("msg");
WARN("msg");
VERBOSE("msg");
DBG("msg");
...

Signed-off-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com>
Upstream-Status: Pending [Not submitted to upstream yet]
---
 .../target/arm/corstone1000/CMakeLists.txt    |  1 +
 .../ext/target/arm/corstone1000/config.cmake  |  4 +-
 .../target/arm/corstone1000/platform_log.h    | 60 +++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 platform/ext/target/arm/corstone1000/platform_log.h

diff --git a/platform/ext/target/arm/corstone1000/CMakeLists.txt b/platform/ext/target/arm/corstone1000/CMakeLists.txt
index 9db2864033..a120f39ea4 100644
--- a/platform/ext/target/arm/corstone1000/CMakeLists.txt
+++ b/platform/ext/target/arm/corstone1000/CMakeLists.txt
@@ -152,6 +152,7 @@ target_compile_definitions(platform_bl2
         $<$<BOOL:${PLATFORM_IS_FVP}>:PLATFORM_IS_FVP>
         $<$<BOOL:${TFM_S_REG_TEST}>:TFM_S_REG_TEST>
         $<$<BOOL:${ENABLE_FWU_AGENT_DEBUG_LOGS}>:ENABLE_FWU_AGENT_DEBUG_LOGS>
+        PLAT_LOG_LEVEL=${PLAT_LOG_LEVEL}
 )
 
 # boot_hal_bl2.c is compiled as part of 'bl2' target and not inside
diff --git a/platform/ext/target/arm/corstone1000/config.cmake b/platform/ext/target/arm/corstone1000/config.cmake
index b71ca672f3..de0b4b64c1 100644
--- a/platform/ext/target/arm/corstone1000/config.cmake
+++ b/platform/ext/target/arm/corstone1000/config.cmake
@@ -63,6 +63,8 @@ set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON       CACHE BOOL      "Enable Inte
 
 if (${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
   set(ENABLE_FWU_AGENT_DEBUG_LOGS     TRUE        CACHE BOOL      "Enable Firmware update agent debug logs.")
-else()
+  set(PLAT_LOG_LEVEL                    4        CACHE STRING     "Set platform log level.")
+  else()
   set(ENABLE_FWU_AGENT_DEBUG_LOGS     FALSE        CACHE BOOL     "Enable Firmware update agent debug logs.")
+  set(PLAT_LOG_LEVEL                    0        CACHE STRING     "Set platform log level.")
 endif()
diff --git a/platform/ext/target/arm/corstone1000/platform_log.h b/platform/ext/target/arm/corstone1000/platform_log.h
new file mode 100644
index 0000000000..b3a6e98026
--- /dev/null
+++ b/platform/ext/target/arm/corstone1000/platform_log.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __PLATFORM_LOG_H__
+#define __PLATFORM_LOG_H__
+
+#define PLAT_LOG_LEVEL_OFF       (0)
+#define PLAT_LOG_LEVEL_ERROR     (1)
+#define PLAT_LOG_LEVEL_WARN      (2)
+#define PLAT_LOG_LEVEL_INFO      (3)
+#define PLAT_LOG_LEVEL_DEBUG     (4)
+
+#ifndef PLAT_LOG_MODULE_NAME
+#define MODULE_NAME_STR " "
+#else
+#define MODULE_NAME_STR "["PLAT_LOG_MODULE_NAME"]: "
+#endif
+
+#ifndef PLAT_LOG_LEVEL
+#warning "Logging level is not defined, default is PLAT_LOG_LEVEL_ERROR."
+#define PLAT_LOG_LEVEL   PLAT_LOG_LEVEL_ERROR
+#endif
+
+
+/* System can override PRINTF with other rich format function*/
+#ifndef PRINTF
+#if PLAT_LOG_LEVEL > PLAT_LOG_LEVEL_OFF
+#include <stdio.h>
+#define PRINTF printf
+#endif
+#endif
+
+#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_ERROR
+    #define ERROR(f_, ...) do { PRINTF("\033[31;4m[ERR]:\033[m%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__);  } while (0)
+#else
+    #define ERROR(f_, ...) do {  } while(0)
+#endif
+#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_WARN
+    #define WARN(f_, ...) do { PRINTF("\033[33;4m[WRN]:\033[m%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__);  } while (0)
+#else
+    #define WARN(f_, ...) do {  } while(0)
+#endif
+#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_INFO
+    #define INFO(f_, ...) do { PRINTF("[INF]:%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__);  } while (0)
+#else
+    #define INFO(f_, ...) do {  } while(0)
+#endif
+#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_DEBUG
+    #define VERBOSE(f_, ...) do { PRINTF("[DBG]:%s" f_"\r\n",MODULE_NAME_STR, ##__VA_ARGS__);  } while (0)
+    #define DEBUG(f_, ...) do { PRINTF("[DBG]:%s" f_"\r\n",MODULE_NAME_STR, ##__VA_ARGS__);  } while (0)
+#else
+    #define VERBOSE(f_, ...) do {  } while(0)
+    #define DEBUG(f_, ...) do {  } while(0)
+#endif
+
+#endif /* __PLATFORM_LOG_H__ */
-- 
2.25.1