ramips: Add support for Mikrotik RouterBOARD RBM33g
[oweals/openwrt.git] / target / linux / brcm63xx / patches-4.9 / 120-mtd-add-of_match_table-parsing-for-partition-parsers.patch
1 From 53980645bb12bd8723ac226805ee171780b24196 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Mon, 26 Jun 2017 13:37:11 +0200
4 Subject: [PATCH 1/4] mtd: add of_match_table parsing for partition parsers
5
6 Allow partition parsers to be matched by attaching compatible strings to
7 partitions.
8
9 This allows specifying the expected format of flash partitions for
10 matching partition parsers.
11
12 Example:
13
14 flash@foo {
15         ...
16         partitions {
17                 compatible = "fixed-partitions";
18
19                 cfe@0 {
20                         reg = <0x0 0x10000>;
21                         label = "cfe";
22                         read-only;
23                 };
24
25                 firmware@10000 {
26                         reg = <0x10000 0x3e0000>;
27                         label = "firmware";
28                         compatible = "brcm,bcm63xx-imagetag";
29                 };
30
31                 nvram@3f0000 {
32                         reg = <0x3e0000 0x10000>;
33                         label = "nvram";
34                 };
35         };
36 };
37
38 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
39 ---
40  drivers/mtd/mtdpart.c | 12 ++++++++----
41  1 file changed, 8 insertions(+), 4 deletions(-)
42
43 --- a/drivers/mtd/mtdpart.c
44 +++ b/drivers/mtd/mtdpart.c
45 @@ -940,8 +940,7 @@ int add_mtd_partitions(struct mtd_info *
46                 add_mtd_device(&slave->mtd);
47                 mtd_partition_split(master, slave);
48                 mtd_add_partition_attrs(slave);
49 -               if (parts[i].types)
50 -                       mtd_parse_part(slave, parts[i].types);
51 +               mtd_parse_part(slave, parts[i].types);
52  
53                 cur_offset = slave->offset + slave->mtd.size;
54         }
55 @@ -1123,7 +1122,9 @@ static int mtd_part_of_parse(struct mtd_
56         const char *fixed = "fixed-partitions";
57         int ret, err = 0;
58  
59 -       np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
60 +       np = mtd_get_of_node(master);
61 +       if (!mtd_is_partition(master))
62 +               np = of_get_child_by_name(np, "partitions");
63         of_property_for_each_string(np, "compatible", prop, compat) {
64                 parser = mtd_part_get_compatible_parser(compat);
65                 if (!parser)
66 @@ -1192,8 +1193,12 @@ int parse_mtd_partitions(struct mtd_info
67                         types = types_of;
68         }
69  
70 -       if (!types)
71 +       if (!types) {
72 +               if (mtd_is_partition(master))
73 +                       return -ENOENT;
74 +
75                 types = default_mtd_part_types;
76 +       }
77  
78         for ( ; *types; types++) {
79                 /*