From patchwork Tue Mar 25 08:19: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: 27012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB47E20062 for ; Tue, 25 Mar 2014 08:47:56 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id j17sf608987oag.2 for ; Tue, 25 Mar 2014 01:47:56 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=acE9xMooklNKUp/wfRZQ0bpekC1PV2M51F4UPKphLcY=; b=kkf2WFtdfVDtVYMeqNc7qyvXHnL5hDlTlg85RGLxyW6WNPxFJJb8SC6I4vcsWRoDKL Fkpi8q9bMhpJ2dAD9SVkRYdqJhodES9DlVpZFW2m3tTxkgedcp16jwOOdQ6WcX4O/pYS EOAfAJzFEIvnPSBLf49bSZswiIX4ZETqqf7IsVs1uSxlm9DhaGlWZrPVe0Fd/Op7S3yo HHlTawLsV6aRCAT+FkRAe2IUqOPY/xxKobfamTsks6alCA2SOd+3sNu/9qJYSDmwrHmc U3C3EsXsv0xJVR9b8a/DIdBjcumVgYEVLat4gypz5Q/Q8pN6n6ujXZMQI5RS+FG3ZS1q d57g== X-Gm-Message-State: ALoCoQkn1nJeoY2zDMgUG1JlV26K4Ses/3xgLuiejSD8zQuX0WetK5R7/PhC/i+g7If9dIqH5Ohb X-Received: by 10.182.104.70 with SMTP id gc6mr14059691obb.35.1395737276455; Tue, 25 Mar 2014 01:47:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.81 with SMTP id r75ls108467qga.71.gmail; Tue, 25 Mar 2014 01:47:56 -0700 (PDT) X-Received: by 10.220.191.134 with SMTP id dm6mr55138761vcb.16.1395737276378; Tue, 25 Mar 2014 01:47:56 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id od9si3550310vcb.65.2014.03.25.01.47.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:47:56 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so154971vcb.24 for ; Tue, 25 Mar 2014 01:47:56 -0700 (PDT) X-Received: by 10.52.165.105 with SMTP id yx9mr46238218vdb.22.1395737276310; Tue, 25 Mar 2014 01:47:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp286734vck; Tue, 25 Mar 2014 01:47:55 -0700 (PDT) X-Received: by 10.67.2.34 with SMTP id bl2mr76968325pad.58.1395737274583; Tue, 25 Mar 2014 01:47:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si10904274pbn.317.2014.03.25.01.47.24; Tue, 25 Mar 2014 01:47:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754470AbaCYIrN (ORCPT + 26 others); Tue, 25 Mar 2014 04:47:13 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:58575 "EHLO mail-we0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752957AbaCYIVE (ORCPT ); Tue, 25 Mar 2014 04:21:04 -0400 Received: by mail-we0-f169.google.com with SMTP id w62so80393wes.14 for ; Tue, 25 Mar 2014 01:21:03 -0700 (PDT) X-Received: by 10.180.37.12 with SMTP id u12mr20404612wij.0.1395735663657; Tue, 25 Mar 2014 01:21:03 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id k4sm5567676wib.19.2014.03.25.01.21.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:21:02 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, dwmw2@infradead.org, angus.clark@st.com, pekon@ti.com Subject: [RFC 24/47] mtd: nand: stm_nand_bch: find IBBT signature Date: Tue, 25 Mar 2014 08:19:41 +0000 Message-Id: <1395735604-26706-25-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> References: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.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: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Scan block for IBBT signature, either "Bbt0" or "1tbB" from pre-specified data block. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 6323590..5bcaabbc 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -43,6 +43,37 @@ static int bch_ecc_sizes[] = { [BCH_NO_ECC] = 0, }; +/* + * Inband Bad Block Table (IBBT) + */ +#define NAND_IBBT_NBLOCKS 4 +#define NAND_IBBT_SIGLEN 4 +#define NAND_IBBT_PRIMARY 0 +#define NAND_IBBT_MIRROR 1 +#define NAND_IBBT_SCHEMA 0x10 +#define NAND_IBBT_BCH_SCHEMA 0x10 + +static uint8_t ibbt_sigs[2][NAND_IBBT_SIGLEN] = { + {'B', 'b', 't', '0'}, + {'1', 't', 'b', 'B'}, +}; + +/* IBBT header */ +struct nand_ibbt_header { + uint8_t signature[4]; /* "Bbt0" or "1tbB" signature */ + uint8_t version; /* BBT version ("age") */ + uint8_t reserved[3]; /* padding */ + uint8_t schema[4]; /* "base" schema (x4) */ +} __packed; + +/* Extend IBBT header with some stm-nand-bch niceties */ +struct nand_ibbt_bch_header { + struct nand_ibbt_header base; + uint8_t schema[4]; /* "private" schema (x4) */ + uint8_t ecc_size[4]; /* ECC bytes (0, 32, 54) (x4) */ + char author[64]; /* Arbitrary string for S/W to use */ +} __packed; + /* Bad Block Table (BBT) */ struct nandi_bbt_info { uint32_t bbt_size; /* Size of bad-block table */ @@ -464,6 +495,66 @@ static uint8_t bch_write_page(struct nandi_controller *nandi, return status; } +/* Scan block for IBBT signature */ +static int bch_find_ibbt_sig(struct nandi_controller *nandi, + uint32_t block, int *bak, uint8_t *vers, + char *author) +{ + struct mtd_info *mtd = &nandi->info.mtd; + struct nand_ibbt_bch_header *ibbt_header; + loff_t offs; + uint8_t *buf = nandi->page_buf; + int match_sig; + unsigned int b; + unsigned int i; + + nandi->cached_page = -1; + + /* Load last page of block */ + offs = (loff_t)block << nandi->block_shift; + offs += mtd->erasesize - mtd->writesize; + if (bch_read_page(nandi, offs, buf) < 0) { + dev_info(nandi->dev, + "Uncorrectable ECC error while scanning BBT signature at block %u [0x%012llx]\n", + block, offs); + return 0; + } + ibbt_header = (struct nand_ibbt_bch_header *)buf; + + /* Test IBBT signature */ + match_sig = 0; + for (b = 0; b < 2 && !match_sig; b++) { + match_sig = 1; + for (i = 0; i < NAND_IBBT_SIGLEN; i++) { + if (ibbt_header->base.signature[i] != ibbt_sigs[b][i]) { + match_sig = 0; + break; + } + } + + } + + if (!match_sig) + return 0; /* Failed to match IBBT signature */ + + /* Test IBBT schema */ + for (i = 0; i < 4; i++) + if (ibbt_header->base.schema[i] != NAND_IBBT_SCHEMA) + return 0; + + /* Test IBBT BCH schema */ + for (i = 0; i < 4; i++) + if (ibbt_header->schema[i] != NAND_IBBT_BCH_SCHEMA) + return 0; + + /* We have a match */ + *vers = ibbt_header->base.version; + *bak = b - 1; + strncpy(author, ibbt_header->author, 64); + + return 1; +} + /* * Initialisation */