8969de504c2d54605dbf5bd9c7641a780c4520bf
[openwrt/openwrt.git] / target / linux / generic / pending-4.9 / 412-mtd-partial_eraseblock_unlock.patch
1 From: Tim Harvey <tharvey@gateworks.com>
2 Subject: mtd: allow partial block unlock
3
4 This allows sysupgrade for devices such as the Gateworks Avila/Cambria
5 product families based on the ixp4xx using the redboot bootloader with
6 combined FIS directory and RedBoot config partitions on larger FLASH
7 devices with larger eraseblocks.
8
9 This second iteration of this patch addresses previous issues:
10 - whitespace breakage fixed
11 - unlock in all scenarios
12 - simplification and fix logic bug
13
14 [john@phrozen.org: this should be moved to the ixp4xx folder]
15
16 Signed-off-by: Tim Harvey <tharvey@gateworks.com>
17 ---
18 drivers/mtd/mtdpart.c | 11 ++++++++++-
19 1 file changed, 10 insertions(+), 1 deletion(-)
20
21 diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
22 index 0238b0babe2f..d41418524833 100644
23 --- a/drivers/mtd/mtdpart.c
24 +++ b/drivers/mtd/mtdpart.c
25 @@ -343,7 +343,16 @@ static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
26 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
27 {
28 struct mtd_part *part = mtd_to_part(mtd);
29 - return part->parent->_unlock(part->parent, ofs + part->offset, len);
30 +
31 + ofs += part->offset;
32 +
33 + if (mtd->flags & MTD_ERASE_PARTIAL) {
34 + /* round up len to next erasesize and round down offset to prev block */
35 + len = (mtd_div_by_eb(len, part->parent) + 1) * part->parent->erasesize;
36 + ofs &= ~(part->parent->erasesize - 1);
37 + }
38 +
39 + return part->parent->_unlock(part->parent, ofs, len);
40 }
41
42 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
43 --
44 2.11.0
45