02fb9cce3e7b0bfb22aec79b708943d9ac2f4813
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 402-mtd-use-typed-mtd-parsers-for-rootfs-and-firmware-split.patch
1 --- a/drivers/mtd/mtdpart.c
2 +++ b/drivers/mtd/mtdpart.c
3 @@ -723,6 +723,36 @@ int mtd_del_partition(struct mtd_info *m
4 }
5 EXPORT_SYMBOL_GPL(mtd_del_partition);
6
7 +static int
8 +run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
9 +{
10 + struct mtd_partition *parts;
11 + int nr_parts;
12 + int i;
13 +
14 + nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
15 + NULL);
16 + if (nr_parts <= 0)
17 + return nr_parts;
18 +
19 + if (WARN_ON(!parts))
20 + return 0;
21 +
22 + for (i = 0; i < nr_parts; i++) {
23 + /* adjust partition offsets */
24 + parts[i].offset += slave->offset;
25 +
26 + mtd_add_partition(slave->parent,
27 + parts[i].name,
28 + parts[i].offset,
29 + parts[i].size);
30 + }
31 +
32 + kfree(parts);
33 +
34 + return nr_parts;
35 +}
36 +
37 #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
38 #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
39 #else
40 @@ -731,6 +761,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
41
42 static void split_firmware(struct mtd_info *master, struct mtd_part *part)
43 {
44 + run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
45 }
46
47 void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
48 @@ -745,6 +776,12 @@ static void mtd_partition_split(struct m
49 if (rootfs_found)
50 return;
51
52 + if (!strcmp(part->mtd.name, "rootfs")) {
53 + run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
54 +
55 + rootfs_found = 1;
56 + }
57 +
58 if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
59 IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
60 split_firmware(master, part);
61 --- a/include/linux/mtd/partitions.h
62 +++ b/include/linux/mtd/partitions.h
63 @@ -67,6 +67,8 @@ struct mtd_part_parser_data {
64
65 enum mtd_parser_type {
66 MTD_PARSER_TYPE_DEVICE = 0,
67 + MTD_PARSER_TYPE_ROOTFS,
68 + MTD_PARSER_TYPE_FIRMWARE,
69 };
70
71 struct mtd_part_parser {