71a97a00f441cef80207dc2234f0b4d7712eeea7
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 401-mtd-add-support-for-different-partition-parser-types.patch
1 From 02cff0ccaa6d364f5c1eeea83f47ac80ccc967d4 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Tue, 3 Sep 2013 18:11:50 +0200
4 Subject: [PATCH] mtd: add support for different partition parser types
5
6 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
7 ---
8 drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
9 include/linux/mtd/partitions.h | 11 ++++++++
10 2 files changed, 67 insertions(+)
11
12 --- a/drivers/mtd/mtdpart.c
13 +++ b/drivers/mtd/mtdpart.c
14 @@ -996,6 +996,62 @@ void mtd_part_parser_cleanup(struct mtd_
15 }
16 }
17
18 +static struct mtd_part_parser *
19 +get_partition_parser_by_type(enum mtd_parser_type type,
20 + struct mtd_part_parser *start)
21 +{
22 + struct mtd_part_parser *p, *ret = NULL;
23 +
24 + spin_lock(&part_parser_lock);
25 +
26 + p = list_prepare_entry(start, &part_parsers, list);
27 + if (start)
28 + mtd_part_parser_put(start);
29 +
30 + list_for_each_entry_continue(p, &part_parsers, list) {
31 + if (p->type == type && try_module_get(p->owner)) {
32 + ret = p;
33 + break;
34 + }
35 + }
36 +
37 + spin_unlock(&part_parser_lock);
38 +
39 + return ret;
40 +}
41 +
42 +int parse_mtd_partitions_by_type(struct mtd_info *master,
43 + enum mtd_parser_type type,
44 + const struct mtd_partition **pparts,
45 + struct mtd_part_parser_data *data)
46 +{
47 + struct mtd_part_parser *prev = NULL;
48 + int ret = 0;
49 +
50 + while (1) {
51 + struct mtd_part_parser *parser;
52 +
53 + parser = get_partition_parser_by_type(type, prev);
54 + if (!parser)
55 + break;
56 +
57 + ret = (*parser->parse_fn)(master, pparts, data);
58 +
59 + if (ret > 0) {
60 + mtd_part_parser_put(parser);
61 + printk(KERN_NOTICE
62 + "%d %s partitions found on MTD device %s\n",
63 + ret, parser->name, master->name);
64 + break;
65 + }
66 +
67 + prev = parser;
68 + }
69 +
70 + return ret;
71 +}
72 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
73 +
74 int mtd_is_partition(const struct mtd_info *mtd)
75 {
76 struct mtd_part *part;
77 --- a/include/linux/mtd/partitions.h
78 +++ b/include/linux/mtd/partitions.h
79 @@ -61,11 +61,14 @@ struct mtd_part_parser_data {
80 unsigned long origin;
81 };
82
83 -
84 /*
85 * Functions dealing with the various ways of partitioning the space
86 */
87
88 +enum mtd_parser_type {
89 + MTD_PARSER_TYPE_DEVICE = 0,
90 +};
91 +
92 struct mtd_part_parser {
93 struct list_head list;
94 struct module *owner;
95 @@ -73,6 +76,7 @@ struct mtd_part_parser {
96 int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
97 struct mtd_part_parser_data *);
98 void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
99 + enum mtd_parser_type type;
100 };
101
102 /* Container for passing around a set of parsed partitions */
103 @@ -105,4 +109,9 @@ uint64_t mtd_get_device_size(const struc
104 extern void __weak arch_split_mtd_part(struct mtd_info *master,
105 const char *name, int offset, int size);
106
107 +int parse_mtd_partitions_by_type(struct mtd_info *master,
108 + enum mtd_parser_type type,
109 + const struct mtd_partition **pparts,
110 + struct mtd_part_parser_data *data);
111 +
112 #endif