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: 29477 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A98E1203F3 for ; Thu, 1 May 2014 09:58:18 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id eb12sf15465744oac.11 for ; Thu, 01 May 2014 02:58:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=1plmpYu/PTfcLKWVjA8qG9CccRknnqK+2uoIGW6IyDQ=; b=V02vXiKty/4l/62dhGMDTNlLthN3NRz5UsrYCuRSgoSXWhAN1FRidquRlClDGLPzi4 MNiz1+8Yg/jwIva/gQpwItbhBHAViJq/Ihw02KkA7kS+Jww5Z0SLlgHqcxrgdO44xiKe qyiqyhWcIyncQON3k9pGcHuyEDjPOAZkd/OCeFcvubIUzc9Wro3Ki4WStNNevS7S6xAQ tn3OK6IaeMQfxdYOl/jNjr/j8S19FGsxAPt5nQJSCzhqAcGiHG0l/AsLCWMmdJHBlVpE j3xoK331MsNMuQ4J4yNDaILIJIILnWL9z8N4rT7lkMo6KiByGOULvOzYZ/qxllk9rqvX Lt3g== X-Gm-Message-State: ALoCoQkQgxsbR/Bx1IZhaHqLhNJlmtQcoIwDzWObcM8B8dVnxUnLbbfdHAo5Hdh7lcYa2yxRNqRn X-Received: by 10.42.211.15 with SMTP id gm15mr4625540icb.28.1398938298257; Thu, 01 May 2014 02:58:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.200 with SMTP id 66ls1019872qgf.24.gmail; Thu, 01 May 2014 02:58:18 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr8280534veb.21.1398938298154; Thu, 01 May 2014 02:58:18 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id cq3si5966923vcb.162.2014.05.01.02.58.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:18 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id hq16so3722666vcb.11 for ; Thu, 01 May 2014 02:58:18 -0700 (PDT) X-Received: by 10.52.228.134 with SMTP id si6mr2099805vdc.5.1398938298093; Thu, 01 May 2014 02:58:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12960vcb; Thu, 1 May 2014 02:58:17 -0700 (PDT) X-Received: by 10.180.77.165 with SMTP id t5mr1559483wiw.38.1398938297201; Thu, 01 May 2014 02:58:17 -0700 (PDT) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by mx.google.com with ESMTPS id m11si568500wiw.98.2014.05.01.02.58.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:17 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.169; Received: by mail-wi0-f169.google.com with SMTP id hi5so449785wib.2 for ; Thu, 01 May 2014 02:58:16 -0700 (PDT) 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 Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;