[PATCH 5/7] xyz-modem: Properly abort/terminate transfer on error

Simon Glass sjg at chromium.org
Thu Aug 12 23:46:23 CEST 2021


Hi Pali,

On Tue, 3 Aug 2021 at 08:29, Pali Rohár <pali at kernel.org> wrote:
>
> 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 <pali at kernel.org>
> ---
>  cmd/load.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg at chromium.org>

>
> diff --git a/cmd/load.c b/cmd/load.c
> index fb8c191fb64f..1ed05a9cd21e 100644
> --- a/cmd/load.c
> +++ b/cmd/load.c
> @@ -975,6 +975,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;
> @@ -987,6 +988,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);
>                                 }
> @@ -998,12 +1002,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 */

Should not have brackets around return value.

>         }
>
>         xyzModem_stream_terminate(false, &getcxmodem);
> --
> 2.20.1
>

Regards,
Simon


More information about the U-Boot mailing list