From patchwork Fri Jun 21 05:09:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 253131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B9C732C00A6 for ; Fri, 21 Jun 2013 15:09:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A486B4A0BD; Fri, 21 Jun 2013 07:09:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zhdwVeLTcy+X; Fri, 21 Jun 2013 07:09:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5EA2C4A0A6; Fri, 21 Jun 2013 07:09:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 824914A0A6 for ; Fri, 21 Jun 2013 07:09:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xvVo4Bibp9oD for ; Fri, 21 Jun 2013 07:09:28 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from pollux.denx.de (host-82-135-33-74.customer.m-online.net [82.135.33.74]) by theia.denx.de (Postfix) with ESMTP id 60AF04A095 for ; Fri, 21 Jun 2013 07:09:21 +0200 (CEST) Received: by pollux.denx.de (Postfix, from userid 515) id C48001A02; Fri, 21 Jun 2013 07:09:20 +0200 (CEST) From: Heiko Schocher To: u-boot@lists.denx.de Date: Fri, 21 Jun 2013 07:09:18 +0200 Message-Id: <1371791358-13066-1-git-send-email-hs@denx.de> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1371445261-3785-1-git-send-email-hs@denx.de> References: <1371445261-3785-1-git-send-email-hs@denx.de> MIME-Version: 1.0 Cc: Marek Vasut , Pantelis Antoniou , Tom Rini , Kyungmin Park , Scott Wood , Heiko Schocher Subject: [U-Boot] =?utf-8?q?=5BPATCH_v3=5D_dfu=2C_nand=3A_before_write_a_b?= =?utf-8?q?uffer_to_nand=2C_erase_the_nand_sectors?= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de before writing the received buffer to nand, erase the nand sectors. If not doing this, nand write fails. See for more info here: http://lists.denx.de/pipermail/u-boot/2013-June/156361.html Using the nand erase option "spread", maybe overwrite blocks on, for example another mtd partition, if the erasing range contains bad blocks. So a limit option is added to nand_erase_opts() Signed-off-by: Heiko Schocher Cc: Scott Wood Cc: Pantelis Antoniou Cc: Lukasz Majewski Cc: Kyungmin Park Cc: Marek Vasut Cc: Tom Rini --- - changes for v2: - use opts.spread as Scott Wood suggested - changes for v3: - add opts.lim as Scott Wood suggested drivers/dfu/dfu_nand.c | 18 ++++++++++++++++-- drivers/mtd/nand/nand_util.c | 4 ++++ include/nand.h | 2 ++ 3 Dateien geändert, 22 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-) diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index 7dc89b2..07dee89 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -63,12 +63,26 @@ static int nand_block_op(enum dfu_nand_op op, struct dfu_entity *dfu, nand = &nand_info[nand_curr_device]; - if (op == DFU_OP_READ) + if (op == DFU_OP_READ) { ret = nand_read_skip_bad(nand, start, &count, &actual, lim, buf); - else + } else { + nand_erase_options_t opts; + + memset(&opts, 0, sizeof(opts)); + opts.offset = start; + opts.length = count; + opts.spread = 1; + opts.quiet = 1; + opts.lim = lim; + /* first erase */ + ret = nand_erase_opts(nand, &opts); + if (ret) + return ret; + /* then write */ ret = nand_write_skip_bad(nand, start, &count, &actual, lim, buf, 0); + } if (ret != 0) { printf("%s: nand_%s_skip_bad call failed at %llx!\n", diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c index d81972c..2778f7f 100644 --- a/drivers/mtd/nand/nand_util.c +++ b/drivers/mtd/nand/nand_util.c @@ -120,6 +120,10 @@ int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts) WATCHDOG_RESET(); + if (opts->lim && (erase.addr > (opts->offset + opts->lim))) { + puts("Size of erase exceeds limit\n"); + return -EFBIG; + } if (!opts->scrub && bbtest) { int ret = mtd_block_isbad(meminfo, erase.addr); if (ret > 0) { diff --git a/include/nand.h b/include/nand.h index 26190e4..228d871 100644 --- a/include/nand.h +++ b/include/nand.h @@ -125,6 +125,8 @@ struct nand_erase_options { /* Don't include skipped bad blocks in size to be erased */ int spread; + /* maximum size that actual may be in order to not exceed the buf */ + loff_t lim; }; typedef struct nand_erase_options nand_erase_options_t;