From patchwork Mon Jan 26 22:24:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Tyser X-Patchwork-Id: 433061 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6B0B31401DE for ; Tue, 27 Jan 2015 09:25:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 256E24B67B; Mon, 26 Jan 2015 23:25:37 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oygQ+CUvu5IY; Mon, 26 Jan 2015 23:25:36 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9E7D94B668; Mon, 26 Jan 2015 23:25:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E2F934B666 for ; Mon, 26 Jan 2015 23:25:22 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a4nCWNMqt30h for ; Mon, 26 Jan 2015 23:25:22 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from xes-mad.com (xes-mad.com [216.165.139.218]) by theia.denx.de (Postfix) with ESMTPS id 835354B65D for ; Mon, 26 Jan 2015 23:25:21 +0100 (CET) Received: from petert.xes-mad.com (rmetzig1 [10.52.18.138]) by xes-mad.com (8.13.8/8.13.8) with ESMTP id t0QMP1XI013741; Mon, 26 Jan 2015 16:25:17 -0600 From: Peter Tyser To: u-boot@lists.denx.de Date: Mon, 26 Jan 2015 16:24:50 -0600 Message-Id: <1422311091-4110-4-git-send-email-ptyser@xes-inc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422311091-4110-1-git-send-email-ptyser@xes-inc.com> References: <1422311091-4110-1-git-send-email-ptyser@xes-inc.com> Cc: Scott Wood , Peter Tyser , Joe Schaack Subject: [U-Boot] [PATCH 4/5] mtd: nand: Use ECC for NAND write verification X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Joe Schaack Modify the nand_write_page() function to use ECC when appropriate to verify writes. Previously if a single bit error occured and software ECC was used the write verification would report a failure. However, the write really did succeed, since ECC can handle the error. The issue can be simulated with a sequence of commands such as: # Inject a fake bit that is stuck low (2K page flash being used) nand erase 0 0x20000 mw.b 0x10000 0xff 0x1000 mw.b 0x10000 0xfe 1 nand write.raw 0x10000 0x0 0x1 # Write some data which needs to toggle the fake stuck bit mw.b 0x10000 0xab 1 nand write 0x10000 0x0 0x800 An error will occur: NAND write: device 0 offset 0x0, size 0x800 NAND write to offset 0 failed -5 0 bytes written: ERROR But you can verify data was correctly written: # Show data is correct when ECC is used nand read 0x10000 0x0 0x800 md 0x10000 # Show the bit is still stuck low nand read.raw 0x10000 0x0 0x1 md 0x10000 Change the behavior so ECC is used when verifying non-raw writes. This only impacts boards that have COFNIG_MTD_NAND_VERIFY_WRITE defined. Signed-off-by: Joe Schaack Signed-off-by: Peter Tyser --- drivers/mtd/nand/nand_base.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index abcb84a..aa039ef 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2405,7 +2405,10 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, /* Send command to read back the data */ chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page); - chip->ecc.read_page_raw(mtd, chip, vfy_buf, oob_required, page); + if (unlikely(raw)) + chip->ecc.read_page_raw(mtd, chip, vfy_buf, oob_required, page); + else + chip->ecc.read_page(mtd, chip, vfy_buf, oob_required, page); status = memcmp(buf, vfy_buf, mtd->writesize);