1 Index: linux-3.14.27/drivers/mtd/mtdpart.c
2 ===================================================================
3 --- linux-3.14.27.orig/drivers/mtd/mtdpart.c
4 +++ linux-3.14.27/drivers/mtd/mtdpart.c
6 #include <linux/kmod.h>
7 #include <linux/mtd/mtd.h>
8 #include <linux/mtd/partitions.h>
9 -#include <linux/magic.h>
10 #include <linux/err.h>
13 -#include "mtdsplit/mtdsplit.h"
15 #define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
17 @@ -49,14 +47,13 @@ struct mtd_part {
18 struct list_head list;
21 -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
24 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
25 * the pointer to that structure with this macro.
27 #define PART(x) ((struct mtd_part *)(x))
31 * MTD methods which simply translate the effective address and pass through
32 * to the _real_ device.
33 @@ -509,12 +506,14 @@ static struct mtd_part *allocate_partiti
34 if (slave->offset == MTDPART_OFS_APPEND)
35 slave->offset = cur_offset;
36 if (slave->offset == MTDPART_OFS_NXTBLK) {
37 - /* Round up to next erasesize */
38 - slave->offset = mtd_roundup_to_eb(cur_offset, master);
39 - if (slave->offset != cur_offset)
40 + slave->offset = cur_offset;
41 + if (mtd_mod_by_eb(cur_offset, master) != 0) {
42 + /* Round up to next erasesize */
43 + slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
44 printk(KERN_NOTICE "Moving partition %d: "
45 "0x%012llx -> 0x%012llx\n", partno,
46 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
49 if (slave->offset == MTDPART_OFS_RETAIN) {
50 slave->offset = cur_offset;
51 @@ -616,10 +615,8 @@ out_register:
57 -__mtd_add_partition(struct mtd_info *master, const char *name,
58 - long long offset, long long length, bool dup_check)
59 +int mtd_add_partition(struct mtd_info *master, const char *name,
60 + long long offset, long long length)
62 struct mtd_partition part;
63 struct mtd_part *p, *new;
64 @@ -651,24 +648,21 @@ __mtd_add_partition(struct mtd_info *mas
65 end = offset + length;
67 mutex_lock(&mtd_partitions_mutex);
69 - list_for_each_entry(p, &mtd_partitions, list)
70 - if (p->master == master) {
71 - if ((start >= p->offset) &&
72 - (start < (p->offset + p->mtd.size)))
75 - if ((end >= p->offset) &&
76 - (end < (p->offset + p->mtd.size)))
80 + list_for_each_entry(p, &mtd_partitions, list)
81 + if (p->master == master) {
82 + if ((start >= p->offset) &&
83 + (start < (p->offset + p->mtd.size)))
86 + if ((end >= p->offset) &&
87 + (end < (p->offset + p->mtd.size)))
91 list_add(&new->list, &mtd_partitions);
92 mutex_unlock(&mtd_partitions_mutex);
94 add_mtd_device(&new->mtd);
95 - mtd_partition_split(master, new);
99 @@ -678,12 +672,6 @@ err_inv:
101 EXPORT_SYMBOL_GPL(mtd_add_partition);
103 -int mtd_add_partition(struct mtd_info *master, const char *name,
104 - long long offset, long long length)
106 - return __mtd_add_partition(master, name, offset, length, true);
109 int mtd_del_partition(struct mtd_info *master, int partno)
111 struct mtd_part *slave, *next;
112 @@ -707,166 +695,6 @@ int mtd_del_partition(struct mtd_info *m
114 EXPORT_SYMBOL_GPL(mtd_del_partition);
117 -run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
119 - struct mtd_partition *parts;
123 - nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, &parts,
128 - if (WARN_ON(!parts))
131 - for (i = 0; i < nr_parts; i++) {
132 - /* adjust partition offsets */
133 - parts[i].offset += slave->offset;
135 - __mtd_add_partition(slave->master,
147 -static inline unsigned long
148 -mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
150 - unsigned long mask = mtd->erasesize - 1;
152 - len += offset & mask;
153 - len = (len + mask) & ~mask;
154 - len -= offset & mask;
158 -static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
160 - size_t squashfs_len;
163 - ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
167 - len = mtd_pad_erasesize(master, offset, squashfs_len);
168 - *split_offset = offset + len;
173 -static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
175 - unsigned int split_offset = 0;
176 - unsigned int split_size;
179 - ret = split_squashfs(master, part->offset, &split_offset);
183 - if (split_offset <= 0)
186 - if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
187 - pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
189 - pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
191 - split_size = part->mtd.size - (split_offset - part->offset);
192 - printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
193 - ROOTFS_SPLIT_NAME, split_offset, split_size);
195 - __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
196 - split_size, false);
199 -#define UBOOT_MAGIC 0x27051956
201 -static void split_uimage(struct mtd_info *master, struct mtd_part *part)
210 - if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
213 - if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
216 - len = be32_to_cpu(hdr.size) + 0x40;
217 - len = mtd_pad_erasesize(master, part->offset, len);
218 - if (len + master->erasesize > part->mtd.size)
221 - if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
222 - pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
224 - pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
226 - __mtd_add_partition(master, "rootfs", part->offset + len,
227 - part->mtd.size - len, false);
230 -#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
231 -#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
233 -#define SPLIT_FIRMWARE_NAME "unused"
236 -static void split_firmware(struct mtd_info *master, struct mtd_part *part)
240 - ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
244 - if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
245 - split_uimage(master, part);
248 -void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
249 - int offset, int size)
253 -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
255 - static int rootfs_found = 0;
260 - if (!strcmp(part->mtd.name, "rootfs")) {
261 - int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
263 - if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
264 - split_rootfs_data(master, part);
269 - if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
270 - config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
271 - split_firmware(master, part);
273 - arch_split_mtd_part(master, part->mtd.name, part->offset,
277 * This function, given a master MTD object and a partition table, creates
278 * and registers slave MTD objects which are bound to the master according to
279 @@ -896,7 +724,6 @@ int add_mtd_partitions(struct mtd_info *
280 mutex_unlock(&mtd_partitions_mutex);
282 add_mtd_device(&slave->mtd);
283 - mtd_partition_split(master, slave);
285 cur_offset = slave->offset + slave->mtd.size;
287 @@ -926,30 +753,6 @@ static struct mtd_part_parser *get_parti
289 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
291 -static struct mtd_part_parser *
292 -get_partition_parser_by_type(enum mtd_parser_type type,
293 - struct mtd_part_parser *start)
295 - struct mtd_part_parser *p, *ret = NULL;
297 - spin_lock(&part_parser_lock);
299 - p = list_prepare_entry(start, &part_parsers, list);
301 - put_partition_parser(start);
303 - list_for_each_entry_continue(p, &part_parsers, list) {
304 - if (p->type == type && try_module_get(p->owner)) {
310 - spin_unlock(&part_parser_lock);
315 void register_mtd_parser(struct mtd_part_parser *p)
317 spin_lock(&part_parser_lock);
318 @@ -1023,38 +826,6 @@ int parse_mtd_partitions(struct mtd_info
322 -int parse_mtd_partitions_by_type(struct mtd_info *master,
323 - enum mtd_parser_type type,
324 - struct mtd_partition **pparts,
325 - struct mtd_part_parser_data *data)
327 - struct mtd_part_parser *prev = NULL;
331 - struct mtd_part_parser *parser;
333 - parser = get_partition_parser_by_type(type, prev);
337 - ret = (*parser->parse_fn)(master, pparts, data);
340 - put_partition_parser(parser);
342 - "%d %s partitions found on MTD device %s\n",
343 - ret, parser->name, master->name);
352 -EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
354 int mtd_is_partition(const struct mtd_info *mtd)
356 struct mtd_part *part;