From patchwork Sat Aug 11 15:25:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Shijie X-Patchwork-Id: 1307661 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id E51063FC66 for ; Sat, 11 Aug 2012 03:28:10 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T02K0-0002sO-2W; Sat, 11 Aug 2012 03:25:05 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T02Jq-0002rs-He; Sat, 11 Aug 2012 03:24:55 +0000 Received: by pbbrq8 with SMTP id rq8so2401873pbb.36 for ; Fri, 10 Aug 2012 20:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=KWow/8T1kA8RN/1qb3leTLsLIR7s23VGI4pyH3d6G1g=; b=zK0YkqkiGqCzz2pMN81ksWqXVGC6AZ5I5DYy6FN3gDRgZeHGQwXuVfsvdRCkhyV3lx 5RLvTHPfrCKn5q/Cm9DQP+i/2Q523YRn/wvNrtwLAC7Zsw6BGPBbALBDbNmlwDvBrIBV adsbl1oq8unpPNfK2c0TqsrR/JK7X1xLdtvfpMCijOBnipRPKfzeplS9xlC2bTTGzUKc 7zpNd7bwkQwSLYHl3hq9pQEYFio/u1dj2E9kmySfFIs5pv8GpVeFwjkYVUFv6hMDqdsO jMHIgrMU16Di37fJvLNzGCW6l31lsxQ7O1a0/1QiI/zcomc8O+2au4eQDNqAsojlDsWh FqLA== Received: by 10.68.190.102 with SMTP id gp6mr17441659pbc.5.1344655492375; Fri, 10 Aug 2012 20:24:52 -0700 (PDT) Received: from localhost.localdomain.Home ([180.155.110.28]) by mx.google.com with ESMTPS id hr1sm522202pbc.23.2012.08.10.20.24.46 (version=SSLv3 cipher=OTHER); Fri, 10 Aug 2012 20:24:51 -0700 (PDT) From: Huang Shijie To: dwmw2@infradead.org Subject: [PATCH v2] mtd: gpmi: add NAND write verify support Date: Sat, 11 Aug 2012 11:25:28 -0400 Message-Id: <1344698728-8709-1-git-send-email-shijie8@gmail.com> X-Mailer: git-send-email 1.7.4.4 X-Spam-Note: CRM114 invocation failed X-Spam-Score: 0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (shijie8[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 3.2 DATE_IN_FUTURE_12_24 Date: is 12 to 24 hours after Received: date 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (shijie8[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: marex@denx.de, fabio.estevam@freescale.com, dedekind1@gmail.com, stable@vger.kernel.org, linux-mtd@lists.infradead.org, shawn.guo@linaro.org, Huang Shijie , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add NAND write verify support in gpmi-nand driver. This patch fixes a kernel crash when we select CONFIG_MTD_NAND_VERIFY_WRITE=y, and do some write tests: root@freescale /$ dd if=/dev/zero of=/dev/mtd0 bs=128k count=1 [ 41.070000] Unable to handle kernel NULL pointer dereference at virtual addr0 [ 41.080000] pgd = c77ac000 [ 41.080000] [00000000] *pgd=4773c831, *pte=00000000, *ppte=00000000 [ 41.090000] Internal error: Oops: 17 [#1] ARM [ 41.090000] Modules linked in: [ 41.090000] CPU: 0 Not tainted (3.6.0-rc1-next-20120809-00002-ga25d017-d) [ 41.090000] PC is at nand_verify_buf+0x18/0x5c [ 41.090000] LR is at nand_write_page+0xc0/0x140 [ 41.090000] pc : [] lr : [] psr: 20000013 [ 41.090000] sp : c7779de4 ip : 00000000 fp : c6e60000 [ 41.090000] r10: 00000000 r9 : 00020000 r8 : 00000000 [ 41.090000] r7 : 00000000 r6 : c6e60000 r5 : c762cb10 r4 : 00000000 [ 41.090000] r3 : c762c8a8 r2 : 00000800 r1 : c6e60000 r0 : 00000000 [ 41.090000] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user [ 41.090000] Control: 0005317f Table: 477ac000 DAC: 00000015 [ 41.090000] Process dd (pid: 427, stack limit = 0xc7778270) [ 41.090000] Stack: (0xc7779de4 to 0xc777a000) ... Cc: Signed-off-by: Huang Shijie --- change log: [1] use the mtd->writesize to allocate the verify buffer. [2] add new field `verify_buf` in gpmi_nand_data{} tested this patch on imx6q-arm2 board. --- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 23 +++++++++++++++++++++++ drivers/mtd/nand/gpmi-nand/gpmi-nand.h | 1 + 2 files changed, 24 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index 8c0d2f0..d98bdea 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -1512,12 +1512,34 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this) return nand_boot_init(this); } +static int gpmi_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) +{ + struct nand_chip *chip = mtd->priv; + struct gpmi_nand_data *this = chip->priv; + int ret; + + ret = chip->ecc.read_page(mtd, chip, this->verify_buf, 0, 0); + if (ret) + return -EFAULT; + if (memcmp(buf, this->verify_buf, len)) + return -EFAULT; + return 0; +} + static int gpmi_scan_bbt(struct mtd_info *mtd) { struct nand_chip *chip = mtd->priv; struct gpmi_nand_data *this = chip->priv; int ret; + /* + * We have gotten the right page size now, use it to allocate + * the proper verify buffer. + */ + this->verify_buf = kzalloc(mtd->writesize, GFP_KERNEL); + if (!this->verify_buf) + return -ENOMEM; + /* Prepare for the BBT scan. */ ret = gpmi_pre_bbt_scan(this); if (ret) @@ -1556,6 +1578,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this) chip->read_byte = gpmi_read_byte; chip->read_buf = gpmi_read_buf; chip->write_buf = gpmi_write_buf; + chip->verify_buf = gpmi_verify_buf; chip->ecc.read_page = gpmi_ecc_read_page; chip->ecc.write_page = gpmi_ecc_write_page; chip->ecc.read_oob = gpmi_ecc_read_oob; diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h index 1547a60..8ddf115 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h @@ -144,6 +144,7 @@ struct gpmi_nand_data { /* MTD / NAND */ struct nand_chip nand; struct mtd_info mtd; + uint8_t *verify_buf; /* General-use Variables */ int current_chip;