From 08e78d81be18abfc427b8d7e1c0f8a16ba4ed023 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 25 Mar 2017 22:52:28 +0800 Subject: [PATCH] nand: fix data corruption after mtd write PD#138714: fix data corruption after mtd write nand_chip.erase is obligatory, without this implement, nand write will fail and cause ecc fail next time read data. Change-Id: I79cabce7c03938e13785ecc42d48b9e750508f3e Signed-off-by: Frank Chen --- drivers/amlogic/mtd/aml_mtd.h | 2 +- drivers/amlogic/mtd/aml_nand.c | 7 ++++--- drivers/amlogic/mtd/nand_flash.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/amlogic/mtd/aml_mtd.h b/drivers/amlogic/mtd/aml_mtd.h index 3d1785b08270..4808dc12be33 100644 --- a/drivers/amlogic/mtd/aml_mtd.h +++ b/drivers/amlogic/mtd/aml_mtd.h @@ -798,7 +798,7 @@ void aml_nand_command(struct mtd_info *mtd, int aml_nand_wait(struct mtd_info *mtd, struct nand_chip *chip); -void aml_nand_erase_cmd(struct mtd_info *mtd, int page); +int aml_nand_erase_cmd(struct mtd_info *mtd, int page); int add_mtd_partitions(struct mtd_info *mtd, const struct mtd_partition *part, int num); diff --git a/drivers/amlogic/mtd/aml_nand.c b/drivers/amlogic/mtd/aml_nand.c index 1b0d0c569f61..916ba47cd64f 100644 --- a/drivers/amlogic/mtd/aml_nand.c +++ b/drivers/amlogic/mtd/aml_nand.c @@ -1109,7 +1109,7 @@ void aml_nand_command(struct mtd_info *mtd, } -void aml_nand_erase_cmd(struct mtd_info *mtd, int page) +int aml_nand_erase_cmd(struct mtd_info *mtd, int page) { struct aml_nand_chip *aml_chip = mtd_to_nand_chip(mtd); struct nand_chip *chip = mtd->priv; @@ -1123,7 +1123,7 @@ void aml_nand_erase_cmd(struct mtd_info *mtd, int page) vt_page_num = (mtd->writesize / (1 << chip->page_shift)); vt_page_num *= (1 << pages_per_blk_shift); if (page % vt_page_num) - return; + return 0; /* Send commands to erase a block */ valid_page_num = (mtd->writesize >> chip->page_shift); @@ -1131,7 +1131,7 @@ void aml_nand_erase_cmd(struct mtd_info *mtd, int page) block_addr = ((page / valid_page_num) >> pages_per_blk_shift); if (aml_nand_rsv_erase_protect(mtd, block_addr) == -1) - return; + return -EPERM; valid_page_num /= aml_chip->plane_num; @@ -1166,6 +1166,7 @@ void aml_nand_erase_cmd(struct mtd_info *mtd, int page) } } } + return 0; } void aml_nand_dma_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) diff --git a/drivers/amlogic/mtd/nand_flash.c b/drivers/amlogic/mtd/nand_flash.c index b3d49c820eec..0af862b816cf 100644 --- a/drivers/amlogic/mtd/nand_flash.c +++ b/drivers/amlogic/mtd/nand_flash.c @@ -1285,7 +1285,7 @@ static int aml_nand_scan_ident(struct mtd_info *mtd, int maxchips) chip->cmdfunc = aml_nand_command; chip->waitfunc = aml_nand_wait; - /*chip->erase_cmd = aml_nand_erase_cmd;*/ + chip->erase = aml_nand_erase_cmd; chip->write_page = aml_nand_write_page; return 0; -- 2.20.1