Some NOR flash devices have a small erase block size. For example, the
Micron N25Q512 can erase in 4K blocks. These devices expose a bug in
fw_env.c where flash_write_buf() incorrectly calculates bytes written
and attempts to write past the environment sectors. Luckily, a range
check prevents any real damage, but this does cause fw_setenv to fail
with an error.
This change corrects the write length calculation.
The bug was introduced with commit
56086921 from 2008 and only affects
configurations where the erase block size is smaller than the total
environment data size.
Signed-off-by: Dustin Byford <dustin@cumulusnetworks.com>
if (mtd_type != MTD_ABSENT)
ioctl(fd, MEMLOCK, &erase);
- processed += blocklen;
+ processed += erasesize;
block_seek = 0;
- blockstart += blocklen;
+ blockstart += erasesize;
}
if (write_total > count)