0c335683ca3dfab06f9c7207c5beb4238fd99703
[librecmc/librecmc-fossil.git] /
1 --- a/drivers/mtd/mtdpart.c
2 +++ b/drivers/mtd/mtdpart.c
3 @@ -641,6 +641,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 @@ -686,6 +717,12 @@ static void split_uimage(struct mtd_info
42  
43  static void split_firmware(struct mtd_info *master, struct mtd_part *part)
44  {
45 +       int ret;
46 +
47 +       ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
48 +       if (ret > 0)
49 +               return;
50 +
51         if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
52                 split_uimage(master, part);
53  }
54 @@ -702,6 +739,12 @@ static void mtd_partition_split(struct m
55         if (rootfs_found)
56                 return;
57  
58 +       if (!strcmp(part->mtd.name, "rootfs")) {
59 +               run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
60 +
61 +               rootfs_found = 1;
62 +       }
63 +
64         if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
65             config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
66                 split_firmware(master, part);
67 --- a/include/linux/mtd/partitions.h
68 +++ b/include/linux/mtd/partitions.h
69 @@ -70,6 +70,8 @@ struct mtd_part_parser_data {
70  
71  enum mtd_parser_type {
72         MTD_PARSER_TYPE_DEVICE = 0,
73 +       MTD_PARSER_TYPE_ROOTFS,
74 +       MTD_PARSER_TYPE_FIRMWARE,
75  };
76  
77  struct mtd_part_parser {