diff options
author | Tom Rini <trini@konsulko.com> | 2022-04-21 11:44:54 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-04-21 11:44:54 -0400 |
commit | e50f66e364be80e02dd0834b84b830f3aade82ea (patch) | |
tree | cd44087cdc8180618f31faae2eb49598cb3ec5c5 /tools/kwboot.c | |
parent | feeacc7ec70560c535c0eb7a4d847ad17cacbeff (diff) | |
parent | ac47bd230cd3430589c63f81e57b3d30e0abe0db (diff) |
Merge https://source.denx.de/u-boot/custodians/u-boot-marvell
- mrvl_uart.sh: Remove script (Pali)
- Fix Espressobin build for configs where ENV is not in SPI (Rogier)
- mvebu: a37xx: Add support for reading OTP (Pali)
- mvebu: uDPU: Ethernet fixes and misc DT and defconfig changes (Robert)
- mvebu: Add support for reading LD0 and LD1 eFuse (Pali)
- kwboot: Replace fstat()+st_size by lseek()+SEEK_END (Pali)
- mvebu: turris_omnia: Enable CONFIG_CMD_FUSE (Pali)
- arm: Add CONFIG_SPL_SYS_NO_VECTOR_TABLE used on 32bit MVEBU (Pali)
- mvebu: a37xx: Add support for writing Security OTP values (Pali)
- mvebu: turris: Misc enhancements and cleanups / fixes (Pali)
- Sheevaplug : Use Marvell uclass mvgbe and PHY driver for Ethernet (Tony)
Diffstat (limited to 'tools/kwboot.c')
-rw-r--r-- | tools/kwboot.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c index 9f2dd2de4ef..b697d3b60e6 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1591,8 +1591,8 @@ static void * kwboot_read_image(const char *path, size_t *size, size_t reserve) { int rc, fd; - struct stat st; void *img; + off_t len; off_t tot; rc = -1; @@ -1602,31 +1602,34 @@ kwboot_read_image(const char *path, size_t *size, size_t reserve) if (fd < 0) goto out; - rc = fstat(fd, &st); - if (rc) + len = lseek(fd, 0, SEEK_END); + if (len == (off_t)-1) + goto out; + + if (lseek(fd, 0, SEEK_SET) == (off_t)-1) goto out; - img = malloc(st.st_size + reserve); + img = malloc(len + reserve); if (!img) goto out; tot = 0; - while (tot < st.st_size) { - ssize_t rd = read(fd, img + tot, st.st_size - tot); + while (tot < len) { + ssize_t rd = read(fd, img + tot, len - tot); if (rd < 0) goto out; tot += rd; - if (!rd && tot < st.st_size) { + if (!rd && tot < len) { errno = EIO; goto out; } } rc = 0; - *size = st.st_size; + *size = len; out: if (rc && img) { free(img); |