From patchwork Thu May 1 09:56:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29470 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3F07B203F3 for ; Thu, 1 May 2014 09:58:06 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id sa20sf10115834veb.0 for ; Thu, 01 May 2014 02:58:06 -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=JPpFIqRIW8UaumMNmGHv0nvqlglmmADRYRJC/la/6Co=; b=LVl82+1DQnMy1Stkeew+IA5K5hdxZcScZXSdRPsiDIivNRpph5OJpb8NMFJ9Gqv6vQ jaAvjCD4m7IPFcCBiJP7n5kpUWIOkzz90UO3fcmPaj5b3usaJf1EhHoRF2PSXvObHrub evxhr8/JxtZCRXZC4xchjr+oM6ydrL2lw+z+wT3ohlzXg8goujscYiKLNSzv+n+pRC4H eTwwSpMaoRXm8/tPx9uHVRH0GlA/1nn0FPY3vjulofhQ0+kFrOg1hZyaeyPc0X9IMpOs 9pj90BhvPhQ5g49u5FvVt5aOuKRfrxKpzigfSx+k+4MWGzpuuftjkghDvvqwhcnlNP/1 q3vg== X-Gm-Message-State: ALoCoQm8IGhyAf1Ri8HgzKnXptOYXEuZqStOi/1LnseIz2VdAMQa5ipu4DyVNmeqc5j7qpTSJ6v7 X-Received: by 10.58.196.209 with SMTP id io17mr5306457vec.7.1398938286017; Thu, 01 May 2014 02:58:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.170 with SMTP id p39ls983835qgd.49.gmail; Thu, 01 May 2014 02:58:05 -0700 (PDT) X-Received: by 10.52.229.97 with SMTP id sp1mr6788886vdc.23.1398938285930; Thu, 01 May 2014 02:58:05 -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 z6si5967525vcm.9.2014.05.01.02.58.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:05 -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.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so3632406vcb.24 for ; Thu, 01 May 2014 02:58:05 -0700 (PDT) X-Received: by 10.220.69.72 with SMTP id y8mr8129070vci.21.1398938285853; Thu, 01 May 2014 02:58:05 -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 ib8csp12947vcb; Thu, 1 May 2014 02:58:05 -0700 (PDT) X-Received: by 10.180.78.225 with SMTP id e1mr1488969wix.17.1398938284984; Thu, 01 May 2014 02:58:04 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by mx.google.com with ESMTPS id el7si583431wib.8.2014.05.01.02.58.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:04 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.177; Received: by mail-wi0-f177.google.com with SMTP id cc10so403826wib.10 for ; Thu, 01 May 2014 02:58:04 -0700 (PDT) X-Received: by 10.180.89.241 with SMTP id br17mr1593980wib.0.1398938284450; Thu, 01 May 2014 02:58:04 -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.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:03 -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 27/47] mtd: nand: stm_nand_bch: find IBBT signature Date: Thu, 1 May 2014 10:56:34 +0100 Message-Id: <1398938214-17847-28-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: , 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 e875446..83faffe 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 */ @@ -681,6 +712,66 @@ static int bch_write(struct mtd_info *mtd, struct nand_chip *chip, return 0; } +/* 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 */