From: Pali Rohár Date: Tue, 3 Aug 2021 14:28:42 +0000 (+0200) Subject: xyz-modem: Properly abort/terminate transfer on error X-Git-Tag: v2025.01-rc5-pxa1908~1694^2~25^2~2 X-Git-Url: http://git.dujemihanovic.xyz/img/static/%7B%7B?a=commitdiff_plain;h=081bd249d119ecad114fd2560974688d8a5ce059;p=u-boot.git xyz-modem: Properly abort/terminate transfer on error 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 --- diff --git a/cmd/load.c b/cmd/load.c index e0c896bb79..549e5637fb 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);