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);
7 +static uint8_t * brnboot_get_selected_root_part(struct mtd_info *master,
10 + static uint8_t root_id;
13 + err = mtd_read(master, offset, 0x01, &len, &root_id);
15 + if (mtd_is_bitflip(err) || !err)
21 +static void brnboot_set_active_root_part(struct mtd_partition *pparts,
22 + struct device_node **part_nodes,
28 + for (i = 0; i < nr_parts; i++) {
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";
39 static int parse_ofpart_partitions(struct mtd_info *master,
40 struct mtd_partition **pparts,
41 struct mtd_part_parser_data *data)
42 @@ -35,7 +67,8 @@ static int parse_ofpart_partitions(struc
43 struct device_node *pp;
44 int nr_parts, i, ret = 0;
45 bool dedicated = true;
47 + uint8_t *proot_id = NULL;
48 + struct device_node **part_nodes;
52 @@ -73,7 +106,9 @@ static int parse_ofpart_partitions(struc
55 *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL);
57 + part_nodes = kzalloc(nr_parts * sizeof(*part_nodes), GFP_KERNEL);
59 + if (!*pparts || !part_nodes)
63 @@ -121,12 +156,22 @@ static int parse_ofpart_partitions(struc
64 if (of_get_property(pp, "lock", &len))
65 (*pparts)[i].mask_flags |= MTD_POWERUP_LOCK;
67 + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
68 + proot_id = brnboot_get_selected_root_part(master, (*pparts)[i].offset);
79 + brnboot_set_active_root_part(*pparts, part_nodes, nr_parts, proot_id);
86 @@ -136,6 +181,7 @@ ofpart_fail: