From patchwork Fri Feb 8 15:48:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Chapman X-Patchwork-Id: 219209 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 51CC52C0086 for ; Sat, 9 Feb 2013 02:48:55 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1797E4A0C0; Fri, 8 Feb 2013 16:48:49 +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 H9OJOGO8FWBX; Fri, 8 Feb 2013 16:48:48 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8A0BF4A0F4; Fri, 8 Feb 2013 16:48:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BE3FF4A0F4 for ; Fri, 8 Feb 2013 16:48:41 +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 OGRcYmx18TXD for ; Fri, 8 Feb 2013 16:48:38 +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 hrndva-omtalb.mail.rr.com (hrndva-omtalb.mail.rr.com [71.74.56.122]) by theia.denx.de (Postfix) with ESMTP id AEC5A4A0C0 for ; Fri, 8 Feb 2013 16:48:34 +0100 (CET) X-Authority-Analysis: v=2.0 cv=C91rOHz+ c=1 sm=0 a=0BEmelG+NCIkmYz4MtfDKA==:17 a=KAMKcUAUZugA:10 a=T-CLKDmqibgA:10 a=h1JwTc6auzgA:10 a=wPDyFdB5xvgA:10 a=kj9zAlcOel0A:10 a=cL4bF6sHAAAA:8 a=Z9EXKnrytoEA:10 a=6ohNodAXAAAA:8 a=h_vRk3YPcO5rg2ya_xQA:9 a=CjuIK1q_8ugA:10 a=gDjHQkheYgsA:10 a=0BEmelG+NCIkmYz4MtfDKA==:117 X-Cloudmark-Score: 0 X-Authenticated-User: X-Originating-IP: 65.34.9.19 Received: from [65.34.9.19] ([65.34.9.19:47588] helo=blue.3gfp.com) by hrndva-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id 8A/97-27917-74E15115; Fri, 08 Feb 2013 15:48:23 +0000 Received: from localhost (localhost [127.0.0.1]) by blue.3gfp.com (Postfix) with ESMTP id D2F4610804BD; Fri, 8 Feb 2013 10:48:22 -0500 (EST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at 3gfp.com Received: from blue.3gfp.com ([127.0.0.1]) by localhost (blue.3gfp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TGwkpAD5kBCA; Fri, 8 Feb 2013 10:48:18 -0500 (EST) Received: from [192.168.1.26] (65349hfc19.tampabay.res.rr.com [65.34.9.19]) by blue.3gfp.com (Postfix) with ESMTPSA id 89AF6108005E; Fri, 8 Feb 2013 10:48:16 -0500 (EST) Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) From: Harvey Chapman In-Reply-To: <1360275748.27002.11@snotra> Date: Fri, 8 Feb 2013 10:48:16 -0500 Message-Id: <41DD0060-5CA2-4643-A5A7-B35BF2775981@3gfp.com> References: <1360274360.27002.10@snotra> <1360275748.27002.11@snotra> To: Scott Wood X-Mailer: Apple Mail (2.1499) Cc: "u-boot@lists.denx.de" Subject: Re: [U-Boot] U-boot nand bug, read.part should fail 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de On Feb 7, 2013, at 5:22 PM, Scott Wood wrote: > It's fine until you get a bad block in the partition, and you end up accessing the first block of the next partition (or getting "Attempt to read/write outside the flash area" if it's the last partition). > > Of course, fixing partition/chip accesses to account for this when determining size would be even better. :-) Something like this? diff --git a/common/cmd_nand.c b/common/cmd_nand.c --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -621,60 +621,78 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, nand = &nand_info[dev]; s = strchr(cmd, '.'); if (s && !strcmp(s, ".raw")) { raw = 1; if (arg_off(argv[3], &dev, &off, &size)) return 1; if (argc > 4 && !str2long(argv[4], &pagecount)) { printf("'%s' is not a number\n", argv[4]); return 1; } if (pagecount * nand->writesize > size) { puts("Size exceeds partition or device limit\n"); return -1; } rwsize = pagecount * (nand->writesize + nand->oobsize); } else { if (arg_off_size(argc - 3, argv + 3, &dev, &off, &size) != 0) return 1; rwsize = size; } + /* If no size was given, it has been calculated for us as + * the remainder of the chip or partition from offset. Adjust + * down for bad blocks, if necessary. + */ + if (argc < 4) { + nand_info_t *nand = &nand_info[dev]; + int maxsize = rwsize; + int offset = off; + for (; offset < maxsize; offset += nand->erasesize) + if (nand_block_isbad(nand, offset)) + rwsize -= nand->erasesize; + + if (rwsize != maxsize) + printf("\nsize adjusted to %d (%d bad blocks)\n", + rwsize, + (maxsize - rwsize) / nand->erasesize); + } + if (!s || !strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i") || !strcmp(s, ".part")) { if (read) ret = nand_read_skip_bad(nand, off, &rwsize, (u_char *)addr); else ret = nand_write_skip_bad(nand, off, &rwsize, (u_char *)addr, 0); #ifdef CONFIG_CMD_NAND_TRIMFFS } else if (!strcmp(s, ".trimffs")) { if (read) { printf("Unknown nand command suffix '%s'\n", s); return 1; } ret = nand_write_skip_bad(nand, off, &rwsize, (u_char *)addr, WITH_DROP_FFS); #endif #ifdef CONFIG_CMD_NAND_YAFFS } else if (!strcmp(s, ".yaffs")) { if (read) { printf("Unknown nand command suffix '%s'.\n", s); return 1; } ret = nand_write_skip_bad(nand, off, &rwsize, (u_char *)addr, WITH_INLINE_OOB); #endif } else if (!strcmp(s, ".oob")) { /* out-of-band data */