412-mtd-partial_eraseblock_unlock.patch 1.4 KB

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