From patchwork Wed Sep 22 07:43:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 65406 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 ozlabs.org (Postfix) with ESMTPS id 57208B70D2 for ; Wed, 22 Sep 2010 17:45:03 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OyJzi-0003fk-NJ; Wed, 22 Sep 2010 07:43:58 +0000 Received: from mail-qw0-f49.google.com ([209.85.216.49]) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OyJzQ-00037o-A3 for linux-mtd@lists.infradead.org; Wed, 22 Sep 2010 07:43:42 +0000 Received: by qwe4 with SMTP id 4so16987qwe.36 for ; Wed, 22 Sep 2010 00:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:organization:to :subject:date:user-agent:cc:references:in-reply-to:mime-version :message-id:content-type:content-transfer-encoding; bh=qC1ZNvZmunKSLaBVcIhqj+G4i++KliFtsGdUbah5iCk=; b=tNUJvxX7wJFAoXtyodxTu04xdVXjlc1fX4lmP1lJZNYYZ171GvC/IuN/na0CZgOCy8 g2NJSBHqQoLgccQvZlHaWT7/xzzI4mdoeeonSAHBecLGnko5OOOAFvgRRuN4giqdyQ8Y r4NexjiJV/rnOxoJNya6AdUqNQoIKBYcA4xSU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:reply-to:organization:to:subject:date:user-agent:cc:references :in-reply-to:mime-version:message-id:content-type :content-transfer-encoding; b=HIEDUaldHgRyqEi9lXhs+xgPzg+FSoRkNt54LxK/9IMDj5OaE0ceXv3EeJqhKH1Rue 6rOzGzF5V6p+X/RxCQShT03c/aANSC7IPqPecY1itCqHqYFj2smI7dCzgcAQNATaptIE E97xQCaMoXOKCoBX1Y2BS/kLEtpNYLscb0xBg= Received: by 10.224.78.233 with SMTP id m41mr7854522qak.27.1285141346713; Wed, 22 Sep 2010 00:42:26 -0700 (PDT) Received: from vapier-m.localnet (c-76-118-228-32.hsd1.ma.comcast.net [76.118.228.32]) by mx.google.com with ESMTPS id t4sm10086825qcs.4.2010.09.22.00.42.25 (version=SSLv3 cipher=RC4-MD5); Wed, 22 Sep 2010 00:42:25 -0700 (PDT) From: Mike Frysinger Organization: ADI To: dedekind1@gmail.com Subject: Re: linux equivalent of u-boot's "nand scrub" (erasing blocks even when OOB says "bad") Date: Wed, 22 Sep 2010 03:43:32 -0400 User-Agent: KMail/1.13.5 (Linux/2.6.35.3; KDE/4.4.5; x86_64; ; ) References: <1284278043.1783.10.camel@brekeke> In-Reply-To: <1284278043.1783.10.camel@brekeke> MIME-Version: 1.0 Message-Id: <201009220343.33025.vapier.adi@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100922_034342_126819_094D3207 X-CRM114-Status: GOOD ( 29.90 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (vapier.adi[at]gmail.com) -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 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL Cc: linux-mtd@lists.infradead.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Mike Frysinger 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 On Sunday, September 12, 2010 03:54:03 Artem Bityutskiy wrote: > On Sun, 2010-09-12 at 00:03 -0400, Mike Frysinger wrote: > > On Sat, Sep 11, 2010 at 02:32, Artem Bityutskiy wrote: > > > It will be confusing if the same word is used in MTD for "unmarking" > > > eraseblocks. How about: 'force erase' or 'bad erase' ? > > > > that makes it sound like an option to the existing MEMERASE operation. > > > > so i guess what if we just do that -- extend the erase_info_user > > > > structure to contain a flags field and add a MEMERASE2 that works with > > the larger structure ? for now we'd only have one option (FORCE), but > > it makes it easy to extend in the future. > > Ohh, this was so stupid of me to not ask people to add extra fields to > 'struct erase_info_user64' which was introduced relatively recently... I > always add extra fields to ioctl data structures... > > But yeah, what you say sounds ok to me. here's a POC that works for me. with a simple tweak to `flash_eraseall`, i can now recover my mtd devices with funky OOB layouts. ive only extended MEMERASE64 as i believe the non-64 variants are EOL ? or should i also extend the 32bit interface as well ? -mike diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 5b081cb..68c2864 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -513,6 +513,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, case MEMERASE: case MEMERASE64: + case MEMERASE64_FLAGS: { struct erase_info *erase; @@ -538,6 +539,17 @@ static int mtd_ioctl(struct inode *inode, struct file *file, } erase->addr = einfo64.start; erase->len = einfo64.length; + } else if (cmd == MEMERASE64_FLAGS) { + struct erase_info_user64_flags einfo64; + + if (copy_from_user(&einfo64, argp, + sizeof(struct erase_info_user64_flags))) { + kfree(erase); + return -EFAULT; + } + erase->addr = einfo64.start; + erase->len = einfo64.length; + erase->flags = einfo64.flags; } else { struct erase_info_user einfo32; diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 8f2958f..e440d84 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2354,7 +2354,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, /* * heck if we have a bad block, we do not erase bad blocks ! */ - if (nand_block_checkbad(mtd, ((loff_t) page) << + if (!(instr->flags & MTD_ERASE_BADBLOCKS) && + nand_block_checkbad(mtd, ((loff_t) page) << chip->page_shift, 0, allowbbt)) { printk(KERN_WARNING "%s: attempt to erase a bad block " "at page 0x%08x\n", __func__, page); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 0f32a9b..f1cda73 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -37,6 +37,7 @@ struct erase_info { struct mtd_info *mtd; uint64_t addr; uint64_t len; + uint32_t flags; uint64_t fail_addr; u_long time; u_long retries; diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h index be51ae2..fef14ba 100644 --- a/include/mtd/mtd-abi.h +++ b/include/mtd/mtd-abi.h @@ -17,6 +17,12 @@ struct erase_info_user64 { __u64 length; }; +struct erase_info_user64_flags { + __u64 start; + __u64 length; + __u32 flags; +}; + struct mtd_oob_buf { __u32 start; __u32 length; @@ -61,6 +67,9 @@ struct mtd_oob_buf64 { #define MTD_OTP_FACTORY 1 #define MTD_OTP_USER 2 +/* Erase flags */ +#define MTD_ERASE_BADBLOCKS 0x1 + struct mtd_info_user { __u8 type; __u32 flags; @@ -110,6 +119,7 @@ struct otp_info { #define MEMERASE64 _IOW('M', 20, struct erase_info_user64) #define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64) #define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64) +#define MEMERASE64_FLAGS _IOW('M', 23, struct erase_info_user64_flags) /* * Obsolete legacy interface. Keep it in order not to break userspace