Andrew Geissler | 2daf84b | 2023-03-31 09:57:23 -0500 | [diff] [blame] | 1 | From 9545d9bb44f8fb5af438fb40cab7fefc95d5a9a4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mohamed Omar Asaker <mohamed.omarasaker@arm.com> |
| 3 | Date: Thu, 22 Dec 2022 09:24:50 +0000 |
| 4 | Subject: [PATCH 6/10] Platform:corstone1000: Add common platform logger |
| 5 | |
| 6 | platform_log defines log messages macros to be used by the platform code |
| 7 | It allows defining the module name to be added at the beginning of the log |
| 8 | message. |
| 9 | Based on build type PLAT_LOG_LEVEL is defined. |
| 10 | In case of Debug/RelWithDebInfo PLAT_LOG_LEVEL is defined to Debug level |
| 11 | else it is defined to OFF. |
| 12 | |
| 13 | usage in source file: |
| 14 | ... |
| 15 | INFO("msg"); |
| 16 | ERROR("msg"); |
| 17 | WARN("msg"); |
| 18 | VERBOSE("msg"); |
| 19 | DBG("msg"); |
| 20 | ... |
| 21 | |
| 22 | Signed-off-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com> |
| 23 | Upstream-Status: Pending [Not submitted to upstream yet] |
| 24 | --- |
| 25 | .../target/arm/corstone1000/CMakeLists.txt | 1 + |
| 26 | .../ext/target/arm/corstone1000/config.cmake | 4 +- |
| 27 | .../target/arm/corstone1000/platform_log.h | 60 +++++++++++++++++++ |
| 28 | 3 files changed, 64 insertions(+), 1 deletion(-) |
| 29 | create mode 100644 platform/ext/target/arm/corstone1000/platform_log.h |
| 30 | |
| 31 | diff --git a/platform/ext/target/arm/corstone1000/CMakeLists.txt b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 32 | index 9db2864033..a120f39ea4 100644 |
| 33 | --- a/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 34 | +++ b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| 35 | @@ -152,6 +152,7 @@ target_compile_definitions(platform_bl2 |
| 36 | $<$<BOOL:${PLATFORM_IS_FVP}>:PLATFORM_IS_FVP> |
| 37 | $<$<BOOL:${TFM_S_REG_TEST}>:TFM_S_REG_TEST> |
| 38 | $<$<BOOL:${ENABLE_FWU_AGENT_DEBUG_LOGS}>:ENABLE_FWU_AGENT_DEBUG_LOGS> |
| 39 | + PLAT_LOG_LEVEL=${PLAT_LOG_LEVEL} |
| 40 | ) |
| 41 | |
| 42 | # boot_hal_bl2.c is compiled as part of 'bl2' target and not inside |
| 43 | diff --git a/platform/ext/target/arm/corstone1000/config.cmake b/platform/ext/target/arm/corstone1000/config.cmake |
| 44 | index b71ca672f3..de0b4b64c1 100644 |
| 45 | --- a/platform/ext/target/arm/corstone1000/config.cmake |
| 46 | +++ b/platform/ext/target/arm/corstone1000/config.cmake |
| 47 | @@ -63,6 +63,8 @@ set(TFM_PARTITION_INTERNAL_TRUSTED_STORAGE ON CACHE BOOL "Enable Inte |
| 48 | |
| 49 | if (${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) |
| 50 | set(ENABLE_FWU_AGENT_DEBUG_LOGS TRUE CACHE BOOL "Enable Firmware update agent debug logs.") |
| 51 | -else() |
| 52 | + set(PLAT_LOG_LEVEL 4 CACHE STRING "Set platform log level.") |
| 53 | + else() |
| 54 | set(ENABLE_FWU_AGENT_DEBUG_LOGS FALSE CACHE BOOL "Enable Firmware update agent debug logs.") |
| 55 | + set(PLAT_LOG_LEVEL 0 CACHE STRING "Set platform log level.") |
| 56 | endif() |
| 57 | diff --git a/platform/ext/target/arm/corstone1000/platform_log.h b/platform/ext/target/arm/corstone1000/platform_log.h |
| 58 | new file mode 100644 |
| 59 | index 0000000000..b3a6e98026 |
| 60 | --- /dev/null |
| 61 | +++ b/platform/ext/target/arm/corstone1000/platform_log.h |
| 62 | @@ -0,0 +1,60 @@ |
| 63 | +/* |
| 64 | + * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 65 | + * |
| 66 | + * SPDX-License-Identifier: BSD-3-Clause |
| 67 | + * |
| 68 | + */ |
| 69 | + |
| 70 | +#ifndef __PLATFORM_LOG_H__ |
| 71 | +#define __PLATFORM_LOG_H__ |
| 72 | + |
| 73 | +#define PLAT_LOG_LEVEL_OFF (0) |
| 74 | +#define PLAT_LOG_LEVEL_ERROR (1) |
| 75 | +#define PLAT_LOG_LEVEL_WARN (2) |
| 76 | +#define PLAT_LOG_LEVEL_INFO (3) |
| 77 | +#define PLAT_LOG_LEVEL_DEBUG (4) |
| 78 | + |
| 79 | +#ifndef PLAT_LOG_MODULE_NAME |
| 80 | +#define MODULE_NAME_STR " " |
| 81 | +#else |
| 82 | +#define MODULE_NAME_STR "["PLAT_LOG_MODULE_NAME"]: " |
| 83 | +#endif |
| 84 | + |
| 85 | +#ifndef PLAT_LOG_LEVEL |
| 86 | +#warning "Logging level is not defined, default is PLAT_LOG_LEVEL_ERROR." |
| 87 | +#define PLAT_LOG_LEVEL PLAT_LOG_LEVEL_ERROR |
| 88 | +#endif |
| 89 | + |
| 90 | + |
| 91 | +/* System can override PRINTF with other rich format function*/ |
| 92 | +#ifndef PRINTF |
| 93 | +#if PLAT_LOG_LEVEL > PLAT_LOG_LEVEL_OFF |
| 94 | +#include <stdio.h> |
| 95 | +#define PRINTF printf |
| 96 | +#endif |
| 97 | +#endif |
| 98 | + |
| 99 | +#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_ERROR |
| 100 | + #define ERROR(f_, ...) do { PRINTF("\033[31;4m[ERR]:\033[m%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__); } while (0) |
| 101 | +#else |
| 102 | + #define ERROR(f_, ...) do { } while(0) |
| 103 | +#endif |
| 104 | +#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_WARN |
| 105 | + #define WARN(f_, ...) do { PRINTF("\033[33;4m[WRN]:\033[m%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__); } while (0) |
| 106 | +#else |
| 107 | + #define WARN(f_, ...) do { } while(0) |
| 108 | +#endif |
| 109 | +#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_INFO |
| 110 | + #define INFO(f_, ...) do { PRINTF("[INF]:%s"f_"\r\n", MODULE_NAME_STR, ##__VA_ARGS__); } while (0) |
| 111 | +#else |
| 112 | + #define INFO(f_, ...) do { } while(0) |
| 113 | +#endif |
| 114 | +#if PLAT_LOG_LEVEL >= PLAT_LOG_LEVEL_DEBUG |
| 115 | + #define VERBOSE(f_, ...) do { PRINTF("[DBG]:%s" f_"\r\n",MODULE_NAME_STR, ##__VA_ARGS__); } while (0) |
| 116 | + #define DEBUG(f_, ...) do { PRINTF("[DBG]:%s" f_"\r\n",MODULE_NAME_STR, ##__VA_ARGS__); } while (0) |
| 117 | +#else |
| 118 | + #define VERBOSE(f_, ...) do { } while(0) |
| 119 | + #define DEBUG(f_, ...) do { } while(0) |
| 120 | +#endif |
| 121 | + |
| 122 | +#endif /* __PLATFORM_LOG_H__ */ |
| 123 | -- |
| 124 | 2.25.1 |
| 125 | |