aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Ferrante2021-08-24 17:29:50 +0200
committerTom Rini2021-09-02 11:19:58 -0400
commit6628813f9d400c49da4926f01833063a30151cdb (patch)
treec3f4646963db0c7010ca32b024b6947f4f144d9f
parent7befc8490a008c332633e693f2adfab38d8d50f2 (diff)
tools: env: Handle shorter read calls
On some cases, the actual number of bytes read can be shorter than what was requested. This can be handled gracefully by taking this difference into account instead of exiting. Signed-off-by: Thibault Ferrante <thibault.ferrante@gmail.com>
-rw-r--r--tools/env/fw_env.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 2a61a5d6f04..e39c39e23a1 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -951,21 +951,23 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
DEVNAME(dev), strerror(errno));
return -1;
}
- if (rc != readlen) {
- fprintf(stderr,
- "Read error on %s: Attempted to read %zd bytes but got %d\n",
- DEVNAME(dev), readlen, rc);
- return -1;
- }
#ifdef DEBUG
fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n",
rc, (unsigned long long)blockstart + block_seek,
DEVNAME(dev));
#endif
- processed += readlen;
- readlen = min(blocklen, count - processed);
- block_seek = 0;
- blockstart += blocklen;
+ 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;
+ block_seek += rc;
+ } else {
+ blockstart += blocklen;
+ readlen = min(blocklen, count - processed);
+ block_seek = 0;
+ }
}
return processed;