Skip to contentSkip to conversation

tools: fw_env: Fix warning when reading too little

PATCH New Harald Seiler 2 participants 2 messages May 28, 2020 – Jun 3, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: fw_env: Fix warning when reading too little

When using CONFIG_ENV_IS_IN_FAT and the config-file specifies a size larger than what U-Boot wrote into the env-file, a confusing error message is shown:

    $ fw_printenv
    Read error on /boot/uboot.env: Success

Fix this by showing a different error message when read returns too little data.

---
 tools/env/fw_env.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/env/fw_env.c +7 -1
index 8734663cd4c7..c6378ecf34f6 100644
@@ -946,11 +946,17 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
 		lseek(fd, blockstart + block_seek, SEEK_SET);
 
 		rc = read(fd, buf + processed, readlen);
-		if (rc != readlen) {
+		if (rc == -1) {
 			fprintf(stderr, "Read error on %s: %s\n",
 				DEVNAME(dev), strerror(errno));
 			return -1;
 		}
+		if (rc != readlen) {
+			fprintf(stderr, "Read error on %s: "
+				"Attempted to read %d 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,
Signature · 1 line
2.25.4
#1 lore raw

PATCH 1/1 tools: fw_env: Fix warning when reading too little

Quoted 11 lines · Harald Seiler

When using CONFIG_ENV_IS_IN_FAT and the config-file specifies a size larger than what U-Boot wrote into the env-file, a confusing error message is shown:

    $ fw_printenv
    Read error on /boot/uboot.env: Success

Fix this by showing a different error message when read returns too little data.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200603/30965a4c/attachment.sig>