diff --git a/drivers/mtd/mtd_nand.c b/drivers/mtd/mtd_nand.c index 7d3530da10..33b4dac6a4 100644 --- a/drivers/mtd/mtd_nand.c +++ b/drivers/mtd/mtd_nand.c @@ -549,6 +549,7 @@ static ssize_t nand_bread(FAR struct mtd_dev_s *dev, off_t startpage, FAR struct nand_dev_s *nand = (FAR struct nand_dev_s *)dev; FAR struct nand_raw_s *raw; FAR struct nand_model_s *model; + bool fixedecc = false; unsigned int pagesperblock; unsigned int page; uint16_t pagesize; @@ -600,7 +601,11 @@ static ssize_t nand_bread(FAR struct mtd_dev_s *dev, off_t startpage, /* Read the next page from NAND */ ret = nand_readpage(nand, block, page, buffer); - if (ret < 0) + if (ret == -EUCLEAN) + { + fixedecc = true; + } + else if (ret < 0) { ferr("ERROR: nand_readpage failed block=%ld page=%d: %d\n", (long)block, page, ret); @@ -624,7 +629,7 @@ static ssize_t nand_bread(FAR struct mtd_dev_s *dev, off_t startpage, } nxmutex_unlock(&nand->lock); - return npages; + return fixedecc ? -EUCLEAN : npages; errout_with_lock: nxmutex_unlock(&nand->lock); diff --git a/drivers/mtd/mtd_nandecc.c b/drivers/mtd/mtd_nandecc.c index 83a0229a8a..255ab1c8f2 100644 --- a/drivers/mtd/mtd_nandecc.c +++ b/drivers/mtd/mtd_nandecc.c @@ -138,14 +138,19 @@ int nandecc_readpage(FAR struct nand_dev_s *nand, off_t block, /* Use the ECC data to verify the page */ ret = hamming_verify256x(data, pagesize, raw->ecc); - if (ret && (ret != HAMMING_ERROR_SINGLEBIT)) + switch (ret) { + case HAMMING_SUCCESS: + return OK; + + case HAMMING_ERROR_SINGLEBIT: + return -EUCLEAN; + + default: ferr("ERROR: Block=%d page=%d Unrecoverable error: %d\n", block, page, ret); - return -EIO; + return -EBADMSG; } - - return OK; } /****************************************************************************