diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2021-09-24 23:06:53 +0200 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2021-10-01 11:07:13 +0200 |
commit | 819cd3281d9003b950005b22a05978625cb73296 (patch) | |
tree | 528366acf2fe90fb805ae0e8949a5da115b5e410 /tools | |
parent | 12df7b790f2836580621271709ffba3c1339d929 (diff) | |
download | u-boot-819cd3281d9003b950005b22a05978625cb73296.zip u-boot-819cd3281d9003b950005b22a05978625cb73296.tar.gz u-boot-819cd3281d9003b950005b22a05978625cb73296.tar.bz2 |
tools: kwboot: Prevent waiting indefinitely if no xmodem reply is received
Currently if BootROM fails to respond with ACK/NAK to a xmodem block, we
will be waiting indefinitely for such response.
Make sure that we only wait at most 1 second (blk_rsp_timeo) for ACK/NAK
for each block in case non-xmodem text output is not being expected.
Interpret this timeout expiration as NAK, to try to send the block
again.
On the other hand, if timeout expires without ACK while some non-xmodem
output was already received (DDR training output, for example), we know
that the block was received, since the code is being executed, so in
this case exit with ETIMEDOUT.
Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/kwboot.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c index cf6e32c..8c11dca 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -407,17 +407,18 @@ static int kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print) { int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo; - uint64_t recv_until = 0; + uint64_t recv_until = _now() + timeout; int rc; - *non_xm_print = 0; + if (non_xm_print) + *non_xm_print = 0; while (1) { rc = kwboot_tty_recv(fd, c, 1, timeout); if (rc) { if (errno != ETIMEDOUT) return rc; - else if (recv_until && recv_until < _now()) + else if (allow_non_xm && *non_xm_print) return -1; else *c = NAK; @@ -430,12 +431,19 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print) /* * If printing non-xmodem text output is allowed and such a byte * was received, print it and increase receiving time. + * Otherwise decrease timeout by time elapsed. */ if (allow_non_xm) { recv_until = _now() + timeout; putchar(*c); fflush(stdout); *non_xm_print = 1; + } else { + timeout = recv_until - _now(); + if (timeout < 0) { + errno = ETIMEDOUT; + return -1; + } } } |