[mcs814x] use the recommended ARM I/O accessors
[openwrt.git] / target / linux / mcs814x / patches-3.3 / 010-fdt_config_cmdline_extend.patch
1 The old logic assumes CMDLINE_FROM_BOOTLOADER vs. CMDLINE_FORCE and
2 ignores CMDLINE_EXTEND.  Here's the old logic:
3
4 - CONFIG_CMDLINE_FORCE=true
5     CONFIG_CMDLINE
6 - dt bootargs=non-empty:
7     dt bootargs
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)
12
13 The new logic is now documented in of_fdt.h and is copied here for
14 reference:
15
16 - CONFIG_CMDLINE_FORCE=true
17     CONFIG_CMDLINE
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:
23     dt bootargs
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)
28
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>
34 ---
35
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
39         return 0;
40  }
41  
42 +/*
43 + * Convert configs to something easy to use in C code
44 + */
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;
57 +#endif
58 +
59 +#ifdef CONFIG_CMDLINE
60 +static const char *config_cmdline = CONFIG_CMDLINE;
61 +#else
62 +static const char *config_cmdline = "";
63 +#endif
64 +
65  int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
66                                      int depth, void *data)
67  {
68 @@ -677,22 +700,26 @@ int __init early_init_dt_scan_chosen(uns
69  
70         early_init_dt_check_for_initrd(node);
71  
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));
76 -
77 -       /*
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.
81 -        */
82 -#ifdef CONFIG_CMDLINE
83 -#ifndef CONFIG_CMDLINE_FORCE
84 -       if (!((char *)data)[0])
85 -#endif
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);
91 +
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));
100 +                       } else
101 +                               strlcpy(data, p, min_t(int, (int)l,
102 +                                               COMMAND_LINE_SIZE));
103 +               }
104 +       }
105
106 +        pr_debug("Command line is: %s\n", (char*)data);
107
108  
109         pr_debug("Command line is: %s\n", (char*)data);
110  
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);
116  
117 +/*
118 + * early_init_dt_scan_chosen - scan the device tree for ramdisk and bootargs
119 + *
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:
124 + *
125 + * - CONFIG_CMDLINE_FORCE=true
126 + *     CONFIG_CMDLINE
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:
132 + *     dt bootargs
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)
137 + */
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);