mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-23 05:08:24 +00:00
fw_env: keep calling read() until whole flash block is read
It's totally valid for read() to provide less bytes than requested maximum. It may happen if there is no more data available yet or source pushes data in small chunks. This actually happens when trying to read env data from NVMEM device. Kernel may provide NVMEM content in page size parts (like 4096 B). This fixes warnings like: Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 16384 bytes but got 4096 Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 12288 bytes but got 4096 Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 8192 bytes but got 4096 Since the main loop in flash_read_buf() is used to read blocks this patch adds a new nested one. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
parent
73b30800f5
commit
9e3003f79d
1 changed files with 15 additions and 19 deletions
10
tools/env/fw_env.c
vendored
10
tools/env/fw_env.c
vendored
|
@ -948,6 +948,7 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
|
||||||
*/
|
*/
|
||||||
lseek(fd, blockstart + block_seek, SEEK_SET);
|
lseek(fd, blockstart + block_seek, SEEK_SET);
|
||||||
|
|
||||||
|
while (readlen) {
|
||||||
rc = read(fd, buf + processed, readlen);
|
rc = read(fd, buf + processed, readlen);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
fprintf(stderr, "Read error on %s: %s\n",
|
fprintf(stderr, "Read error on %s: %s\n",
|
||||||
|
@ -960,18 +961,13 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
|
||||||
DEVNAME(dev));
|
DEVNAME(dev));
|
||||||
#endif
|
#endif
|
||||||
processed += rc;
|
processed += rc;
|
||||||
if (rc != readlen) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"Warning on %s: Attempted to read %zd bytes but got %d\n",
|
|
||||||
DEVNAME(dev), readlen, rc);
|
|
||||||
readlen -= rc;
|
readlen -= rc;
|
||||||
block_seek += rc;
|
}
|
||||||
} else {
|
|
||||||
blockstart += blocklen;
|
blockstart += blocklen;
|
||||||
readlen = min(blocklen, count - processed);
|
readlen = min(blocklen, count - processed);
|
||||||
block_seek = 0;
|
block_seek = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue