1 The old logic assumes CMDLINE_FROM_BOOTLOADER vs. CMDLINE_FORCE and
2 ignores CMDLINE_EXTEND. Here's the old logic:
4 - CONFIG_CMDLINE_FORCE=true
6 - dt bootargs=non-empty:
8 - dt bootargs=empty, @data is non-empty string
9 @data is left unchanged
10 - dt bootargs=empty, @data is empty string
11 CONFIG_CMDLINE (or "" if that's not defined)
13 The new logic is now documented in of_fdt.h and is copied here for
16 - CONFIG_CMDLINE_FORCE=true
18 - CONFIG_CMDLINE_EXTEND=true, @data is non-empty string
19 @data + dt bootargs (even if dt bootargs are empty)
20 - CONFIG_CMDLINE_EXTEND=true, @data is empty string
21 CONFIG_CMDLINE + dt bootargs (even if dt bootargs are empty)
22 - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=non-empty:
24 - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is non-empty string
25 @data is left unchanged
26 - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is empty string
27 CONFIG_CMDLINE (or "" if that's not defined)
29 Signed-off-by: Doug Anderson <diand...@chromium.org>
30 CC: devicetree-discuss@lists.ozlabs.org
31 CC: Grant Likely <grant.lik...@secretlab.ca>
32 CC: Benjamin Herrenschmidt <b...@kernel.crashing.org>
33 CC: Rob Herring <rob.herr...@calxeda.com>
36 --- a/drivers/of/fdt.c
37 +++ b/drivers/of/fdt.c
38 @@ -663,6 +663,29 @@ int __init early_init_dt_scan_memory(uns
43 + * Convert configs to something easy to use in C code
45 +#if defined(CONFIG_CMDLINE_FORCE)
46 +static const int overwrite_incoming_cmdline = 1;
47 +static const int read_dt_cmdline;
48 +static const int concat_cmdline;
49 +#elif defined(CONFIG_CMDLINE_EXTEND)
50 +static const int overwrite_incoming_cmdline;
51 +static const int read_dt_cmdline = 1;
52 +static const int concat_cmdline = 1;
53 +#else /* CMDLINE_FROM_BOOTLOADER */
54 +static const int overwrite_incoming_cmdline;
55 +static const int read_dt_cmdline = 1;
56 +static const int concat_cmdline;
59 +#ifdef CONFIG_CMDLINE
60 +static const char *config_cmdline = CONFIG_CMDLINE;
62 +static const char *config_cmdline = "";
65 int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
66 int depth, void *data)
68 @@ -677,22 +700,26 @@ int __init early_init_dt_scan_chosen(uns
70 early_init_dt_check_for_initrd(node);
72 - /* Retrieve command line */
73 - p = of_get_flat_dt_prop(node, "bootargs", &l);
74 - if (p != NULL && l > 0)
75 - strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
78 - * CONFIG_CMDLINE is meant to be a default in case nothing else
79 - * managed to set the command line, unless CONFIG_CMDLINE_FORCE
80 - * is set in which case we override whatever was found earlier.
82 -#ifdef CONFIG_CMDLINE
83 -#ifndef CONFIG_CMDLINE_FORCE
84 - if (!((char *)data)[0])
86 - strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
87 -#endif /* CONFIG_CMDLINE */
88 + /* Put CONFIG_CMDLINE in if forced or if data had nothing in it to start */
89 + if (overwrite_incoming_cmdline || !((char *)data)[0])
90 + strlcpy(data, config_cmdline, COMMAND_LINE_SIZE);
92 + /* Retrieve command line unless forcing */
93 + if (read_dt_cmdline) {
94 + p = of_get_flat_dt_prop(node, "bootargs", &l);
95 + if (p != NULL && l > 0) {
96 + if (concat_cmdline) {
97 + strlcat(data, " ", COMMAND_LINE_SIZE);
98 + strlcat(data, p, min_t(int, (int)l,
99 + COMMAND_LINE_SIZE));
101 + strlcpy(data, p, min_t(int, (int)l,
102 + COMMAND_LINE_SIZE));
106 + pr_debug("Command line is: %s\n", (char*)data);
109 pr_debug("Command line is: %s\n", (char*)data);
111 --- a/include/linux/of_fdt.h
112 +++ b/include/linux/of_fdt.h
113 @@ -91,6 +91,27 @@ extern int of_flat_dt_is_compatible(unsi
114 extern int of_flat_dt_match(unsigned long node, const char *const *matches);
115 extern unsigned long of_get_flat_dt_root(void);
118 + * early_init_dt_scan_chosen - scan the device tree for ramdisk and bootargs
120 + * The boot arguments will be placed into the memory pointed to by @data.
121 + * That memory should be COMMAND_LINE_SIZE big and initialized to be a valid
122 + * (possibly empty) string. Logic for what will be in @data after this
123 + * function finishes:
125 + * - CONFIG_CMDLINE_FORCE=true
127 + * - CONFIG_CMDLINE_EXTEND=true, @data is non-empty string
128 + * @data + dt bootargs (even if dt bootargs are empty)
129 + * - CONFIG_CMDLINE_EXTEND=true, @data is empty string
130 + * CONFIG_CMDLINE + dt bootargs (even if dt bootargs are empty)
131 + * - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=non-empty:
133 + * - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is non-empty string
134 + * @data is left unchanged
135 + * - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is empty string
136 + * CONFIG_CMDLINE (or "" if that's not defined)
138 extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
139 int depth, void *data);
140 extern void early_init_dt_check_for_initrd(unsigned long node);