68826fc4e1c2c2ea5fc38fd21a9edfe17a5bf74a
[openwrt/openwrt.git] / target / linux / mvebu / patches-4.0 / 100-find_active_root.patch
1 The WRT1900AC among other Linksys routers uses a dual-firmware layout.
2 The bootloader passes the active rootfs in bootargs and also sets the
3 rootfstype to jffs2 - which is clearly something we don't want.
4
5 Rename both root= and rootfstype= variables to avoid issues and also
6 use the former to dynamically rename the active partition to "ubi".
7
8
9 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
10
11 --- a/arch/arm/boot/compressed/atags_to_fdt.c
12 +++ b/arch/arm/boot/compressed/atags_to_fdt.c
13 @@ -66,6 +66,18 @@ static uint32_t get_cell_size(const void
14 return cell_size;
15 }
16
17 +static void mangle_bootargs(void *fdt, const char *fdt_cmdline)
18 +{
19 + char *rootdev;
20 + char *rootfs;
21 +
22 + rootdev = strstr(fdt_cmdline, "root=/dev/mtdblock");
23 + strncpy(rootdev, "uboot_active_root=", 18);
24 +
25 + rootfs = strstr(fdt_cmdline, "rootfstype");
26 + strncpy(rootfs, "origfstype", 10);
27 +}
28 +
29 static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline)
30 {
31 char cmdline[COMMAND_LINE_SIZE];
32 @@ -135,6 +147,9 @@ int atags_to_fdt(void *atag_list, void *
33
34 for_each_tag(atag, atag_list) {
35 if (atag->hdr.tag == ATAG_CMDLINE) {
36 + /* Rename the original root= and rootfstype= options */
37 + mangle_bootargs(fdt,
38 + atag->u.cmdline.cmdline);
39 /* Append the ATAGS command line to the device tree
40 * command line.
41 * NB: This means that if the same parameter is set in
42 --- a/arch/arm/boot/compressed/string.c
43 +++ b/arch/arm/boot/compressed/string.c
44 @@ -111,6 +111,53 @@ char *strchr(const char *s, int c)
45 return (char *)s;
46 }
47
48 +/**
49 + * strncpy - Copy a length-limited, %NUL-terminated string
50 + * @dest: Where to copy the string to
51 + * @src: Where to copy the string from
52 + * @count: The maximum number of bytes to copy
53 + *
54 + * The result is not %NUL-terminated if the source exceeds
55 + * @count bytes.
56 + *
57 + * In the case where the length of @src is less than that of
58 + * count, the remainder of @dest will be padded with %NUL.
59 + *
60 + */
61 +char *strncpy(char *dest, const char *src, size_t count)
62 +{
63 + char *tmp = dest;
64 +
65 + while (count) {
66 + if ((*tmp = *src) != 0)
67 + src++;
68 + tmp++;
69 + count--;
70 + }
71 + return dest;
72 +}
73 +
74 +/**
75 + * strstr - Find the first substring in a %NUL terminated string
76 + * @s1: The string to be searched
77 + * @s2: The string to search for
78 + */
79 +char *strstr(const char *s1, const char *s2)
80 +{
81 + size_t l1, l2;
82 +
83 + l2 = strlen(s2);
84 + if (!l2)
85 + return (char *)s1;
86 + l1 = strlen(s1);
87 + while (l1 >= l2) {
88 + l1--;
89 + if (!memcmp(s1, s2, l2))
90 + return (char *)s1;
91 + s1++;
92 + }
93 + return NULL;
94 +}
95 #undef memset
96
97 void *memset(void *s, int c, size_t count)
98 --- a/drivers/mtd/ofpart.c
99 +++ b/drivers/mtd/ofpart.c
100 @@ -25,12 +25,15 @@ static bool node_has_compatible(struct d
101 return of_get_property(pp, "compatible", NULL);
102 }
103
104 +static int uboot_active_root;
105 +
106 static int parse_ofpart_partitions(struct mtd_info *master,
107 struct mtd_partition **pparts,
108 struct mtd_part_parser_data *data)
109 {
110 struct device_node *node;
111 const char *partname;
112 + const char *owrtpart = "ubi";
113 struct device_node *pp;
114 int nr_parts, i;
115
116 @@ -78,9 +81,15 @@ static int parse_ofpart_partitions(struc
117 (*pparts)[i].offset = of_read_number(reg, a_cells);
118 (*pparts)[i].size = of_read_number(reg + a_cells, s_cells);
119
120 - partname = of_get_property(pp, "label", &len);
121 - if (!partname)
122 - partname = of_get_property(pp, "name", &len);
123 + if (uboot_active_root && (i == uboot_active_root)) {
124 + partname = owrtpart;
125 + } else {
126 + partname = of_get_property(pp, "label", &len);
127 +
128 + if (!partname)
129 + partname = of_get_property(pp, "name", &len);
130 + }
131 +
132 (*pparts)[i].name = partname;
133
134 if (of_get_property(pp, "read-only", &len))
135 @@ -178,6 +187,18 @@ static int __init ofpart_parser_init(voi
136 return 0;
137 }
138
139 +static int __init active_root(char *str)
140 +{
141 + get_option(&str, &uboot_active_root);
142 +
143 + if (!uboot_active_root)
144 + return 1;
145 +
146 + return 1;
147 +}
148 +
149 +__setup("uboot_active_root=", active_root);
150 +
151 static void __exit ofpart_parser_exit(void)
152 {
153 deregister_mtd_parser(&ofpart_parser);