From patchwork Mon Jun 8 20:43:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jehan Bing X-Patchwork-Id: 28246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 42ECCB70C8 for ; Tue, 9 Jun 2009 06:49:00 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MDlhH-0001k1-4I; Mon, 08 Jun 2009 20:43:59 +0000 Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1MDlh7-0001aH-23 for linux-mtd@lists.infradead.org; Mon, 08 Jun 2009 20:43:55 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MDlh3-00014M-I2 for linux-mtd@lists.infradead.org; Mon, 08 Jun 2009 20:43:45 +0000 Received: from adsl-99-185-243-218.dsl.pltn13.sbcglobal.net ([99.185.243.218]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Jun 2009 20:43:45 +0000 Received: from jehan by adsl-99-185-243-218.dsl.pltn13.sbcglobal.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Jun 2009 20:43:45 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: linux-mtd@lists.infradead.org From: Jehan Bing Subject: Re: Nandwrite's behavior in case of write failure Date: Mon, 08 Jun 2009 13:43:26 -0700 Lines: 50 Message-ID: <4A2D77EE.2090400@orb.com> References: <1244205087.5847.66.camel@localhost.localdomain> <4A29D723.1010109@gmail.com> <1244365076.5847.317.camel@localhost.localdomain> Mime-Version: 1.0 X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: adsl-99-185-243-218.dsl.pltn13.sbcglobal.net User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <1244365076.5847.317.camel@localhost.localdomain> X-Spam-Score: -1.0 (-) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (-1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [80.91.229.2 listed in list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Artem Bityutskiy wrote: > Yes, write and erase failure mean that the erasblock is bad. But I think > marking a block as bad straight away is just dangerous. Who knows may be > this is a small glitch in a bus, or a software bug, or some-one > corrupted driver's memory, or whatever. This is why UBI is doing > eraseblock torturing before marking it as bad. And it is very careful > about error codes - only EIO code is considered as a reason to mark an > eraseblock as bad. Fixed broken behavior in case of write failure. More specifically: - Only try to mark a block bad if the errors are EIO. Other errors will abort the tool. - Also abort the tool if the marking fails instead of ignoring it. Signed-off-by: Jehan Bing --- a/nandwrite.c 2009-06-08 13:31:14.000000000 -0700 +++ b/nandwrite.c 2009-06-08 13:33:32.000000000 -0700 @@ -586,6 +586,10 @@ int main(int argc, char * const argv[]) erase_info_t erase; perror ("pwrite"); + if (errno != EIO) { + goto closeall; + } + /* Must rewind to blockstart if we can */ rewind_blocks = (mtdoffset - blockstart) / meminfo.writesize; /* Not including the one we just attempted */ rewind_bytes = (rewind_blocks * meminfo.writesize) + readlen; @@ -602,7 +606,9 @@ int main(int argc, char * const argv[]) (long)erase.start, (long)erase.start+erase.length-1); if (ioctl(fd, MEMERASE, &erase) != 0) { perror("MEMERASE"); - goto closeall; + if (errno != EIO) { + goto closeall; + } } if (markbad) { @@ -610,7 +616,7 @@ int main(int argc, char * const argv[]) fprintf(stderr, "Marking block at %08lx bad\n", (long)bad_addr); if (ioctl(fd, MEMSETBADBLOCK, &bad_addr)) { perror("MEMSETBADBLOCK"); - /* But continue anyway */ + goto closeall; } } mtdoffset = blockstart + meminfo.erasesize;