mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts: kwboot: fix detection of timeout
@ 2014-11-11 20:10 Uwe Kleine-König
  2014-11-17  7:53 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2014-11-11 20:10 UTC (permalink / raw)
  To: barebox; +Cc: Thomas Petazzoni

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 <uwe@kleine-koenig.org>
--
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Gregory CLEMENT <gregory.clement@free-electrons.com>
Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>

I also tried to increase the timeout, but without success :-(. Will test
a different USB-to-RS232 adapter ...
---
 scripts/kwboot.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/scripts/kwboot.c b/scripts/kwboot.c
index e06866052ba9..46328d8ed006 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;
-- 
2.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts: kwboot: fix detection of timeout
  2014-11-11 20:10 [PATCH] scripts: kwboot: fix detection of timeout Uwe Kleine-König
@ 2014-11-17  7:53 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-11-17  7:53 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Thomas Petazzoni, barebox

On Tue, Nov 11, 2014 at 09:10:19PM +0100, Uwe Kleine-König wrote:
> 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 <uwe@kleine-koenig.org>

Applied, thanks

Sascha

> --
> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Gregory CLEMENT <gregory.clement@free-electrons.com>
> Cc: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> 
> I also tried to increase the timeout, but without success :-(. Will test
> a different USB-to-RS232 adapter ...
> ---
>  scripts/kwboot.c | 30 ++++++++++++++++--------------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/scripts/kwboot.c b/scripts/kwboot.c
> index e06866052ba9..46328d8ed006 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;
> -- 
> 2.1.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-17  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-11 20:10 [PATCH] scripts: kwboot: fix detection of timeout Uwe Kleine-König
2014-11-17  7:53 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox