of: Fix handling CONFIG_CMDLINE* even without /chosen node
Rob Herring
maintainercover of: Fix handling CONFIG_CMDLINE* even without /chosen node
Commit a7d550f82b445cf218b47a2c1a9c56e97ecb8c7a (of: fdt: Honor CONFIG_CMDLINE* even without /chosen node) moved the processing of the kernel built-in command line (CONFIG_CMDLINE) from the early_init_dt_scan_chosen routine to the early_init_dt_scan_nodes routine.
The current powerpc startup code does not call into early_init_dt_scan_nodes, so processing of CONFIG_CMDLINE never happens, even if CONFIG_CMDLINE_FORCE=y. The result is an empty kernel command line, and mounting of the root file system then fails with a kernel panic (not syncing: VFS: Unable to mount root fs).
Let's revert the above commit and redo the missing /chosen node handling within early_init_dt_scan_chosen().
---
Rob Herring (2):
Revert "of: fdt: Honor CONFIG_CMDLINE* even without /chosen node"
of: fdt: Honor CONFIG_CMDLINE* even without /chosen node, take 2
drivers/of/fdt.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-)
---
base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2
change-id: 20230103-dt-cmdline-fix-e36eb7e39b75
Best regards,
Signature · 1 line
Rob Herring <[email protected]>
Rob Herring
maintainerPATCH 1/2 Revert "of: fdt: Honor CONFIG_CMDLINE* even without /chosen node"
This reverts commit a7d550f82b445cf218b47a2c1a9c56e97ecb8c7a.
Some arches (PPC at least) don't call early_init_dt_scan_nodes(), so moving the cmdline processing there breaks them.
--- drivers/of/fdt.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/of/fdt.c +20 -20
@@ -1173,6 +1173,26 @@ int __init early_init_dt_scan_chosen(char *cmdline)if (p !=NULL && l >0 )strscpy (cmdline, p,min (l,COMMAND_LINE_SIZE )); +/* +* CONFIG_CMDLINE is meant to be a default in case nothing else +* managed to set the command line, unless CONFIG_CMDLINE_FORCE +* is set in which case we override whatever was found earlier. +*/ +#ifdef CONFIG_CMDLINE +#if defined(CONFIG_CMDLINE_EXTEND ) +strlcat (cmdline," " ,COMMAND_LINE_SIZE ); +strlcat (cmdline,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +#elif defined(CONFIG_CMDLINE_FORCE ) +strscpy (cmdline,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +#else +/* No arguments from boot loader, use kernel's cmdl*/ +if (!((char *)cmdline)[0 ]) +strscpy (cmdline,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); +#endif +#endif /* CONFIG_CMDLINE */ + +pr_debug ("Command line is: %s\n" , (char *)cmdline); + rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l);if (rng_seed && l >0 ) {add_bootloader_randomness (rng_seed, l);
@@ -1277,26 +1297,6 @@ void __init early_init_dt_scan_nodes(void)if (rc)pr_warn ("No chosen node found, continuing without\n" ); -/* -* CONFIG_CMDLINE is meant to be a default in case nothing else -* managed to set the command line, unless CONFIG_CMDLINE_FORCE -* is set in which case we override whatever was found earlier. -*/ -#ifdef CONFIG_CMDLINE -#if defined(CONFIG_CMDLINE_EXTEND ) -strlcat (boot_command_line," " ,COMMAND_LINE_SIZE ); -strlcat (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); -#elif defined(CONFIG_CMDLINE_FORCE ) -strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); -#else -/* No arguments from boot loader, use kernel's cmdl */ -if (!boot_command_line[0 ]) -strscpy (boot_command_line,CONFIG_CMDLINE ,COMMAND_LINE_SIZE ); -#endif -#endif /* CONFIG_CMDLINE */ - -pr_debug ("Command line is: %s\n" , boot_command_line); -/* Setup memory, calling early_init_dt_add_memory_arch */ early_init_dt_scan_memory ();
Signature · 1 line
2.39.0
Rob Herring
maintainerPATCH 2/2 of: fdt: Honor CONFIG_CMDLINE* even without /chosen node, take 2
In reply to Rob HerringI do not read a strict requirement on /chosen node in either ePAPR or in Documentation/devicetree. Help text for CONFIG_CMDLINE and CONFIG_CMDLINE_EXTEND doesn't make their behavior explicitly dependent on the presence of /chosen or the presense of /chosen/bootargs.
However the early check for /chosen and bailing out in early_init_dt_scan_chosen() skips CONFIG_CMDLINE handling which is not really related to /chosen node or the particular method of passing cmdline from bootloader.
This leads to counterintuitive combinations (assuming CONFIG_CMDLINE_EXTEND=y):
a) bootargs="foo", CONFIG_CMDLINE="bar" => cmdline=="foo bar"
b) /chosen missing, CONFIG_CMDLINE="bar" => cmdline==""
c) bootargs="", CONFIG_CMDLINE="bar" => cmdline==" bar"
Rework early_init_dt_scan_chosen() so that the cmdline config options are always handled.
--- drivers/of/fdt.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/of/fdt.c +15 -13
@@ -1161,18 +1161,32 @@ int __init early_init_dt_scan_chosen(char *cmdline)if (node <0 ) node =fdt_path_offset (fdt,"/chosen@0" );if (node <0 ) -return -ENOENT ; +/* Handle the cmdline config options even if no /chosen node */ + goto handle_cmdline; chosen_node_offset = node;early_init_dt_check_for_initrd (node);early_init_dt_check_for_elfcorehdr (node); + rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l); +if (rng_seed && l >0 ) { +add_bootloader_randomness (rng_seed, l); + +/* try to clear seed so it won't be found. */ +fdt_nop_property (initial_boot_params, node,"rng-seed" ); + +/* update CRC check value */ + of_fdt_crc32 =crc32_be (~0 , initial_boot_params, +fdt_totalsize (initial_boot_params)); + } +/* Retrieve command line */ p =of_get_flat_dt_prop (node,"bootargs" , &l);if (p !=NULL && l >0 )strscpy (cmdline, p,min (l,COMMAND_LINE_SIZE )); +handle_cmdline:/* * CONFIG_CMDLINE is meant to be a default in case nothing else * managed to set the command line, unless CONFIG_CMDLINE_FORCE
@@ -1193,18 +1207,6 @@ int __init early_init_dt_scan_chosen(char *cmdline)pr_debug ("Command line is: %s\n" , (char *)cmdline); - rng_seed =of_get_flat_dt_prop (node,"rng-seed" , &l); -if (rng_seed && l >0 ) { -add_bootloader_randomness (rng_seed, l); - -/* try to clear seed so it won't be found. */ -fdt_nop_property (initial_boot_params, node,"rng-seed" ); - -/* update CRC check value */ - of_fdt_crc32 =crc32_be (~0 , initial_boot_params, -fdt_totalsize (initial_boot_params)); - } -return 0 ; }
Signature · 1 line
2.39.0
Hi Rob,
Quoted 4 lines · Rob Herring
Let's revert the above commit and redo the missing /chosen node handling within
early_init_dt_scan_chosen().
Quoted 8 lines
Signed-off-by Rob Herring <[email protected]>---
Rob Herring (2):
Revert "of: fdt: Honor CONFIG_CMDLINE* even without /chosen node"
of: fdt: Honor CONFIG_CMDLINE* even without /chosen node, take 2drivers/of/fdt.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-)
I applied these two patches to v6.2-rc2 and tested on PS3. I used a kernel config file that had a CONFIG_CMDLINE, and CONFIG_CMDLINE_FORCE=y set. Everything seemed to work OK.
Hi Rob,
thanks for looking into it!
Quoted 10 lines · Rob Herring
Commit
a7d550f82b445cf218b47a2c1a9c56e97ecb8c7a(of: fdt: Honor CONFIG_CMDLINE* even without /chosen node) moved the processing of the kernel built-in command line (CONFIG_CMDLINE) from theearly_init_dt_scan_chosenroutine to theearly_init_dt_scan_nodesroutine.The current powerpc startup code does not call into
early_init_dt_scan_nodes, so processing ofCONFIG_CMDLINEnever happens, even ifCONFIG_CMDLINE_FORCE=y. The result is an empty kernel command line, and mounting of the root file system then fails with a kernel panic (not syncing: VFS: Unable to mount root fs).
Quoted 4 lines
Let's revert the above commit and redo the missing /chosen node handling within
early_init_dt_scan_chosen().Signed-off-by Rob Herring <[email protected]>
The series looks good to me,
Signature · 1 line
Alexander Sverdlin.