[PATCH] cli: flush stdin before enabling cli
Quentin Schulz
quentin.schulz at cherry.de
Wed Apr 1 13:18:24 CEST 2026
Hi Gregor,
On 4/1/26 12:46 PM, Gregor Herburger wrote:
> [You don't often get email from gregor.herburger at linutronix.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
>>> 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.
>>>
>>
>> Why does this need an option? I don't know enough (anything really) about
>> the cli in general but the wording seems to indicate this fixes an issue or
>> even a bug. Is there a case in which we wouldn't want to flush?
>
> In our case the problem was in efi_console where query_console_serial
> sent the escape sequence to stdout and stdin was set to nulldev and
> therefore never received. In the bootcmd stdin was set to serial and the
> response was seen on the cli. Thats how it was in our case. My first
> approach was to check in efi_console to not send if stdin is nulldev.
> But after more thoughts I implemented the current approach which flushes
> stdin before starting cli. After all efi_console did exactly what was
> configured in the environment.
>
> I can think of two cases where stdin shouldn't be flushed:
> * User typing commands before cli is reached.
I see we have flush_stdin() in common/autoboot.c already, with the same
implementation. Guarded by CONFIG_AUTOBOOT_FLUSH_STDIN. So I guess if we
have a knob for that, another knob for the cli_loop() part will at least
be consistent so fine by me. I kinda fail to see why we would not want
to flush, but /me shrugs.
Cheers,
Quentin
More information about the U-Boot
mailing list