* [PATCH 0/1] tools: env: Handle shorter read calls
@ 2021-08-24 15:29 Thibault Ferrante
2021-08-24 15:29 ` [PATCH 1/1] " Thibault Ferrante
0 siblings, 1 reply; 3+ messages in thread
From: Thibault Ferrante @ 2021-08-24 15:29 UTC (permalink / raw)
To: u-boot
Cc: wd, joe.hershberger, hws, alex.kiernan, lg, Thibault Ferrante,
Martin Hundebøll
On specific devices, read can return less bytes than expected.
I noticed this problem on a EEPROM chip with 16Kbyte of memory. Defining
an environment with more than 4Kbyte leads to less bytes read than expected
and failures from fw_printenv/fw_setenv.
This patch target to handle this issue by doing multiple reads instead
of exiting directly.
Thibault Ferrante (1):
tools: env: Handle shorter read calls
tools/env/fw_env.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] tools: env: Handle shorter read calls
2021-08-24 15:29 [PATCH 0/1] tools: env: Handle shorter read calls Thibault Ferrante
@ 2021-08-24 15:29 ` Thibault Ferrante
2021-09-02 22:42 ` Tom Rini
0 siblings, 1 reply; 3+ messages in thread
From: Thibault Ferrante @ 2021-08-24 15:29 UTC (permalink / raw)
To: u-boot
Cc: wd, joe.hershberger, hws, alex.kiernan, lg, Thibault Ferrante,
Martin Hundebøll
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>
---
tools/env/fw_env.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 2a61a5d6f0..e39c39e23a 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;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] tools: env: Handle shorter read calls
2021-08-24 15:29 ` [PATCH 1/1] " Thibault Ferrante
@ 2021-09-02 22:42 ` Tom Rini
0 siblings, 0 replies; 3+ messages in thread
From: Tom Rini @ 2021-09-02 22:42 UTC (permalink / raw)
To: Thibault Ferrante
Cc: u-boot, wd, joe.hershberger, hws, alex.kiernan, lg,
Thibault Ferrante, Martin Hundebøll
[-- Attachment #1: Type: text/plain, Size: 373 bytes --]
On Tue, Aug 24, 2021 at 05:29:50PM +0200, Thibault Ferrante wrote:
> 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>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-02 22:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-24 15:29 [PATCH 0/1] tools: env: Handle shorter read calls Thibault Ferrante
2021-08-24 15:29 ` [PATCH 1/1] " Thibault Ferrante
2021-09-02 22:42 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox