From ef8a47a6e779747ecd83b70120eae0af35a116f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Tue, 11 Nov 2014 21:10:19 +0100 Subject: [PATCH] scripts: kwboot: fix detection of timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In function kwboot_xm_sendblock() the loop that implements retrying to send a boot block might be quit if kwboot_tty_send or kwboot_tty_recv return a failure. In this case the value of the variable c that is expected to hold the response byte is uninitialized and most likely still holds an ACK from the previous call to kwboot_xm_sendblock(). So the right thing to do is not to clobber rc if it's already != 0. The result of this patch in my current scenario is that kwboot dies with xmodem: Connection timed out when the SoC stops replying instead of continuing to try sending the remaining blocks which results in select() blocking for one second for each block. Fixes: 0535713bbfa0 ("scripts: add kwboot tool") Signed-off-by: Uwe Kleine-König -- Cc: Thomas Petazzoni Cc: Gregory CLEMENT Cc: Ezequiel Garcia Cc: Sebastian Hesselbarth I also tried to increase the timeout, but without success :-(. Will test a different USB-to-RS232 adapter ... Signed-off-by: Sascha Hauer --- scripts/kwboot.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/kwboot.c b/scripts/kwboot.c index e06866052..46328d8ed 100644 --- a/scripts/kwboot.c +++ b/scripts/kwboot.c @@ -376,21 +376,23 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block) } while (c == NAK && retries-- > 0); - rc = -1; + if (!rc) { + rc = -1; - switch (c) { - case ACK: - rc = 0; - break; - case NAK: - errno = EBADMSG; - break; - case CAN: - errno = ECANCELED; - break; - default: - errno = EPROTO; - break; + switch (c) { + case ACK: + rc = 0; + break; + case NAK: + errno = EBADMSG; + break; + case CAN: + errno = ECANCELED; + break; + default: + errno = EPROTO; + break; + } } return rc;