[PATCH] cli: flush stdin before enabling cli
Tom Rini
trini at konsulko.com
Tue Mar 31 20:11:24 CEST 2026
On Tue, Mar 31, 2026 at 01:03:08PM +0200, Gregor Herburger wrote:
> Currently there is no possibility to flush stdin after autocommands are
> executed. If in the bootcmd the stdin is changed, e.g. from nulldev to
> serial, it could happen that junk characters sit in the fifo and appear
> on the cli.
>
> Add a option to clear stdin before starting the CLI.
>
> Signed-off-by: Gregor Herburger <gregor.herburger at linutronix.de>
Conceptually, good idea, thanks for doing it.
>
> ---
>
> cmd/Kconfig | 7 +++++++
> common/cli.c | 6 ++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 322ebe600c5..e08fbf27358 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -47,6 +47,13 @@ config HUSH_SELECTABLE
> default y if HUSH_OLD_PARSER && HUSH_MODERN_PARSER
> endmenu
>
> +config CMDLINE_FLUSH_STDIN
> + bool "Enable flushing input before starting cli"
> + default n
We don't need default n as that's the default.
> + help
> + When this option is enabled the stdin buffer will be flushed before
> + starting the CLI.
> +
> config CMDLINE_EDITING
> bool "Enable command line editing"
> default y
> diff --git a/common/cli.c b/common/cli.c
> index 4694a35cd0e..42d27ed87e7 100644
> --- a/common/cli.c
> +++ b/common/cli.c
> @@ -295,6 +295,12 @@ err:
> void cli_loop(void)
> {
> bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP);
> +
> + if (IS_ENABLED(CONFIG_CMDLINE_FLUSH_STDIN)) {
> + while (tstc())
> + (void)getchar();
> + }
> +
> #if CONFIG_IS_ENABLED(HUSH_PARSER)
> if (gd->flags & GD_FLG_HUSH_MODERN_PARSER)
> parse_and_run_file();
This is flush_stdin() from common/autoboot.c, but that's a static
function. We should find a better spot for that perhaps and then call it
when required.
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20260331/0c880745/attachment.sig>
More information about the U-Boot
mailing list