During FIT reading through ymodem_read_fit() the function
xyzModem_stream_read() is being used which returns zero once the end
of a stream has been reached. This could lead to an premature exit from
ymodem_read_fit() with certain-sized FIT images reporting that zero
bytes overall were read. Such a premature exit would then result in an
-EIO failure being triggered within the spl_load_simple_fit() caller
function and ultimately lead to a boot failure.

Fix this logic by simply aborting the stream read loops and continuing
with the regular code flow which ultimately would lead to returning
the number of bytes to be read ('size') as expected by the callers of
ymodem_read_fit().

Fixes: fa715193c083 ("spl: Add an option to load a FIT containing U-Boot from 
UART")
Signed-off-by: Andreas Dannenberg <dannenb...@ti.com>
---
 common/spl/spl_ymodem.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 20f4260062..8ad580d8ae 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -44,7 +44,8 @@ static ulong ymodem_read_fit(struct spl_load_info *load, 
ulong offset,
        while (info->image_read < offset) {
                res = xyzModem_stream_read(buf, BUF_SIZE, &err);
                if (res <= 0)
-                       return res;
+                       break;
+
                info->image_read += res;
        }
 
@@ -57,7 +58,7 @@ static ulong ymodem_read_fit(struct spl_load_info *load, 
ulong offset,
        while (info->image_read < offset + size) {
                res = xyzModem_stream_read(buf, BUF_SIZE, &err);
                if (res <= 0)
-                       return res;
+                       break;
 
                memcpy(addr, buf, res);
                info->image_read += res;
-- 
2.17.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to