tools/env: check flash length before probing
PATCH 1/1 tools/env: check flash length before probing
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.
--- tools/env/fw_env.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
tools/env/fw_env.c +8 -8
@@ -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 ;
Signature · 1 line
1.7.8.5
Bishop
PATCH 1/1 tools/env: check flash length before probing
Quoted 14 lines
-----Original Message-----
From: u-boot-bounces at lists.denx.de [mailto:u-boot- bounces at lists.denx.de] On Behalf Of Mike Frysinger
Sent: Thursday, April 05, 2012 1:29 AM
To: u-boot at lists.denx.de
Subject: [U-Boot] [PATCH]tools/env: check flash length before probingIf 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
Quoted 6 lines
Instead of the correct error:
Too few good blocks within rangeRe-order the tests so we check for the end of the flash before probing so we don't probe blocks that don't exist.
Applied the patch:
root:/bin> fw_printenv
Too few good blocks within range
root:/bin> strace fw_printenv
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0open("/etc/fw_env.config", O_RDONLY) = 3ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x2d9ccb4) = -1 ENOTTY (Inappropriate ioctl for device) mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x2d55000 read(3, "# Configuration file for fw_(pri"..., 256) = 256 read(3, "Flash sector size\tNumber of sect"..., 256) = 163read(3, "", 256) = 0
close(3) = 0stat("/dev/mtd0", {st_mode=S_IFCHR|0660, st_rdev=makedev(90, 0), ...}) = 0mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x2e00000open("/dev/mtd0", O_RDONLY) = 3
ioctl(3, MEMGETINFO or MFB_SET_CHROMA_KEY, {type=MTD_NANDFLASH, flags=MTD_WRITEABLE, size=0x80000, erasesize=0x20000, writesize=0x800, oobsize=0x40, padding=0xffffffff}) = 0ioctl(3, MEMGETBADBLOCK, [393216]) = 1
write(2, "Too few good blocks within range"..., 33Too few good blocks within range
) = 33
close(3) = 0_exit(1) = ?
root:/bin>
PATCH 1/1 tools/env: check flash length before probing
Quoted 10 lines · Mark
From: Mike Frysinger
Quoted 9 lines
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 argumentInstead of the correct error:
Too few good blocks within range
Quoted 7 lines
Quoted 2 lines
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.
Applied the patch:
root:/bin>
fw_printenv
Too few good blocks within range
good -- that's what should be displayed. i had to hack up my local printenv for testing against /dev/zero and had to guess at the results :).
Quoted 1 line
ioctl(3, MEMGETBADBLOCK, [393216])= 1
this is what we need to root cause. but let's do it in the existing thread. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120405/8c1365a2/attachment.pgp>
PATCH 1/1 tools/env: check flash length before probing
In reply to Mike FrysingerQuoted 9 lines · On Thursday 05 April 2012 01:29:18 Mike Frysinger wrote:
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 argumentInstead of the correct error:
Too few good blocks within rangeRe-order the tests so we check for the end of the flash before probing so we don't probe blocks that don't exist.
this should be an easy one to pick up :)
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120721/24b870e6/attachment.pgp>