From patchwork Thu May 1 09:56:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 344484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 A2A92140118 for ; Thu, 1 May 2014 20:01:00 +1000 (EST) 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 1Wfnmn-0007FH-1G; Thu, 01 May 2014 10:00:13 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WfnlG-0003O7-Tw for linux-mtd@lists.infradead.org; Thu, 01 May 2014 09:58:39 +0000 Received: by mail-wi0-f178.google.com with SMTP id hm4so403527wib.17 for ; Thu, 01 May 2014 02:58:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1plmpYu/PTfcLKWVjA8qG9CccRknnqK+2uoIGW6IyDQ=; b=nJgsZ3W5aO2ZmaToVqV5aS1aIj9QKqKLGYPd5smGAAejlPv4OxLrPJTBP0wjr2tsEi OhOlHiF59iRIwlvENmVICq1WVNgHR/5MfNYXM5asnMAVxR8Nm/6uEbIus984GaWVAcv9 1dhO+rMw0iUTs2Kg3u9CE3BqnLaSeIoYQXfS9oHd0YDDR9HINF5ULtnus9llUWmNDUj/ KdqBh/rDKTDNdeeW9jiL9m6PBsYtdKXigdUMQorhaMxVQawF+s6Db3cZEP+P3KEQBto7 VgSH8eP5rV3lrzXmWIJMLScFeHKmFahsrPmGb2BB75Yy+EzNRBv9PCQDZgCyaPO+atCT ciUQ== X-Gm-Message-State: ALoCoQm3+JlhxJETGRMCHrkgHcJldiTnDCTf7EO3qmqquo/tSzrGpBL/dr8pjc5ANXgW7OkBIxil X-Received: by 10.180.78.5 with SMTP id x5mr1583349wiw.12.1398938296772; Thu, 01 May 2014 02:58:16 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.58.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:16 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Subject: [PATCH 34/47] mtd: nand: stm_nand_bch: scan block for BBM(s) according to specified BBT options Date: Thu, 1 May 2014 10:56:41 +0100 Message-Id: <1398938214-17847-35-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140501_025839_132326_6A34A146 X-CRM114-Status: GOOD ( 13.97 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.178 listed in list.dnswl.org] Cc: Lee Jones , computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com 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 Search the specified (first and, second or last) page in a block for the BBT. Support Hamming or Advanced Flex Mode (AFM) BBMs too. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 32d2211..7d242ad 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -818,6 +818,66 @@ static int bbt_is_block_bad(uint8_t *bbt, uint32_t block) return bbt_get_block_mark(bbt, block) == BBT_MARK_GOOD ? 0 : 1; } +/* Scan page for BBM(s), according to specified BBT options */ +static int nandi_scan_bad_block_markers_page(struct nandi_controller *nandi, + uint32_t page) +{ + struct mtd_info *mtd = &nandi->info.mtd; + struct nand_chip *chip = mtd->priv; + uint8_t *oob_buf = nandi->oob_buf; + int i, e; + + /* Read the OOB area */ + flex_read_raw(nandi, page, mtd->writesize, oob_buf, mtd->oobsize); + + if (oob_buf[chip->badblockpos] == 0xff) + return 0; + + /* Tolerate 'alien' Hamming Boot Mode ECC */ + e = 0; + for (i = 0; i < mtd->oobsize; i += 16) + e += hweight8(oob_buf[i + 3] ^ 'B'); + if (e <= 1) + return 0; + + /* Tolerate 'alien' Hamming AFM ECC */ + e = 0; + for (i = 0; i < mtd->oobsize; i += 16) { + e += hweight8(oob_buf[i + 3] ^ 'A'); + e += hweight8(oob_buf[i + 4] ^ 'F'); + e += hweight8(oob_buf[i + 5] ^ 'M'); + if (e <= 1) + return 0; + } + + return 1; +} + +/* Scan block for BBM(s), according to specified BBT options */ +static int nandi_scan_bad_block_markers_block(struct nandi_controller *nandi, + uint32_t block) + +{ + struct mtd_info *mtd = &nandi->info.mtd; + struct nand_chip *chip = mtd->priv; + uint32_t pages_per_block = mtd->erasesize >> nandi->page_shift; + uint32_t page = block << (nandi->block_shift - nandi->page_shift); + + if (nandi_scan_bad_block_markers_page(nandi, page)) + return 1; + + if ((chip->bbt_options & NAND_BBT_SCAN2NDPAGE) && + nandi_scan_bad_block_markers_page(nandi, page + 1)) + return 1; + + if ((chip->bbt_options & NAND_BBT_SCANLASTPAGE) && + nandi_scan_bad_block_markers_page(nandi, + page + pages_per_block - 1)) + return 1; + + return 0; +} + /* Populate IBBT BCH Header */ static void bch_fill_ibbt_header(struct nandi_controller *nandi, struct nand_ibbt_bch_header *ibbt_header, @@ -1133,6 +1193,8 @@ static void nandi_set_mtd_defaults(struct nandi_controller *nandi, chip->ecc.layout = &info->ecclayout; chip->options |= NAND_NO_SUBPAGE_WRITE; + chip->bbt_options |= NAND_BBT_USE_FLASH; + /* mtd_info */ mtd->owner = THIS_MODULE; mtd->type = MTD_NANDFLASH;