nand: fix data corruption after mtd write
authorFrank Chen <frank.chen@amlogic.com>
Sat, 25 Mar 2017 14:52:28 +0000 (22:52 +0800)
committerVictor Wan <victor.wan@amlogic.com>
Mon, 27 Mar 2017 12:38:08 +0000 (04:38 -0800)
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 <frank.chen@amlogic.com>
drivers/amlogic/mtd/aml_mtd.h
drivers/amlogic/mtd/aml_nand.c
drivers/amlogic/mtd/nand_flash.c

index 3d1785b082707d9b1043abf8664e5dae59d35f6f..4808dc12be337efb15e90f0049a791c120ecb058 100644 (file)
@@ -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);
index 1b0d0c569f617a3a7c6f97a0e092e9754d0e7ba3..916ba47cd64f00898f2e4a1d2c1794da8c9bb612 100644 (file)
@@ -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)
index b3d49c820eec6965c0d09a0a9b5efd68c1dd1977..0af862b816cf865e2dd072da3509f4b537992a2a 100644 (file)
@@ -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;