At least some MTD_NO_ERASE devices like MRAM do not specify a sensible
erase block size; instead, erasesize is equal to the whole flash size. This
leads to an EINVAL return from mtd_erase_align() whenever a partial erase
is attempted.

At least on the MRAM I tested, a full flash erase did not return an error,
but it did not have any effect on the flash either. As erase seems to be
entirely unsupported on this class of devices, and it is not necessary
anyways, it's better to return early with EOPNOTSUPP.

This fixes envfs_save() on a partitioned MRAM.

Signed-off-by: Matthias Schiffer <[email protected]>
---

v2: handle in mtd_op_erase() instead of envfs_save()

 drivers/mtd/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 56e85b3d8..d3cbe502f 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -178,6 +178,9 @@ static int mtd_op_erase(struct cdev *cdev, loff_t count, 
loff_t offset)
        loff_t addr;
        int ret;
 
+       if (mtd->flags & MTD_NO_ERASE)
+               return -EOPNOTSUPP;
+
        ret = mtd_erase_align(mtd, &count, &offset);
        if (ret)
                return ret;
-- 
2.17.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to