[U-Boot] [PATCH 02/22] spl: Add support for logging in SPL and TPL
Simon Glass
sjg at chromium.org
Wed Sep 26 21:55:00 UTC 2018
It is sometimes useful to log information in SPL and TPL. Add support for
this.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
common/Kconfig | 36 ++++++++++++++++++++++++++++++++++--
common/Makefile | 4 ++--
common/spl/spl.c | 7 +++++++
include/log.h | 7 ++++++-
4 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 3030da4fc99..5c59f66f95e 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -285,6 +285,10 @@ config SPL_LOGLEVEL
int
default LOGLEVEL
+config TPL_LOGLEVEL
+ int
+ default LOGLEVEL
+
config SILENT_CONSOLE
bool "Support a silent console"
help
@@ -481,6 +485,24 @@ config SPL_LOG_MAX_LEVEL
6 - detail
7 - debug
+config TPL_LOG_MAX_LEVEL
+ int "Maximum log level to record in TPL"
+ depends on TPL_LOG
+ default 3
+ help
+ This selects the maximum log level that will be recorded. Any value
+ higher than this will be ignored. If possible log statements below
+ this level will be discarded at build time. Levels:
+
+ 0 - panic
+ 1 - critical
+ 2 - error
+ 3 - warning
+ 4 - note
+ 5 - info
+ 6 - detail
+ 7 - debug
+
config LOG_CONSOLE
bool "Allow log output to the console"
depends on LOG
@@ -491,9 +513,19 @@ config LOG_CONSOLE
log message is shown - other details like level, category, file and
line number are omitted.
-config LOG_SPL_CONSOLE
+config SPL_LOG_CONSOLE
+ bool "Allow log output to the console in SPL"
+ depends on SPL_LOG
+ default y
+ help
+ Enables a log driver which writes log records to the console.
+ Generally the console is the serial port or LCD display. Only the
+ log message is shown - other details like level, category, file and
+ line number are omitted.
+
+config TPL_LOG_CONSOLE
bool "Allow log output to the console in SPL"
- depends on LOG_SPL
+ depends on TPL_LOG
default y
help
Enables a log driver which writes log records to the console.
diff --git a/common/Makefile b/common/Makefile
index 7473b850115..cbca4ff2da6 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -118,8 +118,8 @@ obj-y += cli.o
obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_simple.o cli_readline.o
obj-$(CONFIG_DFU_OVER_USB) += dfu.o
obj-y += command.o
-obj-$(CONFIG_$(SPL_)LOG) += log.o
-obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o
+obj-$(CONFIG_$(SPL_TPL_)LOG) += log.o
+obj-$(CONFIG_$(SPL_TPL_)LOG_CONSOLE) += log_console.o
obj-y += s_record.o
obj-y += xyzModem.o
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 19508c71685..933d290c87e 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -333,6 +333,13 @@ static int spl_common_init(bool setup_malloc)
return ret;
}
bootstage_mark_name(BOOTSTAGE_ID_START_SPL, "spl");
+#if CONFIG_IS_ENABLED(LOG)
+ ret = log_init();
+ if (ret) {
+ debug("%s: Failed to set up logging\n", __func__);
+ return ret;
+ }
+#endif
if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {
ret = fdtdec_setup();
if (ret) {
diff --git a/include/log.h b/include/log.h
index 75ff1e1160c..1146f423a7a 100644
--- a/include/log.h
+++ b/include/log.h
@@ -92,6 +92,8 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
#define _LOG_MAX_LEVEL LOGL_INFO
#endif
+#if CONFIG_IS_ENABLED(LOG)
+
/* Emit a log record if the level is less that the maximum */
#define log(_cat, _level, _fmt, _args...) ({ \
int _l = _level; \
@@ -100,6 +102,9 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
__func__, \
pr_fmt(_fmt), ##_args); \
})
+#else
+#define log(_cat, _level, _fmt, _args...)
+#endif
#ifdef DEBUG
#define _DEBUG 1
@@ -159,7 +164,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
({ if (!(x) && _DEBUG) \
__assert_fail(#x, __FILE__, __LINE__, __func__); })
-#ifdef CONFIG_LOG_ERROR_RETURN
+#if CONFIG_IS_ENABLED(LOG) && defined(CONFIG_LOG_ERROR_RETURN)
#define log_ret(_ret) ({ \
int __ret = (_ret); \
if (__ret < 0) \
--
2.19.0.605.g01d371f741-goog
More information about the U-Boot
mailing list