@@ -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;
@@ -7,6 +7,8 @@
#ifndef __CONSOLE_H
#define __CONSOLE_H
+#include <stdbool.h>
+
extern char console_buffer[];
/* common/console.c */
@@ -72,6 +74,17 @@ int console_record_avail(void);
*/
int console_announce_r(void);
+/**
+ * console_puts_select_stderr() - Output a string to selected console devices
+ *
+ * This writes to stderr only. It is useful for outputting errors
+ *
+ * @serial_only: true to output only to serial, false to output to everything
+ * else
+ * @s: String to output
+ */
+void console_puts_select_stderr(bool serial_only, const char *s);
+
/*
* CONSOLE multiplexing.
*/
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 at chromium.org> --- Changes in v2: None common/console.c | 28 ++++++++++++++++++++++------ include/console.h | 13 +++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-)