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 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;
47 + uint8_t *proot_id = NULL;
48 + struct device_node **part_nodes;
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
55 parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
57 + part_nodes = kzalloc(nr_parts * sizeof(*part_nodes), GFP_KERNEL);
59 + if (!parts || !part_nodes)
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;
67 + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
68 + proot_id = brnboot_get_selected_root_part(master, parts[i].offset);
79 + brnboot_set_active_root_part(parts, part_nodes, nr_parts, proot_id);
86 @@ -137,6 +182,7 @@ ofpart_fail: