Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: fdt: Honor CONFIG_CMDLINE* even without /chosen node

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"

Move CONFIG_CMDLINE handling outside of early_init_dt_scan_chosen() so that
cases b and c above result in the same cmdline.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/11af73e05bad75e4ef49067515e3214f6d944b3d.camel@gmail.com
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Alexander Sverdlin and committed by
Rob Herring
a7d550f8 71a7507a

+20 -20
+20 -20
drivers/of/fdt.c
··· 1173 1173 if (p != NULL && l > 0) 1174 1174 strscpy(cmdline, p, min(l, COMMAND_LINE_SIZE)); 1175 1175 1176 - /* 1177 - * CONFIG_CMDLINE is meant to be a default in case nothing else 1178 - * managed to set the command line, unless CONFIG_CMDLINE_FORCE 1179 - * is set in which case we override whatever was found earlier. 1180 - */ 1181 - #ifdef CONFIG_CMDLINE 1182 - #if defined(CONFIG_CMDLINE_EXTEND) 1183 - strlcat(cmdline, " ", COMMAND_LINE_SIZE); 1184 - strlcat(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1185 - #elif defined(CONFIG_CMDLINE_FORCE) 1186 - strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1187 - #else 1188 - /* No arguments from boot loader, use kernel's cmdl*/ 1189 - if (!((char *)cmdline)[0]) 1190 - strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1191 - #endif 1192 - #endif /* CONFIG_CMDLINE */ 1193 - 1194 - pr_debug("Command line is: %s\n", (char *)cmdline); 1195 - 1196 1176 rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); 1197 1177 if (rng_seed && l > 0) { 1198 1178 add_bootloader_randomness(rng_seed, l); ··· 1276 1296 rc = early_init_dt_scan_chosen(boot_command_line); 1277 1297 if (rc) 1278 1298 pr_warn("No chosen node found, continuing without\n"); 1299 + 1300 + /* 1301 + * CONFIG_CMDLINE is meant to be a default in case nothing else 1302 + * managed to set the command line, unless CONFIG_CMDLINE_FORCE 1303 + * is set in which case we override whatever was found earlier. 1304 + */ 1305 + #ifdef CONFIG_CMDLINE 1306 + #if defined(CONFIG_CMDLINE_EXTEND) 1307 + strlcat(boot_command_line, " ", COMMAND_LINE_SIZE); 1308 + strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1309 + #elif defined(CONFIG_CMDLINE_FORCE) 1310 + strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1311 + #else 1312 + /* No arguments from boot loader, use kernel's cmdl */ 1313 + if (!boot_command_line[0]) 1314 + strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 1315 + #endif 1316 + #endif /* CONFIG_CMDLINE */ 1317 + 1318 + pr_debug("Command line is: %s\n", boot_command_line); 1279 1319 1280 1320 /* Setup memory, calling early_init_dt_add_memory_arch */ 1281 1321 early_init_dt_scan_memory();