From: Marek Vasut Date: Tue, 17 Mar 2026 02:17:40 +0000 (+0100) Subject: console: Prefer currently selected serial console as stdio device X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32dc2866e020edcd89b26366ccb8fa7a2ee2859d;p=thirdparty%2Fu-boot.git console: Prefer currently selected serial console as stdio device 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 Reviewed-by: Simon Glass --- 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; }