From: Mike Frysinger Date: Thu, 5 Apr 2012 01:29:18 -0400 Subject: [U-Boot] [PATCH] tools/env: check flash length before probing Message-ID: <1333603758-26498-1-git-send-email-vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@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; -- 1.7.8.5