From patchwork Thu Jun 28 15:47:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu CASTET X-Patchwork-Id: 167907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7631FB6FFD for ; Fri, 29 Jun 2012 01:49:01 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SkGwS-0000eX-TR; Thu, 28 Jun 2012 15:47:37 +0000 Received: from mail-ee0-f49.google.com ([74.125.83.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SkGwP-0000cI-19 for linux-mtd@lists.infradead.org; Thu, 28 Jun 2012 15:47:33 +0000 Received: by eekd17 with SMTP id d17so886005eek.36 for ; Thu, 28 Jun 2012 08:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=CtkFxXMrXtY7UdcwSMoBMfVZ+QuWmZm6hwsEhN9TTK4=; b=lSkcyO628817SoEKcqHUgTBxaA2ONQc1cdq8CLklzZgKnNyygPlvcVdk9Czt6kAgUA s/A0calDBjyqfQyJwJTFmlecECfcF6Ks6HegwOkq455oENZb3xfC+IWe7lWUz48KETZE vkKwAYYZLvRRaT+uDsXsh/NdpFZosmqGP5R1/VgWUgV0YhaWFjb88uxpJs+zldEUuUEE bZRdmjxss/02cSg00haAIEaIp9nMfTl/fU28cgbs4wv/lronwKuci1AP8bKF2w0rxWjl kgSjsK083ob4Fv7WcUEiyPxIJS4ytCgecSC5eCsloGD1s0xMzn1+YkeGJjP0sKDOaruB RfRA== Received: by 10.14.45.77 with SMTP id o53mr635286eeb.36.1340898450243; Thu, 28 Jun 2012 08:47:30 -0700 (PDT) Received: from perruche.Parrot.Biz (102.213-31-46.rdns.acropolistelecom.net. [46.31.213.102]) by mx.google.com with ESMTPS id m46sm152506871eeh.9.2012.06.28.08.47.28 (version=SSLv3 cipher=OTHER); Thu, 28 Jun 2012 08:47:29 -0700 (PDT) From: Matthieu CASTET To: linux-mtd@lists.infradead.org Subject: [RFC] nand_btt : use nand chip->block_bad Date: Thu, 28 Jun 2012 17:47:22 +0200 Message-Id: <1340898442-1585-1-git-send-email-matthieu.castet@parrot.com> X-Mailer: git-send-email 1.7.10.4 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.83.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (matthieu.castet[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 Cc: Matthieu CASTET X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allow to have only one code for detecting bad block. Also block_bad support badblockbits configuration, for case where there are bitflip in bad block marker. --- drivers/mtd/nand/nand_bbt.c | 102 +------------------------------------------ 1 file changed, 2 insertions(+), 100 deletions(-) diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 30d1319..3d4f6ef 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -123,28 +123,6 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc } /** - * check_short_pattern - [GENERIC] check if a pattern is in the buffer - * @buf: the buffer to search - * @td: search pattern descriptor - * - * Check for a pattern at the given place. Used to search bad block tables and - * good / bad block identifiers. Same as check_pattern, but no optional empty - * check. - */ -static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) -{ - int i; - uint8_t *p = buf; - - /* Compare the pattern */ - for (i = 0; i < td->len; i++) { - if (p[td->offs + i] != td->pattern[i]) - return -1; - } - return 0; -} - -/** * add_marker_len - compute the length of the marker in data area * @td: BBT descriptor used for computation * @@ -398,56 +376,6 @@ static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, return 1; } -/* Scan a given block full */ -static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, - loff_t offs, uint8_t *buf, size_t readlen, - int scanlen, int len) -{ - int ret, j; - - ret = scan_read_raw_oob(mtd, buf, offs, readlen); - /* Ignore ECC errors when checking for BBM */ - if (ret && !mtd_is_bitflip_or_eccerr(ret)) - return ret; - - for (j = 0; j < len; j++, buf += scanlen) { - if (check_pattern(buf, scanlen, mtd->writesize, bd)) - return 1; - } - return 0; -} - -/* Scan a given block partially */ -static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, - loff_t offs, uint8_t *buf, int len) -{ - struct mtd_oob_ops ops; - int j, ret; - - ops.ooblen = mtd->oobsize; - ops.oobbuf = buf; - ops.ooboffs = 0; - ops.datbuf = NULL; - ops.mode = MTD_OPS_PLACE_OOB; - - for (j = 0; j < len; j++) { - /* - * Read the full oob until read_oob is fixed to handle single - * byte reads for 16 bit buswidth. - */ - ret = mtd_read_oob(mtd, offs, &ops); - /* Ignore ECC errors when checking for BBM */ - if (ret && !mtd_is_bitflip_or_eccerr(ret)) - return ret; - - if (check_short_pattern(buf, bd)) - return 1; - - offs += mtd->writesize; - } - return 0; -} - /** * create_bbt - [GENERIC] Create a bad block table by scanning the device * @mtd: MTD device structure @@ -463,30 +391,12 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) { struct nand_chip *this = mtd->priv; - int i, numblocks, len, scanlen; + int i, numblocks; int startblock; loff_t from; - size_t readlen; pr_info("Scanning device for bad blocks\n"); - if (bd->options & NAND_BBT_SCANALLPAGES) - len = 1 << (this->bbt_erase_shift - this->page_shift); - else if (bd->options & NAND_BBT_SCAN2NDPAGE) - len = 2; - else - len = 1; - - if (!(bd->options & NAND_BBT_SCANEMPTY)) { - /* We need only read few bytes from the OOB area */ - scanlen = 0; - readlen = bd->len; - } else { - /* Full page content should be read */ - scanlen = mtd->writesize + mtd->oobsize; - readlen = len * mtd->writesize; - } - if (chip == -1) { /* * Note that numblocks is 2 * (real numblocks) here, see i+=2 @@ -507,20 +417,12 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, from = (loff_t)startblock << (this->bbt_erase_shift - 1); } - if (this->bbt_options & NAND_BBT_SCANLASTPAGE) - from += mtd->erasesize - (mtd->writesize * len); - for (i = startblock; i < numblocks;) { int ret; BUG_ON(bd->options & NAND_BBT_NO_OOB); - if (bd->options & NAND_BBT_SCANALLPAGES) - ret = scan_block_full(mtd, bd, from, buf, readlen, - scanlen, len); - else - ret = scan_block_fast(mtd, bd, from, buf, len); - + ret = this->block_bad(mtd, from, 1); if (ret < 0) return ret;