From patchwork Mon May 25 01:48:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 246407 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 24 May 2020 19:48:39 -0600 Subject: [PATCH v2 02/26] console: Add a way to output to serial only In-Reply-To: <20200525014904.115621-1-sjg@chromium.org> References: <20200525014904.115621-1-sjg@chromium.org> Message-ID: <20200525014904.115621-3-sjg@chromium.org> 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 --- Changes in v2: None common/console.c | 28 ++++++++++++++++++++++------ include/console.h | 13 +++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/common/console.c b/common/console.c index 1deca3cb78..31f46470d2 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; diff --git a/include/console.h b/include/console.h index 74afe22b7e..4c6b8f2614 100644 --- a/include/console.h +++ b/include/console.h @@ -7,6 +7,8 @@ #ifndef __CONSOLE_H #define __CONSOLE_H +#include + 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. */