summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-09-04 00:15:44 +0300
committerTom Rini <trini@konsulko.com>2021-09-04 00:15:44 +0300
commita48f5ff4f523a59cdf025a4cbafd0cb3a932809f (patch)
tree40d868670757b71fc97cab910df5a31f70907322
parent00179319714fd2076cf81f49de357ee699672f31 (diff)
parentdffeb400985d3244ce13ca95ad7c18a78ffd207f (diff)
downloadu-boot-a48f5ff4f523a59cdf025a4cbafd0cb3a932809f.tar.xz
Merge branch '2021-09-03-xyz-modem-fixes' into next
- Assorted x/y/z modem fixes from Pali
-rw-r--r--cmd/load.c32
-rw-r--r--common/xyzModem.c12
2 files changed, 38 insertions, 6 deletions
diff --git a/cmd/load.c b/cmd/load.c
index 3904e133c4..249ebd4ae0 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 "
@@ -978,6 +994,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 +1007,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,16 +1021,24 @@ 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_close(&err);
xyzModem_stream_terminate(false, &getcxmodem);
+ xyzModem_stream_close(&err);
flush_cache(offset, ALIGN(size, ARCH_DMA_MINALIGN));
diff --git a/common/xyzModem.c b/common/xyzModem.c
index fc3459ebba..ece25acb18 100644
--- a/common/xyzModem.c
+++ b/common/xyzModem.c
@@ -32,6 +32,7 @@
/* Values magic to the protocol */
#define SOH 0x01
#define STX 0x02
+#define ETX 0x03 /* ^C for interrupt */
#define EOT 0x04
#define ACK 0x06
#define BSP 0x08
@@ -283,6 +284,7 @@ xyzModem_get_hdr (void)
hdr_found = true;
break;
case CAN:
+ case ETX:
xyz.total_CAN++;
ZM_DEBUG (zm_dump (__LINE__));
if (++can_total == xyzModem_CAN_COUNT)
@@ -494,7 +496,7 @@ xyzModem_stream_read (char *buf, int size, int *err)
total = 0;
stat = xyzModem_cancel;
/* Try and get 'size' bytes into the buffer */
- while (!xyz.at_eof && (size > 0))
+ while (!xyz.at_eof && xyz.len >= 0 && (size > 0))
{
if (xyz.len == 0)
{
@@ -572,6 +574,8 @@ xyzModem_stream_read (char *buf, int size, int *err)
CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
ZM_DEBUG (zm_dprintf ("FINAL ACK (%d)\n", __LINE__));
}
+ else
+ stat = 0;
xyz.at_eof = true;
break;
}
@@ -587,7 +591,7 @@ xyzModem_stream_read (char *buf, int size, int *err)
}
}
/* Don't "read" data from the EOF protocol package */
- if (!xyz.at_eof)
+ if (!xyz.at_eof && xyz.len > 0)
{
len = xyz.len;
if (size < len)
@@ -606,10 +610,10 @@ xyzModem_stream_read (char *buf, int size, int *err)
void
xyzModem_stream_close (int *err)
{
- diag_printf
+ ZM_DEBUG (zm_dprintf
("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n",
xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX,
- xyz.total_CAN, xyz.total_retries);
+ xyz.total_CAN, xyz.total_retries));
ZM_DEBUG (zm_flush ());
}