console: Implement flush() function

On certain places it is required to flush output print buffers to ensure
that text strings were sent to console or serial devices. For example when
printing message that U-Boot is going to boot kernel or when U-Boot is
going to change baudrate of terminal device.

Therefore introduce a new flush() and fflush() functions into console code.
These functions will call .flush callback of associated stdio_dev device.

As this function may increase U-Boot side, allow to compile U-Boot without
this function. For this purpose there is a new config CONSOLE_FLUSH_SUPPORT
which is enabled by default and can be disabled. It is a good idea to have
this option enabled for all boards which have enough space for it.

When option is disabled when U-Boot defines just empty static inline
function fflush() to avoid ifdefs in other code.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Pali Rohár
2022-09-05 11:31:17 +02:00
committed by Tom Rini
parent 7df5b35334
commit 974f48366f
5 changed files with 92 additions and 0 deletions

View File

@@ -37,6 +37,13 @@ struct stdio_dev {
void (*putc)(struct stdio_dev *dev, const char c);
/* To put a string (accelerator) */
void (*puts)(struct stdio_dev *dev, const char *s);
#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
/* To flush output queue */
void (*flush)(struct stdio_dev *dev);
#define STDIO_DEV_ASSIGN_FLUSH(dev, flush_func) ((dev)->flush = (flush_func))
#else
#define STDIO_DEV_ASSIGN_FLUSH(dev, flush_func)
#endif
/* INPUT functions */