diff mbox series

[U-Boot,v4,09/15] log: Add a console driver

Message ID 20171204204831.98915-10-sjg@chromium.org
State Accepted
Delegated to: Tom Rini
Headers show
Series log: Add a new logging feature | expand

Commit Message

Simon Glass Dec. 4, 2017, 8:48 p.m. UTC
It is useful to display log messages on the console. Add a simple driver
to handle this.

Note that this driver outputs to the console, which may be serial or
video. It does not specifically select serial output.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v4: None
Changes in v3: None
Changes in v2:
- Update commit message to explain that this is not just for serial output

 common/Kconfig       | 20 ++++++++++++++++++++
 common/Makefile      |  1 +
 common/log_console.c | 23 +++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 common/log_console.c

Comments

Tom Rini Dec. 7, 2017, 10:54 p.m. UTC | #1
On Mon, Dec 04, 2017 at 01:48:25PM -0700, Simon Glass wrote:

> It is useful to display log messages on the console. Add a simple driver
> to handle this.
> 
> Note that this driver outputs to the console, which may be serial or
> video. It does not specifically select serial output.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/Kconfig b/common/Kconfig
index 9747443feb..1b157e47c3 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -474,6 +474,26 @@  config SPL_LOG_MAX_LEVEL
 	    6 - detail
 	    7 - debug
 
+config LOG_CONSOLE
+	bool "Allow log output to the console"
+	depends on 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 LOG_SPL_CONSOLE
+	bool "Allow log output to the console in SPL"
+	depends on LOG_SPL
+	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.
+
 endmenu
 
 config DEFAULT_FDT_FILE
diff --git a/common/Makefile b/common/Makefile
index f4b632761f..14166209fe 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -129,5 +129,6 @@  obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_simple.o cli_readline.o
 obj-$(CONFIG_CMD_DFU) += dfu.o
 obj-y += command.o
 obj-$(CONFIG_$(SPL_)LOG) += log.o
+obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o
 obj-y += s_record.o
 obj-y += xyzModem.o
diff --git a/common/log_console.c b/common/log_console.c
new file mode 100644
index 0000000000..5af73bd8be
--- /dev/null
+++ b/common/log_console.c
@@ -0,0 +1,23 @@ 
+/*
+ * Logging support
+ *
+ * Copyright (c) 2017 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <log.h>
+
+static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
+{
+	puts(rec->msg);
+
+	return 0;
+}
+
+LOG_DRIVER(console) = {
+	.name	= "console",
+	.emit	= log_console_emit,
+};