From patchwork Thu Apr 5 05:29:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 150867 X-Patchwork-Delegate: joe.hershberger@gmail.com 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 28AEBB6FCF for ; Thu, 5 Apr 2012 15:29:08 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 17E50280FE; Thu, 5 Apr 2012 07:29:06 +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 2VR3a9VZUOm7; Thu, 5 Apr 2012 07:29:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 960A4280FF; Thu, 5 Apr 2012 07:29:03 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AF63D280FF for ; Thu, 5 Apr 2012 07:29:01 +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 X4YbQOUFcGAA for ; Thu, 5 Apr 2012 07:29:01 +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 smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by theia.denx.de (Postfix) with ESMTPS id F1A7E280FE for ; Thu, 5 Apr 2012 07:28:59 +0200 (CEST) Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 98E301B4032 for ; Thu, 5 Apr 2012 05:28:53 +0000 (UTC) From: Mike Frysinger To: u-boot@lists.denx.de Date: Thu, 5 Apr 2012 01:29:18 -0400 Message-Id: <1333603758-26498-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 1.7.8.5 Subject: [U-Boot] [PATCH] tools/env: check flash length before probing 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de If we attempt to probe beyond the end of flash, MEMGETBADBLOCK will fail (as well it should), but we end up erroring out with the distracting: Cannot read bad block mark: Invalid argument Instead of the correct error: Too few good blocks within range Re-order the tests so we check for the end of the flash before probing so we don't probe blocks that don't exist. Reported-by: Mark Bishop Signed-off-by: Mike Frysinger --- tools/env/fw_env.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index e292d2b..d0fbbb0 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -712,10 +712,6 @@ static int flash_read_buf (int dev, int fd, void *buf, size_t count, /* This only runs once on NOR flash */ while (processed < count) { - rc = flash_bad_block (fd, mtd_type, &blockstart); - if (rc < 0) /* block test failed */ - return -1; - if (blockstart + block_seek + readlen > top_of_range) { /* End of range is reached */ fprintf (stderr, @@ -723,6 +719,10 @@ static int flash_read_buf (int dev, int fd, void *buf, size_t count, return -1; } + rc = flash_bad_block (fd, mtd_type, &blockstart); + if (rc < 0) /* block test failed */ + return -1; + if (rc) { /* block is bad */ blockstart += blocklen; continue; @@ -845,15 +845,15 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, /* This only runs once on NOR flash and SPI-dataflash */ while (processed < write_total) { - rc = flash_bad_block (fd, mtd_type, &blockstart); - if (rc < 0) /* block test failed */ - return rc; - if (blockstart + erasesize > top_of_range) { fprintf (stderr, "End of range reached, aborting\n"); return -1; } + rc = flash_bad_block (fd, mtd_type, &blockstart); + if (rc < 0) /* block test failed */ + return rc; + if (rc) { /* block is bad */ blockstart += blocklen; continue;