kernel: tolerate using UBI/UBIFS on MLC flash (FS#1830)
[oweals/openwrt.git] / target / linux / generic / pending-4.14 / 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 --- a/drivers/mtd/mtdpart.c
12 +++ b/drivers/mtd/mtdpart.c
13 @@ -741,6 +741,36 @@ int mtd_del_partition(struct mtd_info *m
14  }
15  EXPORT_SYMBOL_GPL(mtd_del_partition);
16  
17 +static int
18 +run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
19 +{
20 +       struct mtd_partition *parts;
21 +       int nr_parts;
22 +       int i;
23 +
24 +       nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
25 +                                               NULL);
26 +       if (nr_parts <= 0)
27 +               return nr_parts;
28 +
29 +       if (WARN_ON(!parts))
30 +               return 0;
31 +
32 +       for (i = 0; i < nr_parts; i++) {
33 +               /* adjust partition offsets */
34 +               parts[i].offset += slave->offset;
35 +
36 +               mtd_add_partition(slave->parent,
37 +                                 parts[i].name,
38 +                                 parts[i].offset,
39 +                                 parts[i].size);
40 +       }
41 +
42 +       kfree(parts);
43 +
44 +       return nr_parts;
45 +}
46 +
47  #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
48  #define SPLIT_FIRMWARE_NAME    CONFIG_MTD_SPLIT_FIRMWARE_NAME
49  #else
50 @@ -749,6 +779,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
51  
52  static void split_firmware(struct mtd_info *master, struct mtd_part *part)
53  {
54 +       run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
55  }
56  
57  void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
58 @@ -763,6 +794,12 @@ static void mtd_partition_split(struct m
59         if (rootfs_found)
60                 return;
61  
62 +       if (!strcmp(part->mtd.name, "rootfs")) {
63 +               run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
64 +
65 +               rootfs_found = 1;
66 +       }
67 +
68         if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
69             IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
70                 split_firmware(master, part);
71 --- a/include/linux/mtd/partitions.h
72 +++ b/include/linux/mtd/partitions.h
73 @@ -74,6 +74,8 @@ struct mtd_part_parser_data {
74  
75  enum mtd_parser_type {
76         MTD_PARSER_TYPE_DEVICE = 0,
77 +       MTD_PARSER_TYPE_ROOTFS,
78 +       MTD_PARSER_TYPE_FIRMWARE,
79  };
80  
81  struct mtd_part_parser {