1 From 2c82524000cca691c89c9fda251b55ef04eabcb6 Mon Sep 17 00:00:00 2001
2 From: Mathias Kresin <openwrt@kresin.me>
3 Date: Mon, 2 May 2016 18:50:00 +0000
4 Subject: [PATCH] find active root
6 Signed-off-by: Mathias Kresin <openwrt@kresin.me>
8 drivers/mtd/parsers/ofpart_core.c | 49 ++++++++++++++++++++++++++++++-
9 1 file changed, 48 insertions(+), 1 deletion(-)
11 --- a/drivers/mtd/parsers/ofpart_core.c
12 +++ b/drivers/mtd/parsers/ofpart_core.c
13 @@ -38,6 +38,38 @@ static bool node_has_compatible(struct d
14 return of_get_property(pp, "compatible", NULL);
17 +static uint8_t * brnboot_get_selected_root_part(struct mtd_info *master,
20 + static uint8_t root_id;
23 + err = mtd_read(master, offset, 0x01, &len, &root_id);
25 + if (mtd_is_bitflip(err) || !err)
31 +static void brnboot_set_active_root_part(struct mtd_partition *pparts,
32 + struct device_node **part_nodes,
38 + for (i = 0; i < nr_parts; i++) {
41 + if (!of_property_read_u32(part_nodes[i], "brnboot,root-id", &part_root_id)
42 + && part_root_id == *root_id) {
43 + pparts[i].name = "firmware";
49 static int parse_fixed_partitions(struct mtd_info *master,
50 const struct mtd_partition **pparts,
51 struct mtd_part_parser_data *data)
52 @@ -51,6 +83,8 @@ static int parse_fixed_partitions(struct
53 struct device_node *pp;
54 int nr_parts, i, ret = 0;
55 bool dedicated = true;
56 + uint8_t *proot_id = NULL;
57 + struct device_node **part_nodes;
59 /* Pull of_node from the master device node */
60 mtd_node = mtd_get_of_node(master);
61 @@ -95,7 +129,9 @@ static int parse_fixed_partitions(struct
64 parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
66 + part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL);
68 + if (!parts || !part_nodes)
72 @@ -166,6 +202,11 @@ static int parse_fixed_partitions(struct
73 if (of_property_read_bool(pp, "slc-mode"))
74 parts[i].add_flags |= MTD_SLC_ON_MLC_EMULATION;
76 + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
77 + proot_id = brnboot_get_selected_root_part(master, parts[i].offset);
84 @@ -175,6 +216,11 @@ static int parse_fixed_partitions(struct
85 if (quirks && quirks->post_parse)
86 quirks->post_parse(master, parts, nr_parts);
89 + brnboot_set_active_root_part(parts, part_nodes, nr_parts, proot_id);
96 @@ -185,6 +231,7 @@ ofpart_fail: