[U-Boot] fw_env bug for multi-sector environments on NOR flash

Hi,
I am storing u-boot environment variables on a NOR flash using two sectors. I encountered an error when writing changes using fw_setenv.
/etc # cat fw_env.config # Configuration file for fw_(printenv/saveenv) utility. # Up to two entries are valid, in this case the redundand # environment sector is assumed present. # MTD device name Device offset Env. size Flash sector size Number of sectors /dev/mtd12 0x0000 0x20000 0x10000 2
/etc # fw_setenv test test End of range reached, aborting Error: can't write fw_env to flash
The reason for the error is that although both sectors are written in one pass, the loop for the write is executed twice because the "processed" variable is incremented by the incorrect amount. The following change is needed to fix this issue for NOR multi-sector environments.
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index ed6b53f..e6b2cae 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -880,9 +880,8 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
ioctl (fd, MEMLOCK, &erase);
- processed += blocklen; - block_seek = 0; - blockstart += blocklen; + processed += erasesize; + blockstart += erasesize; }
if (write_total > count)
Are there any objections to committing this change?
Yiyang Fei

Dear "Fei, Yiyang",
In message C2A5D1386C6DB94198F2A5C8368EAE6C14659846@DULMEX02.barco.com you wrote:
# MTD device name Device offset Env. size Flash sector size Number of sectors /dev/mtd12 0x0000 0x20000 0x10000 2
Stupid question: why do you define an environment size of 128 kB? I bet you use less than 10% of this, right?
Are you aware that this has a lof of disadvantages, lile significantly slowing down your boot process?
The reason for the error is that although both sectors are written in one pass, the loop for the write is executed twice because the "processed" variable is incremented by the incorrect amount. The following change is needed to fix this issue for NOR multi-sector environments.
...
Are there any objections to committing this change?
Your Signed-off-by: line is missing...
Best regards,
Wolfgang Denk

Dear Mr. Denk,
Stupid question: why do you define an environment size of 128 kB? I bet you use less than 10% of this, right?
Correct
Are you aware that this has a lof of disadvantages, lile significantly slowing down your boot process?
I am now, but the first product is already released and cannot be changed easily.
Your Signed-off-by: line is missing...
I resubmitted updated message.
Best regards, Yiyang Fei
participants (2)
-
Fei, Yiyang
-
Wolfgang Denk