ipq40xx: fix invalid GPIO numbers since kernel 6.6
[openwrt/staging/xback.git] / target / linux / lantiq / patches-6.1 / 0101-find_active_root.patch
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
5
6 Signed-off-by: Mathias Kresin <openwrt@kresin.me>
7 ---
8 drivers/mtd/parsers/ofpart_core.c | 49 ++++++++++++++++++++++++++++++-
9 1 file changed, 48 insertions(+), 1 deletion(-)
10
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);
15 }
16
17 +static uint8_t * brnboot_get_selected_root_part(struct mtd_info *master,
18 + loff_t offset)
19 +{
20 + static uint8_t root_id;
21 + int err, len;
22 +
23 + err = mtd_read(master, offset, 0x01, &len, &root_id);
24 +
25 + if (mtd_is_bitflip(err) || !err)
26 + return &root_id;
27 +
28 + return NULL;
29 +}
30 +
31 +static void brnboot_set_active_root_part(struct mtd_partition *pparts,
32 + struct device_node **part_nodes,
33 + int nr_parts,
34 + uint8_t *root_id)
35 +{
36 + int i;
37 +
38 + for (i = 0; i < nr_parts; i++) {
39 + int part_root_id;
40 +
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";
44 + break;
45 + }
46 + }
47 +}
48 +
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;
58
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
62 return 0;
63
64 parts = kcalloc(nr_parts, sizeof(*parts), GFP_KERNEL);
65 - if (!parts)
66 + part_nodes = kcalloc(nr_parts, sizeof(*part_nodes), GFP_KERNEL);
67 +
68 + if (!parts || !part_nodes)
69 return -ENOMEM;
70
71 i = 0;
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;
75
76 + if (!proot_id && of_device_is_compatible(pp, "brnboot,root-selector"))
77 + proot_id = brnboot_get_selected_root_part(master, parts[i].offset);
78 +
79 + part_nodes[i] = pp;
80 +
81 i++;
82 }
83
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);
87
88 + if (proot_id)
89 + brnboot_set_active_root_part(parts, part_nodes, nr_parts, proot_id);
90 +
91 + kfree(part_nodes);
92 +
93 *pparts = parts;
94 return nr_parts;
95
96 @@ -185,6 +231,7 @@ ofpart_fail:
97 ofpart_none:
98 of_node_put(pp);
99 kfree(parts);
100 + kfree(part_nodes);
101 return ret;
102 }
103