2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
11 #include <common/debug.h>
12 #include <plat/common/platform.h>
14 /* Set the default maximum log level to the `LOG_LEVEL` build flag */
15 static unsigned int max_log_level
= LOG_LEVEL
;
18 * The common log function which is invoked by ARM Trusted Firmware code.
19 * This function should not be directly invoked and is meant to be
20 * only used by the log macros defined in debug.h. The function
21 * expects the first character in the format string to be one of the
22 * LOG_MARKER_* macros defined in debug.h.
24 void tf_log(const char *fmt
, ...)
26 unsigned int log_level
;
28 const char *prefix_str
;
30 /* We expect the LOG_MARKER_* macro as the first character */
33 /* Verify that log_level is one of LOG_MARKER_* macro defined in debug.h */
34 assert((log_level
> 0U) && (log_level
<= LOG_LEVEL_VERBOSE
));
35 assert((log_level
% 10U) == 0U);
37 if (log_level
> max_log_level
)
40 prefix_str
= plat_log_get_prefix(log_level
);
42 while (*prefix_str
!= '\0') {
43 (void)putchar(*prefix_str
);
48 (void)vprintf(fmt
+ 1, args
);
53 * The helper function to set the log level dynamically by platform. The
54 * maximum log level is determined by `LOG_LEVEL` build flag at compile time
55 * and this helper can set a lower (or equal) log level than the one at compile.
57 void tf_log_set_max_level(unsigned int log_level
)
59 assert(log_level
<= LOG_LEVEL_VERBOSE
);
60 assert((log_level
% 10U) == 0U);
62 /* Cap log_level to the compile time maximum. */
63 if (log_level
<= (unsigned int)LOG_LEVEL
)
64 max_log_level
= log_level
;