From patchwork Sat Mar 2 09:01:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 224476 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 3D2EF2C02C5 for ; Sat, 2 Mar 2013 20:22:18 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5E5BC4A0FB; Sat, 2 Mar 2013 10:22:16 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 mk6QUtIWmh2g; Sat, 2 Mar 2013 10:22:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2530D4A0FE; Sat, 2 Mar 2013 10:22:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 92FCC4A0FE for ; Sat, 2 Mar 2013 10:22:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 v6I46veoK4Zf for ; Sat, 2 Mar 2013 10:22:12 +0100 (CET) X-Greylist: delayed 1338 seconds by postgrey-1.27 at theia; Sat, 02 Mar 2013 10:22:10 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 mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by theia.denx.de (Postfix) with ESMTPS id 723034A0FB for ; Sat, 2 Mar 2013 10:22:10 +0100 (CET) Received: by mail-pb0-f45.google.com with SMTP id ro8so2212762pbb.4 for ; Sat, 02 Mar 2013 01:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=dH1HaU68CtZQTJqVqEl0jhm7lFrF3LJkeBIag10YhME=; b=gNunfh/lc+UImaSUV1NHTB5W9dohfvgLnv8il8NLe67YyoIZ3meSSL/hCMBhk/PPdp H+HW+MMkIfzyV4wy2BLNZQyCT0+1GXgzjqiM3GRrZnk7+5j1Bff86TX2VarLvMo5o3Ne b+eHGsWH9LKcRiV0PEAh5KaKIephh7bqfFiCePTfF9J3hFJWRmV6Ym4l63im8z9qaizE bpu83LeWzz+Nd8FcLJb+bV8GrX5eUJzh6aAClm57o1AoEELRkNU85jtvKi4s7ethFw+E f5bC0tYp+imV8VPBy0pBheAf6fpplQkDt/xWX9cNU0zHrMlcQpcQMGBpZaGLFfLL3/Hd LIuw== X-Received: by 10.66.251.129 with SMTP id zk1mr22778664pac.9.1362214488839; Sat, 02 Mar 2013 00:54:48 -0800 (PST) Received: from localhost.localdomain ([115.199.193.213]) by mx.google.com with ESMTPS id 1sm14948107pbg.18.2013.03.02.00.54.44 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 02 Mar 2013 00:54:48 -0800 (PST) From: Tao Hou To: u-boot@lists.denx.de Date: Sat, 2 Mar 2013 17:01:10 +0800 Message-Id: <1362214870-7464-1-git-send-email-hotforest@gmail.com> X-Mailer: git-send-email 1.7.9.5 Cc: Scott Wood , Tao Hou , Lei Wen Subject: [U-Boot] [PATCH] mtd: nand: fix the written length when nand_write_skip_bad failed X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 When the data has been partially written into the NAND Flash, returning the written length instead of 0. The written length may be useful when the upper level decides to continue the writing after skipping the block causing the write failure. Signed-off-by: Tao Hou Cc: Scott Wood Cc: Ben Gardiner Cc: Lei Wen --- drivers/mtd/nand/nand_util.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c index de1d13e..f57d723 100644 --- a/drivers/mtd/nand/nand_util.c +++ b/drivers/mtd/nand/nand_util.c @@ -496,8 +496,10 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, #ifdef CONFIG_CMD_NAND_YAFFS if (flags & WITH_YAFFS_OOB) { - if (flags & ~WITH_YAFFS_OOB) + if (flags & ~WITH_YAFFS_OOB) { + *length = 0; return -EINVAL; + } int pages; pages = nand->erasesize / nand->writesize; @@ -505,6 +507,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, if (*length % (nand->writesize + nand->oobsize)) { printf("Attempt to write incomplete page" " in yaffs mode\n"); + *length = 0; return -EINVAL; } } else @@ -542,7 +545,6 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, if (rval == 0) return 0; - *length = 0; printf("NAND write to offset %llx failed %d\n", offset, rval); return rval; @@ -550,7 +552,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, while (left_to_write > 0) { size_t block_offset = offset & (nand->erasesize - 1); - size_t write_size, truncated_write_size; + size_t write_size, truncated_write_size, written_size; WATCHDOG_RESET(); @@ -586,8 +588,10 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, ops.oobbuf = ops.datbuf + pagesize; rval = nand->write_oob(nand, offset, &ops); - if (rval != 0) + if (rval != 0) { + written_size = pagesize_oob * page; break; + } offset += pagesize; p_buffer += pagesize_oob; @@ -605,14 +609,18 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, rval = nand_write(nand, offset, &truncated_write_size, p_buffer); - offset += write_size; - p_buffer += write_size; + if (rval == 0) { + offset += write_size; + p_buffer += write_size; + } else { + written_size = truncated_write_size; + } } if (rval != 0) { printf("NAND write to offset %llx failed %d\n", offset, rval); - *length -= left_to_write; + *length -= left_to_write - written_size; return rval; }