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 @@ -1113,6 +1113,62 @@ void mtd_part_parser_cleanup(struct mtd_
16 +static struct mtd_part_parser *
17 +get_partition_parser_by_type(enum mtd_parser_type type,
18 + struct mtd_part_parser *start)
20 + struct mtd_part_parser *p, *ret = NULL;
22 + spin_lock(&part_parser_lock);
24 + p = list_prepare_entry(start, &part_parsers, list);
26 + mtd_part_parser_put(start);
28 + list_for_each_entry_continue(p, &part_parsers, list) {
29 + if (p->type == type && try_module_get(p->owner)) {
35 + spin_unlock(&part_parser_lock);
40 +int parse_mtd_partitions_by_type(struct mtd_info *master,
41 + enum mtd_parser_type type,
42 + const struct mtd_partition **pparts,
43 + struct mtd_part_parser_data *data)
45 + struct mtd_part_parser *prev = NULL;
49 + struct mtd_part_parser *parser;
51 + parser = get_partition_parser_by_type(type, prev);
55 + ret = (*parser->parse_fn)(master, pparts, data);
58 + mtd_part_parser_put(parser);
60 + "%d %s partitions found on MTD device %s\n",
61 + ret, parser->name, master->name);
70 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
72 int mtd_is_partition(const struct mtd_info *mtd)
74 struct mtd_part *part;
75 --- a/include/linux/mtd/partitions.h
76 +++ b/include/linux/mtd/partitions.h
77 @@ -68,11 +68,14 @@ struct mtd_part_parser_data {
83 * Functions dealing with the various ways of partitioning the space
86 +enum mtd_parser_type {
87 + MTD_PARSER_TYPE_DEVICE = 0,
90 struct mtd_part_parser {
91 struct list_head list;
93 @@ -81,6 +84,7 @@ struct mtd_part_parser {
94 int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
95 struct mtd_part_parser_data *);
96 void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
97 + enum mtd_parser_type type;
100 /* Container for passing around a set of parsed partitions */
101 @@ -113,4 +117,9 @@ uint64_t mtd_get_device_size(const struc
102 extern void __weak arch_split_mtd_part(struct mtd_info *master,
103 const char *name, int offset, int size);
105 +int parse_mtd_partitions_by_type(struct mtd_info *master,
106 + enum mtd_parser_type type,
107 + const struct mtd_partition **pparts,
108 + struct mtd_part_parser_data *data);