From patchwork Fri Mar 6 12:12:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rnd4@dave-tech.it X-Patchwork-Id: 447293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C12561400EA for ; Fri, 6 Mar 2015 23:14:20 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTr7i-0003cz-IE; Fri, 06 Mar 2015 12:12:58 +0000 Received: from mx.dave-tech.it ([2.229.21.40]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTr7e-0003Uc-TK for linux-mtd@lists.infradead.org; Fri, 06 Mar 2015 12:12:56 +0000 Received: from linuxserver2.lan.dave.eu (unknown [192.168.0.23]) by mx.dave-tech.it (Postfix) with ESMTP id 7406896; Fri, 6 Mar 2015 13:12:20 +0100 (CET) From: rnd4@dave-tech.it To: linux-mtd@lists.infradead.org Subject: [PATCH 2/2] mtd: nand: use nand_chip badblockbits when checking bad block pattern Date: Fri, 6 Mar 2015 13:12:18 +0100 Message-Id: <1425643938-24749-3-git-send-email-rnd4@dave-tech.it> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1425643938-24749-1-git-send-email-rnd4@dave-tech.it> References: <1425643938-24749-1-git-send-email-rnd4@dave-tech.it> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150306_041255_212291_2D47D515 X-CRM114-Status: GOOD ( 14.17 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: boris.brezillon@free-electrons.com, Andrea Scian X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 From: Andrea Scian Use nand_chip->badblockbits like it's used inside nand_base.c when scanning bad block markers. This is particularly useful when using MLC NAND Signed-off-by: Andrea Scian --- drivers/mtd/nand/nand_bbt.c | 19 ++++++++++++++++--- include/linux/mtd/bbm.h | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 2672643..dba7f8b 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -127,9 +127,21 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc */ static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) { - /* Compare the pattern */ - if (memcmp(buf + td->offs, td->pattern, td->len)) - return -1; + if (likely(td->toleratedbitdiff == 0)) { + /* Compare the pattern */ + if (memcmp(buf + td->offs, td->pattern, td->len)) + return -1; + } else { + int i, nbitdiff = 0; + uint8_t tmp; + + for (i = 0; i < td->len; i++) { + tmp = buf[td->offs + i] ^ td->pattern[i]; + nbitdiff += hweight8(tmp); + if (nbitdiff > td->toleratedbitdiff) + return -1; + } + } return 0; } @@ -1309,6 +1321,7 @@ static int nand_create_badblock_pattern(struct nand_chip *this) bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1; bd->pattern = scan_ff_pattern; bd->options |= NAND_BBT_DYNAMICSTRUCT; + bd->toleratedbitdiff = 8-this->badblockbits; this->badblock_pattern = bd; return 0; } diff --git a/include/linux/mtd/bbm.h b/include/linux/mtd/bbm.h index 211ff67..0714337 100644 --- a/include/linux/mtd/bbm.h +++ b/include/linux/mtd/bbm.h @@ -48,6 +48,8 @@ * bad) block in the stored bbt * @pattern: pattern to identify bad block table or factory marked good / * bad blocks, can be NULL, if len = 0 + * @toleratedbitdiff: number of tolerated bit difference (in a byte) between + * pattern and buffer * * Descriptor for the bad block table marker and the descriptor for the * pattern which identifies good and bad blocks. The assumption is made @@ -64,6 +66,7 @@ struct nand_bbt_descr { int maxblocks; int reserved_block_code; uint8_t *pattern; + int toleratedbitdiff; }; /* Options for the bad block table descriptors */