aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSimon Glass2020-07-02 21:12:13 -0600
committerBin Meng2020-07-09 12:33:24 +0800
commit493a4c8af7a4939d96d6e2601282ca4a07c7570e (patch)
tree1d93231503b6d89dadf8480a92210e4580eccfbb /common
parent3dada5a1a89f336f4b751548117949cf255cfcf6 (diff)
console: Add a way to output to serial only
In the video drivers it is useful to print errors while debugging but doing so risks an infinite loop as the debugging info itself may go through the video drivers. Add a new console function that prints information only to the serial device, thus making it safe for use in debugging. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'common')
-rw-r--r--common/console.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/common/console.c b/common/console.c
index 7b9816979af..07c483f820e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -229,18 +229,34 @@ static void console_putc(int file, const char c)
}
}
-static void console_puts_noserial(int file, const char *s)
+/**
+ * console_puts_select() - Output a string to all console devices
+ *
+ * @file: File number to output to (e,g, stdout, see stdio.h)
+ * @serial_only: true to output only to serial, false to output to everything
+ * else
+ * @s: String to output
+ */
+static void console_puts_select(int file, bool serial_only, const char *s)
{
int i;
struct stdio_dev *dev;
for (i = 0; i < cd_count[file]; i++) {
+ bool is_serial;
+
dev = console_devices[file][i];
- if (dev->puts != NULL && !console_dev_is_serial(dev))
+ is_serial = console_dev_is_serial(dev);
+ if (dev->puts && serial_only == is_serial)
dev->puts(dev, s);
}
}
+void console_puts_select_stderr(bool serial_only, const char *s)
+{
+ console_puts_select(stderr, serial_only, s);
+}
+
static void console_puts(int file, const char *s)
{
int i;
@@ -275,9 +291,9 @@ static inline void console_putc(int file, const char c)
stdio_devices[file]->putc(stdio_devices[file], c);
}
-static inline void console_puts_noserial(int file, const char *s)
+void console_puts_select(int file, bool serial_only, const char *s)
{
- if (!console_dev_is_serial(stdio_devices[file]))
+ if (serial_only == console_dev_is_serial(stdio_devices[file]))
stdio_devices[file]->puts(stdio_devices[file], s);
}
@@ -489,7 +505,7 @@ static void print_pre_console_buffer(int flushpoint)
puts(buf_out);
break;
case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL:
- console_puts_noserial(stdout, buf_out);
+ console_puts_select(stdout, false, buf_out);
break;
}
}
@@ -776,7 +792,7 @@ int console_announce_r(void)
display_options_get_banner(false, buf, sizeof(buf));
- console_puts_noserial(stdout, buf);
+ console_puts_select(stdout, false, buf);
#endif
return 0;