d912811850c1f5d3e8bf47d4fb3b1acf32fe8d59
[openwrt/staging/adrian.git] /
1 From 1eeef2d7483a7e3f8d2dd2a5b9939b3b814dc549 Mon Sep 17 00:00:00 2001
2 From: Chris Packham <chris.packham@alliedtelesis.co.nz>
3 Date: Fri, 9 Jun 2017 15:58:31 +1200
4 Subject: [PATCH] mtd: handle partitioning on devices with 0 erasesize
5
6 erasesize is meaningful for flash devices but for SRAM there is no
7 concept of an erase block so erasesize is set to 0. When partitioning
8 these devices instead of ensuring partitions fall on erasesize
9 boundaries we ensure they fall on writesize boundaries.
10
11 Helped-by: Boris Brezillon <boris.brezillon@free-electrons.com>
12 Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
13 Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
14 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
15 ---
16 drivers/mtd/mtdpart.c | 26 +++++++++++++++++---------
17 1 file changed, 17 insertions(+), 9 deletions(-)
18
19 --- a/drivers/mtd/mtdpart.c
20 +++ b/drivers/mtd/mtdpart.c
21 @@ -393,8 +393,12 @@ static struct mtd_part *allocate_partiti
22 const struct mtd_partition *part, int partno,
23 uint64_t cur_offset)
24 {
25 + int wr_alignment = (master->flags & MTD_NO_ERASE) ? master->writesize:
26 + master->erasesize;
27 struct mtd_part *slave;
28 + u32 remainder;
29 char *name;
30 + u64 tmp;
31
32 /* allocate the partition structure */
33 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
34 @@ -499,10 +503,11 @@ static struct mtd_part *allocate_partiti
35 if (slave->offset == MTDPART_OFS_APPEND)
36 slave->offset = cur_offset;
37 if (slave->offset == MTDPART_OFS_NXTBLK) {
38 + tmp = cur_offset;
39 slave->offset = cur_offset;
40 - if (mtd_mod_by_eb(cur_offset, master) != 0) {
41 - /* Round up to next erasesize */
42 - slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
43 + remainder = do_div(tmp, wr_alignment);
44 + if (remainder) {
45 + slave->offset += wr_alignment - remainder;
46 printk(KERN_NOTICE "Moving partition %d: "
47 "0x%012llx -> 0x%012llx\n", partno,
48 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
49 @@ -567,19 +572,22 @@ static struct mtd_part *allocate_partiti
50 slave->mtd.erasesize = master->erasesize;
51 }
52
53 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
54 - mtd_mod_by_eb(slave->offset, &slave->mtd)) {
55 + tmp = slave->offset;
56 + remainder = do_div(tmp, wr_alignment);
57 + if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {
58 /* Doesn't start on a boundary of major erase size */
59 /* FIXME: Let it be writable if it is on a boundary of
60 * _minor_ erase size though */
61 slave->mtd.flags &= ~MTD_WRITEABLE;
62 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
63 + printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
64 part->name);
65 }
66 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
67 - mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) {
68 +
69 + tmp = slave->mtd.size;
70 + remainder = do_div(tmp, wr_alignment);
71 + if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {
72 slave->mtd.flags &= ~MTD_WRITEABLE;
73 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
74 + printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
75 part->name);
76 }
77