public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Gregor Herburger <gregor.herburger@linutronix.de>
Cc: u-boot@lists.denx.de,
	Andrew Goodbody <andrew.goodbody@linaro.org>,
	Heiko Schocher <hs@nabladev.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	"Kory Maincent (TI.com)" <kory.maincent@bootlin.com>,
	Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
	Quentin Schulz <quentin.schulz@cherry.de>
Subject: Re: [PATCH] cli: flush stdin before enabling cli
Date: Tue, 31 Mar 2026 12:11:24 -0600	[thread overview]
Message-ID: <20260331181124.GD41863@bill-the-cat> (raw)
In-Reply-To: <20260331110413.1040527-1-gregor.herburger@linutronix.de>

[-- Attachment #1: Type: text/plain, Size: 1832 bytes --]

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@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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-03-31 18:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 11:03 [PATCH] cli: flush stdin before enabling cli Gregor Herburger
2026-03-31 18:11 ` Tom Rini [this message]
2026-04-01  5:32   ` Gregor Herburger
2026-04-01  9:28 ` Quentin Schulz
2026-04-01 10:46   ` Gregor Herburger
2026-04-01 11:18     ` Quentin Schulz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260331181124.GD41863@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=andrew.goodbody@linaro.org \
    --cc=gregor.herburger@linutronix.de \
    --cc=hs@nabladev.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kory.maincent@bootlin.com \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=quentin.schulz@cherry.de \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox