From patchwork Thu May 1 09:56:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29479 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 14088203F3 for ; Thu, 1 May 2014 09:58:22 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id s7sf7942807qap.0 for ; Thu, 01 May 2014 02:58:21 -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=H94a0mDNWCuJIUwk3V3C7HOqGrYfWF9LCB0p6SGlBpA=; b=cmcRZwUGjA5EvTppWNHMI2A2P5IngMYxkHzsxvEnzWr3EFglwi8B0UelZhLa8+nfp4 TapudxZpCR3HtT2YGrpEqsSc+rq0YbHLaSvFK6spaccwE9SmtHiM0K0DkINoqHRzlW12 SUYNKA/YcGwi8+VwVmIUibqgBoPISUdQMG5MXXmrjoKR+A+5UjmLbjTxzgXRA4ngOqUe IFNY80FKFVtTTs2tGDNpO4ybwkT/fRMx6aAMRS4fuo/qs03KzHi5drhAb1czf063CPce yd6CWE0eW1te9CNqO1QDAJtMkJXdWyIJcQsxvsEmNWBT4uxVJ9apJXZyg0BOw8HcFGeE od0w== X-Gm-Message-State: ALoCoQnWdnZHxYBrFAgDhvQ8q5FqSLtUtZZPD+qHg1j0wGYg6xy5vb0Nm+W3lF4SDr0Sk0IEtOFx X-Received: by 10.236.206.15 with SMTP id k15mr4345742yho.44.1398938301885; Thu, 01 May 2014 02:58:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.225 with SMTP id f88ls965726qgf.65.gmail; Thu, 01 May 2014 02:58:21 -0700 (PDT) X-Received: by 10.52.164.237 with SMTP id yt13mr6907873vdb.18.1398938301749; Thu, 01 May 2014 02:58:21 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id rn1si5964282vec.186.2014.05.01.02.58.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:21 -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.128.172; Received: by mail-ve0-f172.google.com with SMTP id jy13so3673780veb.3 for ; Thu, 01 May 2014 02:58:21 -0700 (PDT) X-Received: by 10.53.1.69 with SMTP id be5mr6756118vdd.27.1398938301682; Thu, 01 May 2014 02:58:21 -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 ib8csp12966vcb; Thu, 1 May 2014 02:58:21 -0700 (PDT) X-Received: by 10.194.82.9 with SMTP id e9mr8076630wjy.45.1398938300564; Thu, 01 May 2014 02:58:20 -0700 (PDT) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by mx.google.com with ESMTPS id ci9si186751wjc.154.2014.05.01.02.58.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:20 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.180; Received: by mail-wi0-f180.google.com with SMTP id hi2so405767wib.7 for ; Thu, 01 May 2014 02:58:20 -0700 (PDT) X-Received: by 10.194.63.196 with SMTP id i4mr1409799wjs.50.1398938300052; Thu, 01 May 2014 02:58:20 -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.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:58:19 -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 36/47] mtd: nand: stm_nand_bch: search for and load flash-resident BBT Date: Thu, 1 May 2014 10:56:43 +0100 Message-Id: <1398938214-17847-37-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: , If a BBT already exists in flash, it's this function's task to locate it and load it into the driver for local consumption. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 1569738..2df452b 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -1148,6 +1148,93 @@ static int bch_find_ibbt_sig(struct nandi_controller *nandi, return 1; } +/* Search for and load Flash-resident BBT, updating Primary/Mirror if req'd */ +static int bch_load_bbt(struct nandi_controller *nandi, + struct nandi_bbt_info *bbt_info) +{ + unsigned int update = 0; + uint32_t block; + loff_t offs; + uint8_t vers; + char author[64]; + int bak; + + dev_dbg(nandi->dev, "looking for Flash-resident BBTs\n"); + + bbt_info->bbt_block[0] = 0; + bbt_info->bbt_block[1] = 0; + bbt_info->bbt_vers[0] = 0; + bbt_info->bbt_vers[1] = 0; + + /* Look for IBBT signatures */ + for (block = nandi->blocks_per_device - NAND_IBBT_NBLOCKS; + block < nandi->blocks_per_device; + block++) { + offs = (loff_t)block << nandi->block_shift; + + if (bch_find_ibbt_sig(nandi, block, &bak, &vers, author)) { + dev_dbg(nandi->dev, + "found BBT [%s:%u] at 0x%012llx [%u] (%s)\n", + bbt_strs[bak], vers, offs, block, + author); + + if (bbt_info->bbt_block[bak] == 0 || + ((int8_t)(bbt_info->bbt_vers[bak] - vers)) < 0) { + bbt_info->bbt_block[bak] = block; + bbt_info->bbt_vers[bak] = vers; + } + } + } + + /* What have we found? */ + if (bbt_info->bbt_block[0] == 0 && bbt_info->bbt_block[1] == 0) { + /* no primary, no mirror: return error */ + return 1; + } else if (bbt_info->bbt_block[0] == 0) { + /* no primary: use mirror, update primary */ + bak = 1; + update = NAND_IBBT_UPDATE_PRIMARY; + bbt_info->bbt_block[0] = nandi->blocks_per_device - 1; + } else if (bbt_info->bbt_block[1] == 0) { + /* no mirror: use primary, update mirror */ + bak = 0; + update = NAND_IBBT_UPDATE_MIRROR; + bbt_info->bbt_block[1] = nandi->blocks_per_device - 1; + } else if (bbt_info->bbt_vers[0] == bbt_info->bbt_vers[1]) { + /* primary == mirror: use primary, no update required */ + bak = 0; + } else if ((int8_t)(bbt_info->bbt_vers[1] - + bbt_info->bbt_vers[0]) < 0) { + /* primary > mirror: use primary, update mirror */ + bak = 0; + update = NAND_IBBT_UPDATE_MIRROR; + } else { + /* mirror > primary: use mirror, update primary */ + bak = 1; + update = NAND_IBBT_UPDATE_PRIMARY; + } + + vers = bbt_info->bbt_vers[bak]; + block = bbt_info->bbt_block[bak]; + offs = block << nandi->block_shift; + dev_info(nandi->dev, "using BBT [%s:%u] at 0x%012llx [%u]\n", + bbt_strs[bak], vers, offs, block); + + /* Read BBT data */ + if (bch_read_page(nandi, offs, bbt_info->bbt) < 0) { + dev_err(nandi->dev, + "error while reading BBT %s:%u] at 0x%012llx [%u]\n", + bbt_strs[bak], vers, offs, block); + return 1; + } + + /* Update other BBT if required */ + if (update) + bch_update_bbts(nandi, bbt_info, update, vers); + + return 0; +} + /* * Initialisation */