]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
console: Prefer currently selected serial console as stdio device
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Tue, 17 Mar 2026 02:17:40 +0000 (03:17 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 30 Mar 2026 23:02:17 +0000 (17:02 -0600)
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@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
common/console.c

index 48586fd2166246ad41c00e771a3989f1d5b9ddbd..22e554cf203a5db33a274c96bcb0e4ff074a8a5a 100644 (file)
@@ -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;
        }