[v2,6/6] UBI: use mtd->writebufsize to set minimal I/O unit size

Submitted by Anatolij Gustschin on Dec. 16, 2010, 10:42 p.m.

Details

Message ID 1292539339-25111-7-git-send-email-agust@denx.de
State New, archived
Headers show

Commit Message

Anatolij Gustschin Dec. 16, 2010, 10:42 p.m.
Previously we used mtd->writesize field to set UBI's minimal
I/O unit size. This sometimes caused UBIFS recovery issues
when mounting an uncleanly unmounted UBIFS partition on NOR
flash since mtd->writesize is 1 byte for NOR flash. The
MTD CFI driver however often performs writing multiple
bytes in one programming operation using the chip's write
buffer. We have to use the size of this write buffer as
a minimal I/O unit size for UBI on NOR flash to fix the
observed UBIFS recovery issues.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
 drivers/mtd/ubi/build.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy Dec. 19, 2010, 5:46 p.m.
On Thu, 2010-12-16 at 23:42 +0100, Anatolij Gustschin wrote:
> Previously we used mtd->writesize field to set UBI's minimal
> I/O unit size. This sometimes caused UBIFS recovery issues
> when mounting an uncleanly unmounted UBIFS partition on NOR
> flash since mtd->writesize is 1 byte for NOR flash. The
> MTD CFI driver however often performs writing multiple
> bytes in one programming operation using the chip's write
> buffer. We have to use the size of this write buffer as
> a minimal I/O unit size for UBI on NOR flash to fix the
> observed UBIFS recovery issues.
> 
> Signed-off-by: Anatolij Gustschin <agust@denx.de>

I've re-wrote the commentary and pushed, please, check.
Anatolij Gustschin Dec. 20, 2010, 9:18 a.m.
On Sun, 19 Dec 2010 19:46:19 +0200
Artem Bityutskiy <dedekind1@gmail.com> wrote:

> On Thu, 2010-12-16 at 23:42 +0100, Anatolij Gustschin wrote:
> > Previously we used mtd->writesize field to set UBI's minimal
> > I/O unit size. This sometimes caused UBIFS recovery issues
> > when mounting an uncleanly unmounted UBIFS partition on NOR
> > flash since mtd->writesize is 1 byte for NOR flash. The
> > MTD CFI driver however often performs writing multiple
> > bytes in one programming operation using the chip's write
> > buffer. We have to use the size of this write buffer as
> > a minimal I/O unit size for UBI on NOR flash to fix the
> > observed UBIFS recovery issues.
> > 
> > Signed-off-by: Anatolij Gustschin <agust@denx.de>
> 
> I've re-wrote the commentary and pushed, please, check.

Checked, it is ok. Thanks!

Anatolij

Patch hide | download patch | download mbox

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 5ebe280..c2d5310 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -672,7 +672,24 @@  static int io_init(struct ubi_device *ubi)
 		ubi->nor_flash = 1;
 	}
 
-	ubi->min_io_size = ubi->mtd->writesize;
+	/*
+	 * Sets minimal I/O unit size (min_io_size) for UBI. On NAND flash
+	 * min_io_size should be equivalent to ubi->mtd->writesize.
+	 * In case of NOR flash minimal I/O size must be equal to the size
+	 * of the write buffer used by internal flash programming algorithm.
+	 * This requirement results from the fact that the flash programming
+	 * operation could be interrupted by a power cut or a system reset
+	 * causing corrupted (partially written) areas in a NOR flash sector.
+	 * Knowing the size of potentially corrupted areas UBIFS scanning
+	 * and recovery algorithms are able to perform successful recovery.
+	 */
+	if (ubi->mtd->type == MTD_NANDFLASH)
+		ubi_assert(ubi->mtd->writebufsize == ubi->mtd->writesize);
+	else if (ubi->mtd->type == MTD_NORFLASH)
+		ubi_assert(ubi->mtd->writebufsize > 0);
+
+	ubi->min_io_size = ubi->mtd->writebufsize;
+
 	ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
 
 	/*