kernel: add missing patch
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 402-mtd-use-typed-mtd-parsers-for-rootfs-and-firmware-split.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: kernel/3.10: allow to use partition parsers for rootfs and firmware split
3
4 lede-commit: 3b71cd94bc9517bc25267dccb393b07d4b54564e
5 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
6 ---
7  drivers/mtd/mtdpart.c          | 37 +++++++++++++++++++++++++++++++++++++
8  include/linux/mtd/partitions.h |  2 ++
9  2 files changed, 39 insertions(+)
10
11 diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
12 index f20207e32075..28f76315dfa0 100644
13 --- a/drivers/mtd/mtdpart.c
14 +++ b/drivers/mtd/mtdpart.c
15 @@ -761,6 +761,36 @@ int mtd_del_partition(struct mtd_info *mtd, int partno)
16  }
17  EXPORT_SYMBOL_GPL(mtd_del_partition);
18  
19 +static int
20 +run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
21 +{
22 +       struct mtd_partition *parts;
23 +       int nr_parts;
24 +       int i;
25 +
26 +       nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
27 +                                               NULL);
28 +       if (nr_parts <= 0)
29 +               return nr_parts;
30 +
31 +       if (WARN_ON(!parts))
32 +               return 0;
33 +
34 +       for (i = 0; i < nr_parts; i++) {
35 +               /* adjust partition offsets */
36 +               parts[i].offset += slave->offset;
37 +
38 +               mtd_add_partition(slave->parent,
39 +                                 parts[i].name,
40 +                                 parts[i].offset,
41 +                                 parts[i].size);
42 +       }
43 +
44 +       kfree(parts);
45 +
46 +       return nr_parts;
47 +}
48 +
49  #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
50  #define SPLIT_FIRMWARE_NAME    CONFIG_MTD_SPLIT_FIRMWARE_NAME
51  #else
52 @@ -769,6 +799,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
53  
54  static void split_firmware(struct mtd_info *master, struct mtd_part *part)
55  {
56 +       run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
57  }
58  
59  void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
60 @@ -783,6 +814,12 @@ static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
61         if (rootfs_found)
62                 return;
63  
64 +       if (!strcmp(part->mtd.name, "rootfs")) {
65 +               run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
66 +
67 +               rootfs_found = 1;
68 +       }
69 +
70         if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
71             IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
72                 split_firmware(master, part);
73 diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
74 index baafd542432e..356e29815aa2 100644
75 --- a/include/linux/mtd/partitions.h
76 +++ b/include/linux/mtd/partitions.h
77 @@ -74,6 +74,8 @@ struct mtd_part_parser_data {
78  
79  enum mtd_parser_type {
80         MTD_PARSER_TYPE_DEVICE = 0,
81 +       MTD_PARSER_TYPE_ROOTFS,
82 +       MTD_PARSER_TYPE_FIRMWARE,
83  };
84  
85  struct mtd_part_parser {
86 -- 
87 2.11.0
88