From: Dustin Byford Date: Fri, 7 Mar 2014 04:48:23 +0000 (-0800) Subject: fw_env: correct writes to devices with small erase blocks X-Git-Tag: v2014.04-rc3~84 X-Git-Url: https://git.kernelconcepts.de/?p=karo-tx-uboot.git;a=commitdiff_plain;h=4b774ff114201175ea9c05dfa12eef3ff1704753 fw_env: correct writes to devices with small erase blocks 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 --- diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 649db0493a..d228cc34da 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -863,9 +863,9 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, if (mtd_type != MTD_ABSENT) ioctl(fd, MEMLOCK, &erase); - processed += blocklen; + processed += erasesize; block_seek = 0; - blockstart += blocklen; + blockstart += erasesize; } if (write_total > count)