From 152ea6c4bdc91bddde472d5999c776ff93caf2c8 Mon Sep 17 00:00:00 2001 From: jingfei Date: Tue, 27 May 2025 12:34:54 +0800 Subject: [PATCH] ftl:remove erase buffer for mtd device without erase interface When there's no erase function for mtd, we decide if we need erase_buffer based on this: 1. If we've got bad block marking, we still need the erase buffer. If a write fails, it's used to read back the entire bad block's contents before writing to a new block. 2. If we don't have bad block marking, the erase buffer isn't needed and can be skipped. Signed-off-by: jingfei --- drivers/mtd/ftl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index ace0eeb2c53..6f087bccba6 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -561,6 +561,18 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, int nbytes; int ret; + if (dev->mtd->erase == NULL && dev->lptable == NULL) + { + ret = MTD_BWRITE(dev->mtd, startblock, nblocks, buffer); + if (ret != nblocks) + { + ferr("ERROR: Direct write block %" PRIdOFF " failed: %d\n", + startblock, ret); + } + + return ret; + } + if (dev->oflags & O_DIRECT) { /* Direct write mode */