public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de, "Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-marvell 13/13] tools: kwboot: Resend first 3 xmodem retry packets immediately
Date: Mon, 25 Oct 2021 15:13:04 +0200	[thread overview]
Message-ID: <20211025131304.21310-14-kabel@kernel.org> (raw)
In-Reply-To: <20211025131304.21310-1-kabel@kernel.org>

From: Pali Rohár <pali@kernel.org>

Currently when kwboot receive some garbage reply which does not understand,
it waits 1s before it tries to resend packet again.

The most common error on UART is that receiver sees some bit flipped which
results in invalid reply.

This behavior slows down xmodem transfer over UART as basically on every
error kwboot is waiting one second.

To fix this, try to resend xmodem packet for first 3 attempts immediately
without any delay. If broken reply is received also after the 3 attempts,
continue retrying with 1s delay like it was before.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
---
 tools/kwboot.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 16c5a84825..bb7cae9f05 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -851,7 +851,8 @@ kwboot_baud_magic_handle(int fd, char c, int baudrate)
 }
 
 static int
-kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print,
+kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,
+		     int allow_non_xm, int *non_xm_print,
 		     int baudrate, int *baud_changed)
 {
 	int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;
@@ -904,6 +905,10 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print,
 				*non_xm_print = 1;
 			}
 		} else {
+			if (nak_on_non_xm) {
+				*c = NAK;
+				break;
+			}
 			timeout = recv_until - _now();
 			if (timeout < 0) {
 				errno = ETIMEDOUT;
@@ -937,7 +942,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,
 			*done_print = 1;
 		}
 
-		rc = kwboot_xm_recv_reply(fd, &c, allow_non_xm, &non_xm_print,
+		rc = kwboot_xm_recv_reply(fd, &c, retries < 3,
+					  allow_non_xm, &non_xm_print,
 					  baudrate, &baud_changed);
 		if (rc)
 			goto can;
@@ -979,7 +985,8 @@ kwboot_xm_finish(int fd)
 		if (rc)
 			return rc;
 
-		rc = kwboot_xm_recv_reply(fd, &c, 0, NULL, 0, NULL);
+		rc = kwboot_xm_recv_reply(fd, &c, retries < 3,
+					  0, NULL, 0, NULL);
 		if (rc)
 			return rc;
 	} while (c == NAK && retries++ < 16);
-- 
2.32.0


  parent reply	other threads:[~2021-10-25 13:15 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 13:12 [PATCH u-boot-marvell 00/13] Yet another kwboot improvements Marek Behún
2021-10-25 13:12 ` [PATCH u-boot-marvell 01/13] tools: kwboot: Initialize rfds to zero Marek Behún
2021-10-26  5:41   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 02/13] tools: kwboot: Fix initialization of tty device Marek Behún
2021-10-26  5:41   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 03/13] tools: kwboot: Reserve enough space for patching kwbimage in memory Marek Behún
2021-10-26  5:42   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 04/13] tools: kwboot: Validate 4-byte image data checksum Marek Behún
2021-10-26  5:43   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 05/13] tools: kwboot: Inject baudrate change back code after data part Marek Behún
2021-10-26  5:43   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 06/13] tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code Marek Behún
2021-10-26  5:44   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 07/13] tools: kwboot: Correctly set configuration of UART for BootROM messages Marek Behún
2021-10-26  5:45   ` Stefan Roese
2021-10-25 13:12 ` [PATCH u-boot-marvell 08/13] tools: kwboot: Show verbose message when waiting for baudrate change magic Marek Behún
2021-10-26  5:45   ` Stefan Roese
2021-10-25 13:13 ` [PATCH u-boot-marvell 09/13] tools: kwboot: Simplify code for aligning image header Marek Behún
2021-10-26  5:45   ` Stefan Roese
2021-10-25 13:13 ` [PATCH u-boot-marvell 10/13] tools: kwboot: Do not modify kwbimage header before increasing its size Marek Behún
2021-10-26  5:46   ` Stefan Roese
2021-10-25 13:13 ` [PATCH u-boot-marvell 11/13] tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr() Marek Behún
2021-10-26  5:48   ` Stefan Roese
2021-10-25 13:13 ` [PATCH u-boot-marvell 12/13] tools: kwboot: Change retry loop from decreasing to increasing Marek Behún
2021-10-26  5:49   ` Stefan Roese
2021-10-25 13:13 ` Marek Behún [this message]
2021-10-26  5:50   ` [PATCH u-boot-marvell 13/13] tools: kwboot: Resend first 3 xmodem retry packets immediately Stefan Roese
2021-10-25 14:39 ` [PATCH u-boot-marvell 00/13] Yet another kwboot improvements Stefan Roese
2021-10-25 14:42   ` Pali Rohár
2021-10-25 15:15     ` Stefan Roese
2021-10-26  8:33       ` Pali Rohár
2021-10-26  8:45         ` Stefan Roese
2021-10-26  9:06           ` Pali Rohár
2021-10-26 11:09             ` Stefan Roese
2021-10-26 12:40               ` Pali Rohár
2021-10-26 13:06                 ` Marek Behún
2021-10-26 14:06                   ` Stefan Roese
2021-10-26 14:21                 ` Stefan Roese
2021-10-26 14:48                   ` Pali Rohár
2021-10-26 15:13                     ` Stefan Roese
2021-10-26 15:20                       ` Marek Behún
2021-10-26 15:25                         ` Stefan Roese
2021-10-26 15:34                           ` Marek Behún
2021-10-26 15:40                             ` Stefan Roese
2021-10-26 18:48                   ` Pali Rohár
2021-10-27  5:09                     ` Stefan Roese
2021-10-27 13:52                       ` Pali Rohár
2021-10-27 14:10                         ` Pali Rohár
2021-10-27 15:08                           ` Marek Behún
2021-10-27 15:13                             ` Pali Rohár
2021-10-27 15:27                           ` Stefan Roese
2021-10-27 15:29                             ` Pali Rohár
2021-10-27 21:03                             ` Pali Rohár
2021-10-28  6:16                               ` Stefan Roese
2021-10-28 11:04                                 ` Pali Rohár
2021-10-28 14:20                                   ` Stefan Roese
2021-10-28 17:00                                     ` Pali Rohár
2021-10-29  4:44                                       ` Stefan Roese
2021-11-03  7:46 ` Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211025131304.21310-14-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox