[PATCH v2] console: Prefer currently selected serial console as stdio device
Simon Glass
sjg at chromium.org
Tue Mar 17 13:29:07 CET 2026
On Mon, 16 Mar 2026 at 20:18, Marek Vasut
<marek.vasut+renesas at mailbox.org> wrote:
>
> Adjust the scan for default console stdio device to prefer the
> currently selected serial device. This is useful in combination
> with CONFIG_SERIAL_PROBE_ALL=y, in which case the system would
> instantiate all serial devices as stdio devices in the order in
> which they are listed in control DT. The currently selected serial
> device may not be the first device listed in DT, in which case the
> current console_init_r() implementation unexpectedly switches to
> another serial console after listing stderr using "Err:" line, and
> just before showing U-Boot shell, which is not the desired behavior.
>
> The scan now iterates over the entire list of stdio devices. If the
> current iterator stdio device is the current serial device, or there
> is no input or output stdio device assigned to the input or output
> stream yet, then the current iterator stdio device is assigned to that
> stream. This way, the first suitable stdio device is assigned to the
> stream, but the current serial console stdio device can override that
> assignment.
>
> As a small optimization, if the current iterator stdio device is the
> current serial device and both input and output streams as assigned,
> then the loop can terminate, because the current serial device has a
> chance to be used as a stdio device at this point.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Alexander Sverdlin <alexander.sverdlin at siemens.com>
> Cc: Andre Przywara <andre.przywara at arm.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: u-boot at lists.denx.de
> ---
> V2: Merge the two loops into one
> ---
> common/console.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/common/console.c b/common/console.c
> index 48586fd2166..22e554cf203 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -1212,13 +1212,16 @@ int console_init_r(void)
> list_for_each(pos, list) {
> dev = list_entry(pos, struct stdio_dev, list);
>
> - if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
> + if ((dev->flags & DEV_FLAGS_INPUT) &&
> + (dev->priv == gd->cur_serial_dev || !inputdev))
> inputdev = dev;
> - }
> - if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
> +
> + if ((dev->flags & DEV_FLAGS_OUTPUT) &&
> + (dev->priv == gd->cur_serial_dev || !outputdev))
> outputdev = dev;
> - }
> - if(inputdev && outputdev)
> +
> + /* The current serial console is the preferred stdio. */
> + if (dev->priv == gd->cur_serial_dev && inputdev && outputdev)
> break;
> }
>
> --
> 2.51.0
>
Reviewed-by: Simon Glass <sjg at chromium.org>
More information about the U-Boot
mailing list