1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: mtd: add support for different partition parser types
4 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
6 drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
7 include/linux/mtd/partitions.h | 11 ++++++++
8 2 files changed, 67 insertions(+)
10 --- a/drivers/mtd/mtdpart.c
11 +++ b/drivers/mtd/mtdpart.c
12 @@ -55,6 +55,10 @@ struct mtd_part {
15 static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
16 +static int parse_mtd_partitions_by_type(struct mtd_info *master,
17 + enum mtd_parser_type type,
18 + const struct mtd_partition **pparts,
19 + struct mtd_part_parser_data *data);
22 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
23 @@ -702,6 +706,36 @@ int mtd_del_partition(struct mtd_info *m
25 EXPORT_SYMBOL_GPL(mtd_del_partition);
28 +run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
30 + struct mtd_partition *parts;
34 + nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
39 + if (WARN_ON(!parts))
42 + for (i = 0; i < nr_parts; i++) {
43 + /* adjust partition offsets */
44 + parts[i].offset += slave->offset;
46 + mtd_add_partition(slave->parent,
57 #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
58 #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
60 @@ -1037,6 +1071,61 @@ void mtd_part_parser_cleanup(struct mtd_
64 +static struct mtd_part_parser *
65 +get_partition_parser_by_type(enum mtd_parser_type type,
66 + struct mtd_part_parser *start)
68 + struct mtd_part_parser *p, *ret = NULL;
70 + spin_lock(&part_parser_lock);
72 + p = list_prepare_entry(start, &part_parsers, list);
74 + mtd_part_parser_put(start);
76 + list_for_each_entry_continue(p, &part_parsers, list) {
77 + if (p->type == type && try_module_get(p->owner)) {
83 + spin_unlock(&part_parser_lock);
88 +static int parse_mtd_partitions_by_type(struct mtd_info *master,
89 + enum mtd_parser_type type,
90 + const struct mtd_partition **pparts,
91 + struct mtd_part_parser_data *data)
93 + struct mtd_part_parser *prev = NULL;
97 + struct mtd_part_parser *parser;
99 + parser = get_partition_parser_by_type(type, prev);
103 + ret = (*parser->parse_fn)(master, pparts, data);
106 + mtd_part_parser_put(parser);
108 + "%d %s partitions found on MTD device %s\n",
109 + ret, parser->name, master->name);
119 int mtd_is_partition(const struct mtd_info *mtd)
121 struct mtd_part *part;
122 --- a/include/linux/mtd/partitions.h
123 +++ b/include/linux/mtd/partitions.h
124 @@ -73,6 +73,10 @@ struct mtd_part_parser_data {
125 * Functions dealing with the various ways of partitioning the space
128 +enum mtd_parser_type {
129 + MTD_PARSER_TYPE_DEVICE = 0,
132 struct mtd_part_parser {
133 struct list_head list;
134 struct module *owner;
135 @@ -81,6 +85,7 @@ struct mtd_part_parser {
136 int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
137 struct mtd_part_parser_data *);
138 void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
139 + enum mtd_parser_type type;
142 /* Container for passing around a set of parsed partitions */