Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752291AbcD2RtH (ORCPT ); Fri, 29 Apr 2016 13:49:07 -0400 Received: from mail-bn1bon0118.outbound.protection.outlook.com ([157.56.111.118]:35914 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751679AbcD2RtE (ORCPT ); Fri, 29 Apr 2016 13:49:04 -0400 X-Greylist: delayed 890 seconds by postgrey-1.27 at vger.kernel.org; Fri, 29 Apr 2016 13:49:04 EDT Authentication-Results: free-electrons.com; dkim=none (message not signed) header.d=none;free-electrons.com; dmarc=none action=none header.from=ni.com; Date: Fri, 29 Apr 2016 12:34:18 -0500 From: Kyle Roeschley To: Boris Brezillon CC: , , , , , , , , Peter Pan Subject: Re: [PATCH v3] mtd: nand_bbt: scan for next free bbt block if writing bbt fails Message-ID: <20160429173417.GA18490@senary> References: <1458945076-18305-1-git-send-email-kyle.roeschley@ni.com> <20160330151351.323a5333@bbrezillon> <20160330151623.7c1e4241@bbrezillon> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20160330151623.7c1e4241@bbrezillon> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [130.164.62.218] X-ClientProxiedBy: BY2PR06CA032.namprd06.prod.outlook.com (10.141.250.150) To DM2PR0401MB0942.namprd04.prod.outlook.com (10.160.97.24) X-MS-Office365-Filtering-Correlation-Id: 06fc3080-112f-4265-0fa4-08d37054795e X-Microsoft-Exchange-Diagnostics: 1;DM2PR0401MB0942;2:Vr4OK9Y2kUsT5k5PvwGPSPbbG3tWRYMG04rRpQk3wP+h6G99KMLljKcCwc+A6tg4+Ob4QJQ592PitxNx7psnPAUcQnUMVG4BMsedENkx1Sc9L+bZc4qzQ4s+rmb98nveyuTqz68YEE475KaPVoNJFkuLQmc3mzeEl0QvJjB+YHwsAz+si5pxBOZjEy1nVVHL;3:YU+SjjU6L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vUCV1bgEno3UHFy2VZF2wyPcymvIUEz+YoPa1n7IG9rJVrvVwT/UKAh5pKWp/TXKxI8/YDP/bcj00rQvI6X7eE0d8UmOgJSpZz9u+hQ+QkZKfHrLeyL28= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:DM2PR0401MB0942;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0401MB0942; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0401MB0942;4:l/9sfqjETPRolAAoFnW9GQxAWNaUNa+IguD5Nlsjn3f1h4TFB4DxjUX1tiRRQ+yXIrl9jGGQIsnoUqcRODhkcz3+EUUqlL87px6UmzeMa4itzRFznQ9sfCNIknHlJR4iHmoxt3+ddP3jFgVnWOeX2n9DaFVzJJZeF3aD4pJEUd118u+LqsBbWZ0ysNNhrF0HPeB046lKUv3x+1nswh3oVvjzUfVOEc+QERAMnuvf1jQ2xnyuFjDKzWeVwQ5IlA9dKwvhClO8/Sx2IGsC171JAJmmpfFvrF5eBtmTJKlnpO4V4Kq63kIC+PkEXuzqFkTz6iK3n+WgJkvAi50M9P3+l18BLnPJedL9qZ5nxt2Z4bBGjaQOZTvCnjGhil2SMnGwicy6Ftzvw1c0+16JypDz2A== X-Forefront-PRVS: 0927AA37C7 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(51914003)(24454002)(92566002)(19580405001)(1096002)(83506001)(33716001)(4326007)(97756001)(110136002)(189998001)(19580395003)(4001350100001)(586003)(76176999)(50986999)(54356999)(23726003)(81166005)(3846002)(6116002)(5004730100002)(5008740100001)(1076002)(2906002)(46406003)(50466002)(2950100001)(86362001)(15975445007)(16601075003)(9686002)(42186005)(66066001)(33656002)(47776003)(77096005);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0401MB0942;H:senary;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0401MB0942;23:2406K+yQXneND2cPiaGtZf9JR5VPRrSI5j2jWOL?= =?us-ascii?Q?vUzCm+g780INMLOxkCu5rQXcS/ukVbylkxR3DL7IGA+ttxZQYawTXIhB1VCk?= =?us-ascii?Q?2OYzyVKETUpzrV287czygpFpC9hsaf/hM6G0scing2KkPM+/Xw4tBRjoK4AT?= =?us-ascii?Q?E44zlwrDx2yKnU1rd9LdIhc3QM58P9kdIRUFKr4uFTs7snWz5LAVnGZNqUr8?= =?us-ascii?Q?k4tpHNKNn3tuEXN5VS1YzaAW3XsEdKFK07TgYcSS8Gf+IcmHCyF+AdUP96+D?= =?us-ascii?Q?RKuJp4l/G//8qFaFaWxE7vJBqTji4MD7mZWC6tOdzrqRqGiZcwyohIOG47cs?= =?us-ascii?Q?Kbqmiww2f1Qi4F9PmLKM2MWmIKBKkWG1+SoFPXxItFLpIudr5jUtTfDAK1T5?= =?us-ascii?Q?juUJQnwQ4739dmHofqspxs3ss1uxQgQXjB2hBVjFkINykR+bEp4UPBRWv2NI?= =?us-ascii?Q?NyAGTEW7yrKJZpinUhYgvmVIh7F2FeKi8C6LHE0/RMGIieR9za/fW9xZq2xe?= =?us-ascii?Q?MdQMypmkZNiEho9XOq2KX6oWstWJYGYvK5EPCrOsFU7mF5QH4Yj1fY2ufD9C?= =?us-ascii?Q?/uSXGq9HFe/fnqZR2lEF0dUfVQj41D8QXNOcZtmAgOdbb2vIQCCC0o9/IMA2?= =?us-ascii?Q?R80Cu4mc8dMpsnChDbb6ENs0pQs3nFbku/mGWO+mGa89B9x/DxYpptebhlXL?= =?us-ascii?Q?3CnxQ3YtX0LgGsM1m0LCRy7JJsv4eRR5PhFQLOYawyDpX7ioVomeL/LHODRg?= =?us-ascii?Q?p/p30RatGZJzYRYJY+jndPsfDubnOBA4VU9IGyfu8QVUM97kffVkcegavTRs?= =?us-ascii?Q?Y3TeRAukBKb6l+lryQb+X8z9bn0XKZMA1141DgQUCmcsh/SlsLSvnedszFXv?= =?us-ascii?Q?FUpB8HeTe9kasiQ5zJ/p+0xSTIKRExCg7x4typBV8tGU5shteSuk1BI4OvyB?= =?us-ascii?Q?2rYtH0z5wavxkDdA1nlf+KqT9Kaf5feCBxRTO1wP9mGQd45uUdl7lNZxvMG+?= =?us-ascii?Q?f/T2Kb1nMuV4VMBS1mpz8eQFoJVo7wTyESW17f4ZuEiK9zKrcQV6S/Ju7J9B?= =?us-ascii?Q?xbiSRtsc=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0401MB0942;5:Ee2lCjidWO4/1gI3nHpHLHwLdovlchT8OxMr0/hrlX1ucHIEXtkd71B8HNbEvNez0BfbfUYJhy93e0HTg1nP7ZAHI9akOdD/Brw0nI3z1OtUrSdEyk//swomFXIrDklPNbWPL/DDH+rFFbujyB8WIj01a6B/W0KKe9Iy5S2jI4ZSFXFOM7Jo/VXLcbHZKaTw;24:fUiJ9eFLKiqbyT+3BUh2kppDtJYmljgoAHuZCM75s+ZhDjtIq1NSsE3sE4vZUQuQgZNoQjuU8wabI8N3V9tV3vfTfCibQunQKPHuYcsfwNY=;7:rE+1VFSqu/32XCqNLMSVEQFjpjwvynOukyycsZ74E2I1zcFL3e9FJxeYNNrkwoTMWTkEdsE5FiMmVIM2CiMj2lqflFS7ymLrFoo1LrhLMqFpNDl/w/jQoCsLfiGXk4NjWGQ+cQf0F9qIXciRZ7CiRwmt27T1h5mY1uQ/S9rtFg2J9xvY4LMO4XDzKUOg5LOv78O2nih9uFyWn1EKEWiPfA9ZvbIpnEXjfJfnbKQYrSg= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ni.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2016 17:34:09.3268 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0401MB0942 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5778 Lines: 165 Hi Boris, On Wed, Mar 30, 2016 at 03:16:23PM +0200, Boris Brezillon wrote: > +Peter, who's currently reworking the NAND BBT code. > > On Wed, 30 Mar 2016 15:13:51 +0200 > Boris Brezillon wrote: > > > Hi Kyle, > > > > On Fri, 25 Mar 2016 17:31:16 -0500 > > Kyle Roeschley wrote: > > > > > If erasing or writing the BBT fails, we should mark the current BBT > > > block as bad and use the BBT descriptor to scan for the next available > > > unused block in the BBT. We should only return a failure if there isn't > > > any space left. > > > > > > Based on original code implemented by Jeff Westfahl > > > . > > > > > > Signed-off-by: Kyle Roeschley > > > Suggested-by: Jeff Westfahl > > > --- > > > This v3 is in response to comments from Brian Norris and Bean Ho on 8/26/15: > > > http://lists.infradead.org/pipermail/linux-mtd/2015-August/061411.html > > > > > > v3: Don't overload mtd->priv > > > Keep nand_erase_nand from erroring on protected BBT blocks > > > > > > v2: Mark OOB area in each block as well as BBT > > > Avoid marking read-only, bad address, or known bad blocks as bad > > > --- > > > drivers/mtd/nand/nand_base.c | 4 ++-- > > > drivers/mtd/nand/nand_bbt.c | 37 +++++++++++++++++++++++++++++++++++-- > > > 2 files changed, 37 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c > > > index b6facac..9ad8a86 100644 > > > --- a/drivers/mtd/nand/nand_base.c > > > +++ b/drivers/mtd/nand/nand_base.c > > > @@ -2916,8 +2916,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, > > > /* Select the NAND device */ > > > chip->select_chip(mtd, chipnr); > > > > > > - /* Check, if it is write protected */ > > > - if (nand_check_wp(mtd)) { > > > + /* Check if it is write protected, unless we're erasing BBT */ > > > + if (nand_check_wp(mtd) && !allowbbt) { > > > > Hm, will this really work. Can a write-protected device accept erase > > commands? > > Having looked into this more, no. Since v2, we called block_markbad in write_bbt incorrectly and caused the chip to report that it was write protected. Fixing that makes this unnecessary. > > > pr_debug("%s: device is write protected!\n", > > > __func__); > > > instr->state = MTD_ERASE_FAILED; > > > diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c > > > index 2fbb523..01526e5 100644 > > > --- a/drivers/mtd/nand/nand_bbt.c > > > +++ b/drivers/mtd/nand/nand_bbt.c > > > @@ -662,6 +662,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, > > > page = td->pages[chip]; > > > goto write; > > > } > > > + next: > > > > Please put this label at the beginning of the line and fix all the other > > issues reported by checkpatch (I know we already have a 'write' label > > which does not follow this rule, but let's try to avoid adding new > > ones). > > Will do. > > > > > > /* > > > * Automatic placement of the bad block table. Search direction > > > @@ -787,14 +788,46 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, > > > einfo.addr = to; > > > einfo.len = 1 << this->bbt_erase_shift; > > > res = nand_erase_nand(mtd, &einfo, 1); > > > - if (res < 0) > > > + if (res == -EIO) { > > > + /* This block is bad. Mark it as such and see if > > > + * there's another block available in the BBT area. */ > > > + int block = page >> > > > + (this->bbt_erase_shift - this->page_shift); > > > + pr_info("nand_bbt: failed to erase block %d when writing BBT\n", > > > + block); > > > + bbt_mark_entry(this, block, BBT_BLOCK_WORN); > > > + > > > + res = this->block_markbad(mtd, block); > > > > Not sure we should mark the block bad until we managed to write a new > > BBT. ITOH, if we do so and the new BBT write is interrupted, it > > will trigger a full BBM scan, which should be harmless on most > > platforms (except those overwriting BBM with real data :-/) > > So is your suggestion here just to swap the order of block_markbad and bbt_mark_entry? > > > + if (res) > > > + pr_warn("nand_bbt: error %d while marking block %d bad\n", > > > + res, block); > > > + td->pages[chip] = -1; > > > + goto next; > > > + } else if (res < 0) { > > > goto outerr; > > > + } > > > > > > res = scan_write_bbt(mtd, to, len, buf, > > > td->options & NAND_BBT_NO_OOB ? NULL : > > > &buf[len]); > > > - if (res < 0) > > > + if (res == -EIO) { > > > + /* This block is bad. Mark it as such and see if > > > + * there's another block available in the BBT area. */ > > > + int block = page >> > > > + (this->bbt_erase_shift - this->page_shift); > > > + pr_info("nand_bbt: failed to write block %d when writing BBT\n", > > > + block); > > > + bbt_mark_entry(this, block, BBT_BLOCK_WORN); > > > + > > > + res = this->block_markbad(mtd, block); > > > + if (res) > > > + pr_warn("nand_bbt: error %d while marking block %d bad\n", > > > + res, block); > > > + td->pages[chip] = -1; > > > + goto next; > > > + } else if (res < 0) { > > > goto outerr; > > > + } > > > > > > pr_info("Bad block table written to 0x%012llx, version 0x%02X\n", > > > (unsigned long long)to, td->version[chip]); > > > > Bean, Brian, can you comment on this new version. I haven't followed > > the previous iterations, and would like to have your feedback before > > taking a decision. > > > > Thanks, > > > > Boris > > > > > > > > -- > Boris Brezillon, Free Electrons > Embedded Linux and Kernel engineering > http://free-electrons.com Thanks for the feedback, -- Kyle Roeschley Software Engineer National Instruments