U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/21] spl: Add support for logging in SPL and TPL
Date: Thu, 15 Nov 2018 18:43:49 -0700	[thread overview]
Message-ID: <20181116014409.147279-2-sjg@chromium.org> (raw)
In-Reply-To: <20181116014409.147279-1-sjg@chromium.org>

It is sometimes useful to log information in SPL and TPL. Add support for
this.

Reviewed-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Add comments to the log_ret() functions to indicate usage
- Update log_msg_ret() to make use of the message and avoid a warning

Changes in v2: None

 common/Kconfig   | 36 ++++++++++++++++++++++++++++++++++--
 common/Makefile  |  4 ++--
 common/spl/spl.c |  7 +++++++
 include/log.h    | 19 +++++++++++++++++--
 4 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index d7300c212f5..9bc329a0e61 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -290,6 +290,10 @@ config SPL_LOGLEVEL
 	int
 	default LOGLEVEL
 
+config TPL_LOGLEVEL
+	int
+	default LOGLEVEL
+
 config SILENT_CONSOLE
 	bool "Support a silent console"
 	help
@@ -486,6 +490,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
@@ -496,9 +518,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 a2388364d9f..d18897b973b 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-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 12f9359c0ac..740182a8be6 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -336,6 +336,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 a872fc6ef5f..ad6870bfed8 100644
--- a/include/log.h
+++ b/include/log.h
@@ -107,6 +107,8 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 #define log_io(_fmt...)
 #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; \
@@ -115,6 +117,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
@@ -174,7 +179,16 @@ 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)
+/*
+ * Log an error return value, possibly with a message. Usage:
+ *
+ *	return log_ret(fred_call());
+ *
+ * or:
+ *
+ *	return log_msg_ret("fred failed", fred_call());
+ */
 #define log_ret(_ret) ({ \
 	int __ret = (_ret); \
 	if (__ret < 0) \
@@ -189,8 +203,9 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
 	__ret; \
 	})
 #else
+/* Non-logging versions of the above which just return the error code */
 #define log_ret(_ret) (_ret)
-#define log_msg_ret(_msg, _ret) (_ret)
+#define log_msg_ret(_msg, _ret) ((void)(_msg), _ret)
 #endif
 
 /**
-- 
2.19.1.1215.g8438c0b245-goog

  reply	other threads:[~2018-11-16  1:43 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16  1:43 [U-Boot] [PATCH v3 00/21] spl: Add features for passing info from SPL to U-Boot proper Simon Glass
2018-11-16  1:43 ` Simon Glass [this message]
2018-11-26 18:43   ` [U-Boot] [U-Boot, v3, 01/21] spl: Add support for logging in SPL and TPL Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 02/21] Add core support for a bloblist to convey data from SPL Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 03/21] spl: Set up the bloblist in SPL Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot,v3,03/21] " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 04/21] bloblist: Locate bloblist in U-Boot Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot,v3,04/21] " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 05/21] test: Add a simple test for bloblist Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 06/21] Add bloblist documentation Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot,v3,06/21] " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 07/21] spl: Support hash, input, pch, pci, rtc, tpm in SPL Simon Glass
2018-11-26 18:43   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 08/21] spl: Add a define for SPL_TPL_PROMPT Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 09/21] spl: Make SPL_DISABLE_BANNER_PRINT a positive option Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 10/21] spl: Add a comment to spl_set_bd() Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot,v3,10/21] " Tom Rini
2018-11-16  1:43 ` [U-Boot] [PATCH v3 11/21] sandbox: Add a memory map to the sandbox README Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 12/21] test/py: Add a way to pass flags to sandbox Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 13/21] sandbox: Add an option to display of-platdata in SPL Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 14/21] sandbox: Drop the deprecated 'sb' command Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 15/21] sandbox: Add a new " Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot,v3,15/21] " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 16/21] sandbox: Allow puts() output before global_data is set up Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 17/21] sandbox: Refactor code to create os_jump_to_file() Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 18/21] sandbox: Use malloc() and free() from os layer Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 19/21] sandbox: Filter arguments when starting U-Boot Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 20/21] sandbox: Boot in U-Boot through the standard call Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-16  1:44 ` [U-Boot] [PATCH v3 21/21] spl: Add support for passing handoff info to U-Boot proper Simon Glass
2018-11-26 18:44   ` [U-Boot] [U-Boot, v3, " Tom Rini
2018-11-27  0:08     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181116014409.147279-2-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox