There is a MTD_NO_ERASE flag for supporting spi flash devices with no
erase command but this isn't checked.

spi_flash_erase now returns 0 if this flag is set.

Signed-off-by: Yasir Kilic <[email protected]>
---
 include/spi_flash.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/spi_flash.h b/include/spi_flash.h
index 2e703e85250..f471225bf54 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -128,6 +128,11 @@ static inline int spi_flash_write(struct spi_flash *flash, 
u32 offset,
 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
                                  size_t len)
 {
+       struct mtd_info *mtd = &flash->mtd;
+
+       if (mtd->flags | MTD_NO_ERASE)
+               return 0;
+
        return spi_flash_erase_dm(flash->dev, offset, len);
 }
 
@@ -208,6 +213,9 @@ static inline int spi_flash_erase(struct spi_flash *flash, 
u32 offset,
        struct mtd_info *mtd = &flash->mtd;
        struct erase_info instr;
 
+       if (mtd->flags | MTD_NO_ERASE)
+               return 0;
+
        if (offset % mtd->erasesize || len % mtd->erasesize) {
                printf("SF: Erase offset/length not multiple of erase size\n");
                return -EINVAL;

-- 
2.43.0

Reply via email to