| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | --- a/drivers/mtd/mtdpart.c | 
|  | 22 | +++ b/drivers/mtd/mtdpart.c | 
|  | 23 | @@ -294,7 +294,16 @@ static int part_lock(struct mtd_info *mt | 
|  | 24 | static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | 
|  | 25 | { | 
|  | 26 | struct mtd_part *part = mtd_to_part(mtd); | 
|  | 27 | -	return part->parent->_unlock(part->parent, ofs + part->offset, len); | 
|  | 28 | + | 
|  | 29 | +	ofs += part->offset; | 
|  | 30 | + | 
|  | 31 | +	if (mtd->flags & MTD_ERASE_PARTIAL) { | 
|  | 32 | +		/* round up len to next erasesize and round down offset to prev block */ | 
|  | 33 | +		len = (mtd_div_by_eb(len, part->parent) + 1) * part->parent->erasesize; | 
|  | 34 | +		ofs &= ~(part->parent->erasesize - 1); | 
|  | 35 | +	} | 
|  | 36 | + | 
|  | 37 | +	return part->parent->_unlock(part->parent, ofs, len); | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) |