[PATCH v1] serial-uclass: reset gd->cur_serial_dev to NULL if serial not found

Tom Rini trini at konsulko.com
Thu Aug 31 18:26:27 CEST 2023


On Fri, Aug 18, 2023 at 12:34:30PM +0300, Maksim Kiselev wrote:

> Reset gd->cur_serial_dev pointer to avoid calling non-relocated code
> from relocated code if a serial driver is not found and
> CONFIG_REQUIRE_SERIAL_CONSOLE is disabled.
> 
> Here is detailed explanation of what this patch is trying to fix.
> 
> U-boot calls the serial_find_console_or_panic() function twice.
> The first console setup occurs before U-boot relocation in
> the serial_init(). This stage uses simple FDT parsing and
> assigns gd->cur_serial_dev to a "serial" device that lives in
> non-relocated code too.
> 
> The second console setup after U-boot relocation(from serial_initialize())
> may use full live DT (if OF_LIVE enabled) probe sequence with buses,
> clocks, resets, etc... And if the console setup fails at this step,
> than we should be caught by panic_str("No serial driver found").
> 
> But... If we disable CONFIG_REQUIRE_SERIAL_CONSOLE, than we
> return from serial_init() with gd->cur_serial_dev pointing
> to the "old"(non-relocated) serial device.
> 
> And if this area, where "old" serial device is placed, is changed
> (e.g. Linux kernel may be relocated at this address), than we will get
> an unexpected crash on the next call of printf().
> 
> Signed-off-by: Maksim Kiselev <bigunclemax at gmail.com>

Applied to u-boot/next, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20230831/30ba7fb0/attachment.sig>


More information about the U-Boot mailing list