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 <[email protected]>
Signed-off-by: Mike Frysinger <[email protected]>
---
 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

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to