@@ -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;