kernel: update kernel 4.9 to 4.9.34
[openwrt/staging/wigyori.git] / target / linux / lantiq / patches-4.9 / 0101-find_active_root.patch
1 --- a/drivers/mtd/ofpart.c
2 +++ b/drivers/mtd/ofpart.c
3 @@ -25,6 +25,38 @@ static bool node_has_compatible(struct d
4 return of_get_property(pp, "compatible", NULL);
5 }
6
7 +static uint8_t * brnboot_get_selected_root_part(struct mtd_info *master,
8 + loff_t offset)
9 +{
10 + static uint8_t root_id;
11 + int err, len;
12 +
13 + err = mtd_read(master, offset, 0x01, &len, &root_id);
14 +
15 + if (mtd_is_bitflip(err) || !err)
16 + return &root_id;
17 +
18 + return NULL;
19 +}
20 +
21 +static void brnboot_set_active_root_part(struct mtd_partition *pparts,
22 + struct device_node **part_nodes,
23 + int nr_parts,
24 + uint8_t *root_id)
25 +{
26 + int i;
27 +
28 + for (i = 0; i < nr_parts; i++) {
29 + int part_root_id;
30 +
31 + if (!of_property_read_u32(part_nodes[i], "brnboot,root-id", &part_root_id)
32 + && part_root_id == *root_id) {
33 + pparts[i].name = "firmware";
34 + break;
35 + }
36 + }
37 +}
38 +
39 static int parse_ofpart_partitions(struct mtd_info *master,
40 const struct mtd_partition **pparts,
41 struct mtd_part_parser_data *data)
42 @@ -36,7 +68,8 @@ static int parse_ofpart_partitions(struc
43 struct device_node *pp;
44 int nr_parts, i, ret = 0;
45 bool dedicated = true;
46 -
47 + uint8_t *proot_id = NULL;
48 + struct device_node **part_nodes;
49
50 /* Pull of_node from the master device node */
51 mtd_node = mtd_get_of_node(master);
52 @@ -72,7 +105,9 @@ static int parse_ofpart_partitions(struc
53 return 0;
54
55 parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
56 - if (!parts)
57 + part_nodes = kzalloc(nr_parts * sizeof(*part_nodes), GFP_KERNEL);
58 +
59 + if (!parts || !part_nodes)
60 return -ENOMEM;
61
62 i = 0;
63 @@ -121,12 +156,22 @@ static int parse_ofpart_partitions(struc
64 if (of_get_property(pp, "lock", &len))
65 parts[i].mask_flags |= MTD_POWERUP_LOCK;
66
67 + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
68 + proot_id = brnboot_get_selected_root_part(master, parts[i].offset);
69 +
70 + part_nodes[i] = pp;
71 +
72 i++;
73 }
74
75 if (!nr_parts)
76 goto ofpart_none;
77
78 + if (proot_id)
79 + brnboot_set_active_root_part(parts, part_nodes, nr_parts, proot_id);
80 +
81 + kfree(part_nodes);
82 +
83 *pparts = parts;
84 return nr_parts;
85
86 @@ -137,6 +182,7 @@ ofpart_fail:
87 ofpart_none:
88 of_node_put(pp);
89 kfree(parts);
90 + kfree(part_nodes);
91 return ret;
92 }
93