Add concept of console output log levels

Create new LOG_LEVEL build option, which controls the amount of
console output compiled into the build. This should be one of the
following:

    0  (LOG_LEVEL_NONE)
    10 (LOG_LEVEL_NOTICE)
    20 (LOG_LEVEL_ERROR)
    30 (LOG_LEVEL_WARNING)
    40 (LOG_LEVEL_INFO)
    50 (LOG_LEVEL_VERBOSE)

All log output up to and including the log level is compiled into the
build. The default value is 40 in debug builds and 20 in release
builds.

Complement the existing INFO, WARN and ERROR console output macros
with NOTICE and VERBOSE macros, which are conditionally compiled in
depending on the value of LOG_LEVEL.

Fixes ARM-software/tf-issues#232

Change-Id: I951e2f333e7b90fc4b1060741d9a6db699d5aa72
This commit is contained in:
Dan Handley 2014-08-08 14:36:42 +01:00
parent c1efc4c066
commit 289c28a8f5
3 changed files with 63 additions and 14 deletions

View File

@ -80,8 +80,12 @@ export Q
ifneq (${DEBUG}, 0) ifneq (${DEBUG}, 0)
BUILD_TYPE := debug BUILD_TYPE := debug
# Use LOG_LEVEL_INFO by default for debug builds
LOG_LEVEL := 40
else else
BUILD_TYPE := release BUILD_TYPE := release
# Use LOG_LEVEL_NOTICE by default for release builds
LOG_LEVEL := 20
endif endif
# Default build string (git branch and commit) # Default build string (git branch and commit)
@ -213,6 +217,9 @@ $(eval $(call add_define,ARM_GIC_ARCH))
$(eval $(call assert_boolean,ASM_ASSERTION)) $(eval $(call assert_boolean,ASM_ASSERTION))
$(eval $(call add_define,ASM_ASSERTION)) $(eval $(call add_define,ASM_ASSERTION))
# Process LOG_LEVEL flag
$(eval $(call add_define,LOG_LEVEL))
ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
-Werror -Wmissing-include-dirs \ -Werror -Wmissing-include-dirs \
-mgeneral-regs-only -D__ASSEMBLY__ \ -mgeneral-regs-only -D__ASSEMBLY__ \

View File

@ -146,6 +146,19 @@ performed.
* `DEBUG`: Chooses between a debug and release build. It can take either 0 * `DEBUG`: Chooses between a debug and release build. It can take either 0
(release) or 1 (debug) as values. 0 is the default (release) or 1 (debug) as values. 0 is the default
* `LOG_LEVEL`: Chooses the log level, which controls the amount of console log
output compiled into the build. This should be one of the following:
0 (LOG_LEVEL_NONE)
10 (LOG_LEVEL_NOTICE)
20 (LOG_LEVEL_ERROR)
30 (LOG_LEVEL_WARNING)
40 (LOG_LEVEL_INFO)
50 (LOG_LEVEL_VERBOSE)
All log output up to and including the log level is compiled into the build.
The default value is 40 in debug builds and 20 in release builds.
* `NS_TIMER_SWITCH`: Enable save and restore for non-secure timer register * `NS_TIMER_SWITCH`: Enable save and restore for non-secure timer register
contents upon world switch. It can take either 0 (don't save and restore) or contents upon world switch. It can take either 0 (don't save and restore) or
1 (do save and restore). 0 is the default. An SPD could set this to 1 if it 1 (do save and restore). 0 is the default. An SPD could set this to 1 if it

View File

@ -33,24 +33,53 @@
#include <stdio.h> #include <stdio.h>
/* If building the project with DEBUG disabled the INFO and WARN macros /* The log output macros print output to the console. These macros produce
* won't produce any output. The ERROR macro is always enabled. * compiled log output only if the LOG_LEVEL defined in the makefile (or the
* The format expected is the same as for printf(). * make command line) is greater or equal than the level required for that
* INFO("Info %s.\n", "message") -> INFO: Info message. * type of log output.
* WARN("Warning %s.\n", "message") -> WARN: Warning message. * The format expected is the same as for printf(). For example:
* ERROR("Error %s.\n", "message") -> ERROR: Error message. * INFO("Info %s.\n", "message") -> INFO: Info message.
* * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
* TODO : add debug levels.
*/ */
#if DEBUG
#define INFO(...) tf_printf("INFO: " __VA_ARGS__) #define LOG_LEVEL_NONE 0
#define WARN(...) tf_printf("WARN: " __VA_ARGS__) #define LOG_LEVEL_ERROR 10
#define LOG_LEVEL_NOTICE 20
#define LOG_LEVEL_WARNING 30
#define LOG_LEVEL_INFO 40
#define LOG_LEVEL_VERBOSE 50
#if LOG_LEVEL >= LOG_LEVEL_NOTICE
# define NOTICE(...) tf_printf("NOTICE: " __VA_ARGS__)
#else #else
#define INFO(...) # define NOTICE(...)
#define WARN(...) #endif
#if LOG_LEVEL >= LOG_LEVEL_ERROR
# define ERROR(...) tf_printf("ERROR: " __VA_ARGS__)
#else
# define ERROR(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_WARNING
# define WARN(...) tf_printf("WARNING: " __VA_ARGS__)
#else
# define WARN(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_INFO
# define INFO(...) tf_printf("INFO: " __VA_ARGS__)
#else
# define INFO(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
# define VERBOSE(...) tf_printf("VERBOSE: " __VA_ARGS__)
#else
# define VERBOSE(...)
#endif #endif
#define ERROR(...) tf_printf("ERROR: " __VA_ARGS__)
void __dead2 do_panic(void); void __dead2 do_panic(void);
#define panic() do_panic() #define panic() do_panic()