kernel/3.1[02]: move MTD root device setup code to mtdcore
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.10 / 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 @@ -626,6 +626,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 static inline unsigned long
39 mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
40 {
41 @@ -685,6 +716,10 @@ static void split_rootfs_data(struct mtd
42 unsigned int split_size;
43 int ret;
44
45 + ret = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
46 + if (ret > 0)
47 + return;
48 +
49 ret = split_squashfs(master, part->offset, &split_offset);
50 if (ret)
51 return;
52 @@ -734,6 +769,12 @@ static void split_uimage(struct mtd_info
53
54 static void split_firmware(struct mtd_info *master, struct mtd_part *part)
55 {
56 + int ret;
57 +
58 + ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
59 + if (ret > 0)
60 + return;
61 +
62 if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
63 split_uimage(master, part);
64 }
65 --- a/include/linux/mtd/partitions.h
66 +++ b/include/linux/mtd/partitions.h
67 @@ -70,6 +70,8 @@ struct mtd_part_parser_data {
68
69 enum mtd_parser_type {
70 MTD_PARSER_TYPE_DEVICE = 0,
71 + MTD_PARSER_TYPE_ROOTFS,
72 + MTD_PARSER_TYPE_FIRMWARE,
73 };
74
75 struct mtd_part_parser {