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.
5 Rename both root= and rootfstype= variables to avoid issues and also
6 use the former to dynamically rename the active partition to "ubi".
9 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
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
17 +static void mangle_bootargs(void *fdt, const char *fdt_cmdline)
22 + rootdev = strstr(fdt_cmdline, "root=/dev/mtdblock");
23 + strncpy(rootdev, "uboot_active_root=", 18);
25 + rootfs = strstr(fdt_cmdline, "rootfstype");
26 + strncpy(rootfs, "origfstype", 10);
29 static void merge_fdt_bootargs(void *fdt, const char *fdt_cmdline)
31 char cmdline[COMMAND_LINE_SIZE];
32 @@ -135,6 +147,9 @@ int atags_to_fdt(void *atag_list, void *
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
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)
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
54 + * The result is not %NUL-terminated if the source exceeds
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.
61 +char *strncpy(char *dest, const char *src, size_t count)
66 + if ((*tmp = *src) != 0)
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
79 +char *strstr(const char *s1, const char *s2)
89 + if (!memcmp(s1, s2, l2))
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);
104 +static int uboot_active_root;
106 static int parse_ofpart_partitions(struct mtd_info *master,
107 struct mtd_partition **pparts,
108 struct mtd_part_parser_data *data)
110 struct device_node *node;
111 const char *partname;
112 + const char *owrtpart = "ubi";
113 struct device_node *pp;
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);
120 - partname = of_get_property(pp, "label", &len);
122 - partname = of_get_property(pp, "name", &len);
123 + if (uboot_active_root && (i == uboot_active_root)) {
124 + partname = owrtpart;
126 + partname = of_get_property(pp, "label", &len);
129 + partname = of_get_property(pp, "name", &len);
132 (*pparts)[i].name = partname;
134 if (of_get_property(pp, "read-only", &len))
135 @@ -178,6 +187,18 @@ static int __init ofpart_parser_init(voi
139 +static int __init active_root(char *str)
141 + get_option(&str, &uboot_active_root);
143 + if (!uboot_active_root)
149 +__setup("uboot_active_root=", active_root);
151 static void __exit ofpart_parser_exit(void)
153 deregister_mtd_parser(&ofpart_parser);