From 1f26c49ea1d968ff59abe804af14314d5f5dc8de Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 3 Aug 2021 16:28:41 +0200 Subject: xyz-modem: Close stream after processing/sending terminate sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obviously it is not possible to send terminate sequence over stream after closing stream. Signed-off-by: Pali Rohár --- cmd/load.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/load.c b/cmd/load.c index 3904e133c4a..e0c896bb79a 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -1009,8 +1009,8 @@ static ulong load_serial_ymodem(ulong offset, int mode) printf("%s\n", xyzModem_error(err)); } - xyzModem_stream_close(&err); xyzModem_stream_terminate(false, &getcxmodem); + xyzModem_stream_close(&err); flush_cache(offset, ALIGN(size, ARCH_DMA_MINALIGN)); -- cgit v1.3.1 From 081bd249d119ecad114fd2560974688d8a5ce059 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 3 Aug 2021 16:28:42 +0200 Subject: xyz-modem: Properly abort/terminate transfer on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transfer termination tries to instruct sender that transfer was terminated. Print error message and indicates aborted transfer in return value. Signed-off-by: Pali Rohár Reviewed-by: Simon Glass --- cmd/load.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/load.c b/cmd/load.c index e0c896bb79a..549e5637fbf 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -978,6 +978,7 @@ static ulong load_serial_ymodem(ulong offset, int mode) res = xyzModem_stream_open(&info, &err); if (!res) { + err = 0; while ((res = xyzModem_stream_read(ymodemBuf, 1024, &err)) > 0) { store_addr = addr + offset; @@ -990,6 +991,9 @@ static ulong load_serial_ymodem(ulong offset, int mode) rc = flash_write((char *) ymodemBuf, store_addr, res); if (rc != 0) { + xyzModem_stream_terminate(true, &getcxmodem); + xyzModem_stream_close(&err); + printf("\n"); flash_perror(rc); return (~0); } @@ -1001,12 +1005,20 @@ static ulong load_serial_ymodem(ulong offset, int mode) } } + if (err) { + xyzModem_stream_terminate((err == xyzModem_cancel) ? false : true, &getcxmodem); + xyzModem_stream_close(&err); + printf("\n%s\n", xyzModem_error(err)); + return (~0); /* Download aborted */ + } + if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) efi_set_bootdev("Uart", "", "", map_sysmem(offset, 0), size); } else { - printf("%s\n", xyzModem_error(err)); + printf("\n%s\n", xyzModem_error(err)); + return (~0); /* Download aborted */ } xyzModem_stream_terminate(false, &getcxmodem); -- cgit v1.3.1 From c97b2557bcd5899cdf7bd57e09379b159f4796c8 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 3 Aug 2021 16:28:43 +0200 Subject: xyz-modem: Show information about finished transfer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show "## Start Addr" or "## Binary (...) download aborted" information like in Kermit "loadb" command. Signed-off-by: Pali Rohár --- cmd/load.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cmd') diff --git a/cmd/load.c b/cmd/load.c index 549e5637fbf..249ebd4ae07 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -474,6 +474,14 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc, addr = load_serial_ymodem(offset, xyzModem_ymodem); + if (addr == ~0) { + image_load_addr = 0; + printf("## Binary (ymodem) download aborted\n"); + rcode = 1; + } else { + printf("## Start Addr = 0x%08lX\n", addr); + image_load_addr = addr; + } } else if (strcmp(argv[0],"loadx")==0) { printf("## Ready for binary (xmodem) download " "to 0x%08lX at %d bps...\n", @@ -482,6 +490,14 @@ static int do_load_serial_bin(struct cmd_tbl *cmdtp, int flag, int argc, addr = load_serial_ymodem(offset, xyzModem_xmodem); + if (addr == ~0) { + image_load_addr = 0; + printf("## Binary (xmodem) download aborted\n"); + rcode = 1; + } else { + printf("## Start Addr = 0x%08lX\n", addr); + image_load_addr = addr; + } } else { printf("## Ready for binary (kermit) download " -- cgit v1.3.1