Skip to content

Commit 064e32d

Browse files
committed
of: fdt: Honor CONFIG_CMDLINE* even without /chosen node, take 2
I 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. [commit msg written by Alexander Sverdlin] Cc: Alexander Sverdlin <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Arnd Bergmann <[email protected]> Tested-by: Geoff Levand <[email protected]> Reviewed-by: Alexander Sverdlin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring <[email protected]>
1 parent bd0ddcf commit 064e32d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/of/fdt.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,18 +1163,32 @@ int __init early_init_dt_scan_chosen(char *cmdline)
11631163
if (node < 0)
11641164
node = fdt_path_offset(fdt, "/chosen@0");
11651165
if (node < 0)
1166-
return -ENOENT;
1166+
/* Handle the cmdline config options even if no /chosen node */
1167+
goto handle_cmdline;
11671168

11681169
chosen_node_offset = node;
11691170

11701171
early_init_dt_check_for_initrd(node);
11711172
early_init_dt_check_for_elfcorehdr(node);
11721173

1174+
rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l);
1175+
if (rng_seed && l > 0) {
1176+
add_bootloader_randomness(rng_seed, l);
1177+
1178+
/* try to clear seed so it won't be found. */
1179+
fdt_nop_property(initial_boot_params, node, "rng-seed");
1180+
1181+
/* update CRC check value */
1182+
of_fdt_crc32 = crc32_be(~0, initial_boot_params,
1183+
fdt_totalsize(initial_boot_params));
1184+
}
1185+
11731186
/* Retrieve command line */
11741187
p = of_get_flat_dt_prop(node, "bootargs", &l);
11751188
if (p != NULL && l > 0)
11761189
strscpy(cmdline, p, min(l, COMMAND_LINE_SIZE));
11771190

1191+
handle_cmdline:
11781192
/*
11791193
* CONFIG_CMDLINE is meant to be a default in case nothing else
11801194
* managed to set the command line, unless CONFIG_CMDLINE_FORCE
@@ -1195,18 +1209,6 @@ int __init early_init_dt_scan_chosen(char *cmdline)
11951209

11961210
pr_debug("Command line is: %s\n", (char *)cmdline);
11971211

1198-
rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l);
1199-
if (rng_seed && l > 0) {
1200-
add_bootloader_randomness(rng_seed, l);
1201-
1202-
/* try to clear seed so it won't be found. */
1203-
fdt_nop_property(initial_boot_params, node, "rng-seed");
1204-
1205-
/* update CRC check value */
1206-
of_fdt_crc32 = crc32_be(~0, initial_boot_params,
1207-
fdt_totalsize(initial_boot_params));
1208-
}
1209-
12101212
return 0;
12111213
}
12121214

0 commit comments

Comments
 (0)