Hi Yalçın,
On 2026-10-30T07:36:55+11:00, Yalçın Can <[email protected]> wrote:
> console: allocate the device list when SYS_CONSOLE_IS_IN_ENV is off
>
> With CONSOLE_MUX but without SYS_CONSOLE_IS_IN_ENV, console_init_r() calls
> console_devices_set() before anything has allocated console_devices[file]
> (only iomux_doenv() does). The stdout device pointer is then written to
> address 0 and read back from there by console_puts_select().
>
> That goes unnoticed while address 0 is RAM. On the RK3066 started from
> the boot ROM, address 0 is the ROM (GRF soc_remap = 0): the write is
> lost and the console calls ROM words as a stdio_dev, hanging in
> console_announce_r().
>
> Allocate the one-entry list when it is missing.
>
> Tested on an MK808B (RK3066) with U-Boot started from the NAND ID blocks:
> boots to autoboot with the USB ACM console; before, it hung at the banner.
>
> Co-Authored-By: Claude Opus 5.5 <[email protected]>
> Signed-off-by: Yalçın Can <[email protected]>
>
> common/console.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
> diff --git a/common/console.c b/common/console.c
> @@ -248,6 +248,19 @@ int cd_count[MAX_FILES];
> + /*
> + * Only iomux_doenv() allocates the device list. Without
> SYS_CONSOLE_IS_IN_ENV,
> + * console_init_r() gets here first and the list is still NULL: the
> device went to address 0
> + * and was read back from there. That only works while 0 is RAM
> (MK808B: after the vendor
> + * loader's soc_remap); from the boot ROM, 0 is the ROM and the console
> calls garbage.
> + */
Please can you cut this down to a line or two, e.g. 'iomux_doenv() has
not allocated the list yet if SYS_CONSOLE_IS_IN_ENV is disabled'. The
MK808B and soc_remap details are in the commit message and will go out
of date here. The lines are also well over 80 columns.
> diff --git a/common/console.c b/common/console.c
> @@ -248,6 +248,19 @@ int cd_count[MAX_FILES];
> + if (!console_devices[file]) {
> + console_devices[file] = calloc(1, sizeof(struct stdio_dev *));
On Tom's question, I checked this. console_devices[] is a
zero-initialised global. In the !SYS_CONSOLE_IS_IN_ENV version of
console_init_r(), the env_set() calls run before GD_FLG_DEVINIT is
set, so on_console() returns early and iomux_doenv() never runs. So
console_devices_set() really does write through a NULL pointer. If
iomux_doenv() runs later (e.g. 'setenv stdout ...') it frees this list
as 'old_set', so a heap allocation is correct.
It would be worth putting this in the commit message, since it shows
the problem without relying on the RK3066 memory map. Also,
sizeof(*console_devices[file]) would be a little more robust than
spelling out the type.
A sandbox test with CONSOLE_MUX enabled and SYS_CONSOLE_IS_IN_ENV
disabled would be good, perhaps as a follow-up.
Regards,
Simon