From patchwork Tue Nov 5 12:00:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 288482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3C1EA2C032D for ; Tue, 5 Nov 2013 23:01:21 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VdfJd-0007aV-HA; Tue, 05 Nov 2013 12:01:01 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VdfJb-0006y9-RM; Tue, 05 Nov 2013 12:00:59 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VdfJV-0006vC-3H for linux-mtd@lists.infradead.org; Tue, 05 Nov 2013 12:00:54 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id CBD6881D; Tue, 5 Nov 2013 13:00:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost.localdomain (unknown [190.2.98.212]) by mail.free-electrons.com (Postfix) with ESMTPA id 5C9717E4; Tue, 5 Nov 2013 13:00:35 +0100 (CET) From: Ezequiel Garcia To: Subject: [PATCH 1/1] mtd: nand: Allow bad block markers to be found in the data region Date: Tue, 5 Nov 2013 09:00:21 -0300 Message-Id: <1383652821-3557-2-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1383652821-3557-1-git-send-email-ezequiel.garcia@free-electrons.com> References: <1383652821-3557-1-git-send-email-ezequiel.garcia@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131105_070053_403630_DE56E37D X-CRM114-Status: GOOD ( 16.00 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Lior Amsalem , Thomas Petazzoni , Tawfik Bayouk , Artem Bityutskiy , Huang Shijie , Ezequiel Garcia , Gregory Clement , Brian Norris , David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Some NAND controllers provide its own unique view of a flash device's page, where the page is partitioned into several DATA,OOB regions. In other words, a flash that's specified by the manufacturer as: |-------------------------| | DATA | OOB | |-------------------------| is actually handled by the driver/controller as: |-------------------------| | DATA | OOB | DATA | OOB | |-------------------------| This has a peculiar side-effect: the bad block marker is located at a position that is regarded as the data region in the controller's view. Therefore, when the device is scanned for bad blocks (for the first time) and the bad block table is built using the factory-marked blocks, these markers are never found. To address this case, we introduce a new option NAND_BBT_DATA_BBM. Such option is used to read the data region of a a given page, instead of the oob region, in the scan_block_fast() function. The page is read as usual, using the length and offset parameters set in the bad block pattern. Given drivers can customize the bad block pattern to match its specific requirements, the new option allows to search for a bad block marker at *any* position within a page. Signed-off-by: Ezequiel Garcia --- drivers/mtd/nand/nand_bbt.c | 11 +++++++++-- include/linux/mtd/bbm.h | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index c0615d1..3f712cc 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -419,10 +419,17 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, struct mtd_oob_ops ops; int j, ret; + if (bd->options & NAND_BBT_DATA_BBM) { + ops.oobbuf = (buf + mtd->writesize); + ops.datbuf = buf; + ops.len = mtd->writesize; + } else { + ops.oobbuf = buf; + ops.datbuf = NULL; + ops.len = 0; + } ops.ooblen = mtd->oobsize; - ops.oobbuf = buf; ops.ooboffs = 0; - ops.datbuf = NULL; ops.mode = MTD_OPS_PLACE_OOB; for (j = 0; j < numpages; j++) { diff --git a/include/linux/mtd/bbm.h b/include/linux/mtd/bbm.h index 36bb6a5..75d590d 100644 --- a/include/linux/mtd/bbm.h +++ b/include/linux/mtd/bbm.h @@ -114,6 +114,10 @@ struct nand_bbt_descr { * entire spare area. Must be used with NAND_BBT_USE_FLASH. */ #define NAND_BBT_NO_OOB_BBM 0x00080000 +/* + * Search for bad block marker in the data region, instead of the OOB. + */ +#define NAND_BBT_DATA_BBM 0x00100000 /* * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr