summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2021-09-24 23:06:54 +0200
committerStefan Roese <sr@denx.de>2021-10-01 11:07:13 +0200
commit9cdc264e2c6c6f92778145e0fd007d21ea0001c0 (patch)
tree146e3bc5ca4be43d387f23ba27f82088160bc733 /tools
parent819cd3281d9003b950005b22a05978625cb73296 (diff)
downloadu-boot-9cdc264e2c6c6f92778145e0fd007d21ea0001c0.tar.gz
u-boot-9cdc264e2c6c6f92778145e0fd007d21ea0001c0.tar.bz2
u-boot-9cdc264e2c6c6f92778145e0fd007d21ea0001c0.zip
tools: kwboot: Properly finish xmodem transfer
After kwboot sends EOT, BootROM sends back ACK. Add code for handling this and retry sending EOT on error. Signed-off-by: Pali Rohár <pali@kernel.org> [ refactored ] 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.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 8c11dca5ed..ad91afd075 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -404,6 +404,29 @@ _is_xm_reply(char c)
}
static int
+_xm_reply_to_error(int c)
+{
+ int rc = -1;
+
+ switch (c) {
+ case ACK:
+ rc = 0;
+ break;
+ case NAK:
+ errno = EBADMSG;
+ break;
+ case CAN:
+ errno = ECANCELED;
+ break;
+ default:
+ errno = EPROTO;
+ break;
+ }
+
+ return rc;
+}
+
+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;
@@ -483,24 +506,29 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,
if (non_xm_print)
kwboot_printv("\n");
- rc = -1;
+ return _xm_reply_to_error(c);
+}
- switch (c) {
- case ACK:
- rc = 0;
- break;
- case NAK:
- errno = EBADMSG;
- break;
- case CAN:
- errno = ECANCELED;
- break;
- default:
- errno = EPROTO;
- break;
- }
+static int
+kwboot_xm_finish(int fd)
+{
+ int rc, retries;
+ char c;
- return rc;
+ kwboot_printv("Finishing transfer\n");
+
+ retries = 16;
+ do {
+ rc = kwboot_tty_send_char(fd, EOT);
+ if (rc)
+ return rc;
+
+ rc = kwboot_xm_recv_reply(fd, &c, 0, NULL);
+ if (rc)
+ return rc;
+ } while (c == NAK && retries-- > 0);
+
+ return _xm_reply_to_error(c);
}
static int
@@ -577,7 +605,7 @@ kwboot_xmodem(int tty, const void *_img, size_t size)
if (rc)
return rc;
- return kwboot_tty_send_char(tty, EOT);
+ return kwboot_xm_finish(tty);
}
static int