]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
cli: flush stdin before enabling cli
authorGregor Herburger <gregor.herburger@linutronix.de>
Mon, 13 Apr 2026 15:24:54 +0000 (17:24 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 22 Apr 2026 20:23:49 +0000 (14:23 -0600)
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@linutronix.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/Kconfig
common/cli.c

index 9b8a13c34469af698bef5675da5751e8fd1fd2aa..3fd791f3e4be46fd4e8f324003523ad5f14dd0ba 100644 (file)
@@ -47,6 +47,14 @@ config HUSH_SELECTABLE
        default y if HUSH_OLD_PARSER && HUSH_MODERN_PARSER
 endmenu
 
+config CMDLINE_FLUSH_STDIN
+       bool "Enable flushing input before starting cli"
+       help
+         When this option is enabled the stdin buffer will be flushed before
+         starting the CLI. This is useful when stdin is changed during boot
+         (e.g. from nulldev to serial) and junk characters may be pending
+         in the buffer.
+
 config CMDLINE_EDITING
        bool "Enable command line editing"
        default y
index 4694a35cd0e0c926b38c7d5ec17eb46048aaf726..bcc7264d51a252d9e7f8f2e662dd6dff617f47af 100644 (file)
@@ -295,6 +295,10 @@ err:
 void cli_loop(void)
 {
        bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP);
+
+       if (IS_ENABLED(CONFIG_CMDLINE_FLUSH_STDIN))
+               console_flush_stdin();
+
 #if CONFIG_IS_ENABLED(HUSH_PARSER)
        if (gd->flags & GD_FLG_HUSH_MODERN_PARSER)
                parse_and_run_file();