console: allocate the device list when SYS_CONSOLE_IS_IN_ENV is off
PATCH 1/1 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.
--- common/console.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
common/console.c +13 -0
@@ -248,6 +248,19 @@ int cd_count[MAX_FILES];static void console_devices_set (int file,struct stdio_dev *dev) { +/* +* 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. +*/ +if (!console_devices[file]) { + console_devices[file] =calloc (1 ,sizeof (struct stdio_dev *)); +if (!console_devices[file]) { + cd_count[file] =0 ; +return ; + } + } console_devices[file][0 ] = dev; cd_count[file] =1 ; }
Signature · 1 line
2.47.3
Quoted 10 lines · Yalçın Can
With
CONSOLE_MUXbut withoutSYS_CONSOLE_IS_IN_ENV,console_init_r()callsconsole_devices_set()before anything has allocated console_devices[file] (onlyiomux_doenv()does). The stdout device pointer is then written to address 0 and read back from there byconsole_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 astdio_dev, hanging inconsole_announce_r().
Quoted 7 lines
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]>
Thank you for disclosing that you used AI here. As a project, we generally discourage its use.
Quoted 18 lines
--- common/console.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)common/console.c +6
-0@@ -248,6 +248,19 @@ int cd_count[MAX_FILES];static void console_devices_set (int file,struct stdio_dev *dev) { +/* +* 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. +*/
common/console.c int cd_count[MAX_FILES]; · line 266
Quoted 10 lines
common/console.c +7
-0+if (!console_devices[file]) { + console_devices[file] =calloc (1 ,sizeof (struct stdio_dev *)); +if (!console_devices[file]) { + cd_count[file] =0 ; +return ; + } + } console_devices[file][0 ] = dev; cd_count[file] =1 ; }
How you found the issue is interesting. But we support plenty of platforms already where 0x0 is not valid memory. So this is one of those cases where it's impossible to know, without someone spending time to verify the details, if what Claude deduced makes any sense, or not, if this is the right fix.
Signature · 1 line
Tom
Hi Yalçın,
Quoted 25 lines · Yalçın Can
console: allocate the device list when
SYS_CONSOLE_IS_IN_ENVis offWith
CONSOLE_MUXbut withoutSYS_CONSOLE_IS_IN_ENV,console_init_r()callsconsole_devices_set()before anything has allocated console_devices[file] (onlyiomux_doenv()does). The stdout device pointer is then written to address 0 and read back from there byconsole_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 astdio_dev, hanging inconsole_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(+)
common/console.c int cd_count[MAX_FILES]; · line 253
Quoted 6 lines
common/console.c +6
-0@@ -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.
common/console.c int cd_count[MAX_FILES]; · line 249
Quoted 4 lines
common/console.c +2
-0@@ -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