kernel: update kernel 3.18 to version 3.18.23
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-3.18 / 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 @@ -642,6 +642,37 @@ 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, &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->master,
27 + parts[i].name,
28 + parts[i].offset,
29 + parts[i].size,
30 + false);
31 + }
32 +
33 + kfree(parts);
34 +
35 + return nr_parts;
36 +}
37 +
38 #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
39 #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
40 #else
41 @@ -650,6 +681,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
42
43 static void split_firmware(struct mtd_info *master, struct mtd_part *part)
44 {
45 + run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
46 }
47
48 void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
49 @@ -664,6 +696,12 @@ static void mtd_partition_split(struct m
50 if (rootfs_found)
51 return;
52
53 + if (!strcmp(part->mtd.name, "rootfs")) {
54 + run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
55 +
56 + rootfs_found = 1;
57 + }
58 +
59 if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
60 config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
61 split_firmware(master, part);
62 --- a/include/linux/mtd/partitions.h
63 +++ b/include/linux/mtd/partitions.h
64 @@ -70,6 +70,8 @@ struct mtd_part_parser_data {
65
66 enum mtd_parser_type {
67 MTD_PARSER_TYPE_DEVICE = 0,
68 + MTD_PARSER_TYPE_ROOTFS,
69 + MTD_PARSER_TYPE_FIRMWARE,
70 };
71
72 struct mtd_part_parser {