xyzModem.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. // SPDX-License-Identifier: eCos-2.0
  2. /*
  3. *==========================================================================
  4. *
  5. * xyzModem.c
  6. *
  7. * RedBoot stream handler for xyzModem protocol
  8. *
  9. *==========================================================================
  10. *#####DESCRIPTIONBEGIN####
  11. *
  12. * Author(s): gthomas
  13. * Contributors: gthomas, tsmith, Yoshinori Sato
  14. * Date: 2000-07-14
  15. * Purpose:
  16. * Description:
  17. *
  18. * This code is part of RedBoot (tm).
  19. *
  20. *####DESCRIPTIONEND####
  21. *
  22. *==========================================================================
  23. */
  24. #include <common.h>
  25. #include <xyzModem.h>
  26. #include <stdarg.h>
  27. #include <u-boot/crc.h>
  28. #include <watchdog.h>
  29. /* Assumption - run xyzModem protocol over the console port */
  30. /* Values magic to the protocol */
  31. #define SOH 0x01
  32. #define STX 0x02
  33. #define ETX 0x03 /* ^C for interrupt */
  34. #define EOT 0x04
  35. #define ACK 0x06
  36. #define BSP 0x08
  37. #define NAK 0x15
  38. #define CAN 0x18
  39. #define EOF 0x1A /* ^Z for DOS officionados */
  40. /* Data & state local to the protocol */
  41. static struct
  42. {
  43. int *__chan;
  44. unsigned char pkt[1024], *bufp;
  45. unsigned char blk, cblk, crc1, crc2;
  46. unsigned char next_blk; /* Expected block */
  47. int len, mode, total_retries;
  48. int total_SOH, total_STX, total_CAN;
  49. bool crc_mode, at_eof, tx_ack;
  50. unsigned long file_length, read_length;
  51. } xyz;
  52. #define xyzModem_CHAR_TIMEOUT 2000 /* 2 seconds */
  53. #define xyzModem_MAX_RETRIES 20
  54. #define xyzModem_MAX_RETRIES_WITH_CRC 10
  55. #define xyzModem_CAN_COUNT 3 /* Wait for 3 CAN before quitting */
  56. typedef int cyg_int32;
  57. static int
  58. CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c)
  59. {
  60. ulong now = get_timer(0);
  61. WATCHDOG_RESET();
  62. while (!tstc ())
  63. {
  64. if (get_timer(now) > xyzModem_CHAR_TIMEOUT)
  65. break;
  66. }
  67. if (tstc ())
  68. {
  69. *c = getchar();
  70. return 1;
  71. }
  72. return 0;
  73. }
  74. static void
  75. CYGACC_COMM_IF_PUTC (char x, char y)
  76. {
  77. putc (y);
  78. }
  79. /* Validate a hex character */
  80. __inline__ static bool
  81. _is_hex (char c)
  82. {
  83. return (((c >= '0') && (c <= '9')) ||
  84. ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')));
  85. }
  86. /* Convert a single hex nibble */
  87. __inline__ static int
  88. _from_hex (char c)
  89. {
  90. int ret = 0;
  91. if ((c >= '0') && (c <= '9'))
  92. {
  93. ret = (c - '0');
  94. }
  95. else if ((c >= 'a') && (c <= 'f'))
  96. {
  97. ret = (c - 'a' + 0x0a);
  98. }
  99. else if ((c >= 'A') && (c <= 'F'))
  100. {
  101. ret = (c - 'A' + 0x0A);
  102. }
  103. return ret;
  104. }
  105. /* Convert a character to lower case */
  106. __inline__ static char
  107. _tolower (char c)
  108. {
  109. if ((c >= 'A') && (c <= 'Z'))
  110. {
  111. c = (c - 'A') + 'a';
  112. }
  113. return c;
  114. }
  115. /* Parse (scan) a number */
  116. static bool
  117. parse_num (char *s, unsigned long *val, char **es, char *delim)
  118. {
  119. bool first = true;
  120. int radix = 10;
  121. char c;
  122. unsigned long result = 0;
  123. int digit;
  124. while (*s == ' ')
  125. s++;
  126. while (*s)
  127. {
  128. if (first && (s[0] == '0') && (_tolower (s[1]) == 'x'))
  129. {
  130. radix = 16;
  131. s += 2;
  132. }
  133. first = false;
  134. c = *s++;
  135. if (_is_hex (c) && ((digit = _from_hex (c)) < radix))
  136. {
  137. /* Valid digit */
  138. result = (result * radix) + digit;
  139. }
  140. else
  141. {
  142. if (delim != (char *) 0)
  143. {
  144. /* See if this character is one of the delimiters */
  145. char *dp = delim;
  146. while (*dp && (c != *dp))
  147. dp++;
  148. if (*dp)
  149. break; /* Found a good delimiter */
  150. }
  151. return false; /* Malformatted number */
  152. }
  153. }
  154. *val = result;
  155. if (es != (char **) 0)
  156. {
  157. *es = s;
  158. }
  159. return true;
  160. }
  161. #if defined(DEBUG) && !CONFIG_IS_ENABLED(USE_TINY_PRINTF)
  162. /*
  163. * Note: this debug setup works by storing the strings in a fixed buffer
  164. */
  165. static char zm_debug_buf[8192];
  166. static char *zm_out = zm_debug_buf;
  167. static char *zm_out_start = zm_debug_buf;
  168. static int
  169. zm_dprintf(char *fmt, ...)
  170. {
  171. int len;
  172. va_list args;
  173. va_start(args, fmt);
  174. len = diag_vsprintf(zm_out, fmt, args);
  175. va_end(args);
  176. zm_out += len;
  177. return len;
  178. }
  179. static void
  180. zm_flush (void)
  181. {
  182. zm_out = zm_out_start;
  183. }
  184. static void
  185. zm_dump_buf (void *buf, int len)
  186. {
  187. }
  188. static unsigned char zm_buf[2048];
  189. static unsigned char *zm_bp;
  190. static void
  191. zm_new (void)
  192. {
  193. zm_bp = zm_buf;
  194. }
  195. static void
  196. zm_save (unsigned char c)
  197. {
  198. *zm_bp++ = c;
  199. }
  200. static void
  201. zm_dump (int line)
  202. {
  203. zm_dprintf ("Packet at line: %d\n", line);
  204. zm_dump_buf (zm_buf, zm_bp - zm_buf);
  205. }
  206. #define ZM_DEBUG(x) x
  207. #else
  208. #define ZM_DEBUG(x)
  209. #endif
  210. /* Wait for the line to go idle */
  211. static void
  212. xyzModem_flush (void)
  213. {
  214. int res;
  215. char c;
  216. while (true)
  217. {
  218. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
  219. if (!res)
  220. return;
  221. }
  222. }
  223. static int
  224. xyzModem_get_hdr (void)
  225. {
  226. char c;
  227. int res;
  228. bool hdr_found = false;
  229. int i, can_total, hdr_chars;
  230. unsigned short cksum;
  231. ZM_DEBUG (zm_new ());
  232. /* Find the start of a header */
  233. can_total = 0;
  234. hdr_chars = 0;
  235. if (xyz.tx_ack)
  236. {
  237. CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
  238. xyz.tx_ack = false;
  239. }
  240. while (!hdr_found)
  241. {
  242. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
  243. ZM_DEBUG (zm_save (c));
  244. if (res)
  245. {
  246. hdr_chars++;
  247. switch (c)
  248. {
  249. case SOH:
  250. xyz.total_SOH++;
  251. case STX:
  252. if (c == STX)
  253. xyz.total_STX++;
  254. hdr_found = true;
  255. break;
  256. case CAN:
  257. case ETX:
  258. xyz.total_CAN++;
  259. ZM_DEBUG (zm_dump (__LINE__));
  260. if (++can_total == xyzModem_CAN_COUNT)
  261. {
  262. return xyzModem_cancel;
  263. }
  264. else
  265. {
  266. /* Wait for multiple CAN to avoid early quits */
  267. break;
  268. }
  269. case EOT:
  270. /* EOT only supported if no noise */
  271. if (hdr_chars == 1)
  272. {
  273. CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
  274. ZM_DEBUG (zm_dprintf ("ACK on EOT #%d\n", __LINE__));
  275. ZM_DEBUG (zm_dump (__LINE__));
  276. return xyzModem_eof;
  277. }
  278. default:
  279. /* Ignore, waiting for start of header */
  280. ;
  281. }
  282. }
  283. else
  284. {
  285. /* Data stream timed out */
  286. xyzModem_flush (); /* Toss any current input */
  287. ZM_DEBUG (zm_dump (__LINE__));
  288. CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000);
  289. return xyzModem_timeout;
  290. }
  291. }
  292. /* Header found, now read the data */
  293. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.blk);
  294. ZM_DEBUG (zm_save (xyz.blk));
  295. if (!res)
  296. {
  297. ZM_DEBUG (zm_dump (__LINE__));
  298. return xyzModem_timeout;
  299. }
  300. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.cblk);
  301. ZM_DEBUG (zm_save (xyz.cblk));
  302. if (!res)
  303. {
  304. ZM_DEBUG (zm_dump (__LINE__));
  305. return xyzModem_timeout;
  306. }
  307. xyz.len = (c == SOH) ? 128 : 1024;
  308. xyz.bufp = xyz.pkt;
  309. for (i = 0; i < xyz.len; i++)
  310. {
  311. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c);
  312. ZM_DEBUG (zm_save (c));
  313. if (res)
  314. {
  315. xyz.pkt[i] = c;
  316. }
  317. else
  318. {
  319. ZM_DEBUG (zm_dump (__LINE__));
  320. return xyzModem_timeout;
  321. }
  322. }
  323. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc1);
  324. ZM_DEBUG (zm_save (xyz.crc1));
  325. if (!res)
  326. {
  327. ZM_DEBUG (zm_dump (__LINE__));
  328. return xyzModem_timeout;
  329. }
  330. if (xyz.crc_mode)
  331. {
  332. res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc2);
  333. ZM_DEBUG (zm_save (xyz.crc2));
  334. if (!res)
  335. {
  336. ZM_DEBUG (zm_dump (__LINE__));
  337. return xyzModem_timeout;
  338. }
  339. }
  340. ZM_DEBUG (zm_dump (__LINE__));
  341. /* Validate the message */
  342. if ((xyz.blk ^ xyz.cblk) != (unsigned char) 0xFF)
  343. {
  344. ZM_DEBUG (zm_dprintf
  345. ("Framing error - blk: %x/%x/%x\n", xyz.blk, xyz.cblk,
  346. (xyz.blk ^ xyz.cblk)));
  347. ZM_DEBUG (zm_dump_buf (xyz.pkt, xyz.len));
  348. xyzModem_flush ();
  349. return xyzModem_frame;
  350. }
  351. /* Verify checksum/CRC */
  352. if (xyz.crc_mode)
  353. {
  354. cksum = crc16_ccitt(0, xyz.pkt, xyz.len);
  355. if (cksum != ((xyz.crc1 << 8) | xyz.crc2))
  356. {
  357. ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n",
  358. xyz.crc1, xyz.crc2, cksum & 0xFFFF));
  359. return xyzModem_cksum;
  360. }
  361. }
  362. else
  363. {
  364. cksum = 0;
  365. for (i = 0; i < xyz.len; i++)
  366. {
  367. cksum += xyz.pkt[i];
  368. }
  369. if (xyz.crc1 != (cksum & 0xFF))
  370. {
  371. ZM_DEBUG (zm_dprintf
  372. ("Checksum error - recvd: %x, computed: %x\n", xyz.crc1,
  373. cksum & 0xFF));
  374. return xyzModem_cksum;
  375. }
  376. }
  377. /* If we get here, the message passes [structural] muster */
  378. return 0;
  379. }
  380. int
  381. xyzModem_stream_open (connection_info_t * info, int *err)
  382. {
  383. int stat = 0;
  384. int retries = xyzModem_MAX_RETRIES;
  385. int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC;
  386. /* ZM_DEBUG(zm_out = zm_out_start); */
  387. #ifdef xyzModem_zmodem
  388. if (info->mode == xyzModem_zmodem)
  389. {
  390. *err = xyzModem_noZmodem;
  391. return -1;
  392. }
  393. #endif
  394. /* TODO: CHECK ! */
  395. int dummy = 0;
  396. xyz.__chan = &dummy;
  397. xyz.len = 0;
  398. xyz.crc_mode = true;
  399. xyz.at_eof = false;
  400. xyz.tx_ack = false;
  401. xyz.mode = info->mode;
  402. xyz.total_retries = 0;
  403. xyz.total_SOH = 0;
  404. xyz.total_STX = 0;
  405. xyz.total_CAN = 0;
  406. xyz.read_length = 0;
  407. xyz.file_length = 0;
  408. CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
  409. if (xyz.mode == xyzModem_xmodem)
  410. {
  411. /* X-modem doesn't have an information header - exit here */
  412. xyz.next_blk = 1;
  413. return 0;
  414. }
  415. while (retries-- > 0)
  416. {
  417. stat = xyzModem_get_hdr ();
  418. if (stat == 0)
  419. {
  420. /* Y-modem file information header */
  421. if (xyz.blk == 0)
  422. {
  423. /* skip filename */
  424. while (*xyz.bufp++);
  425. /* get the length */
  426. parse_num ((char *) xyz.bufp, &xyz.file_length, NULL, " ");
  427. /* The rest of the file name data block quietly discarded */
  428. xyz.tx_ack = true;
  429. }
  430. xyz.next_blk = 1;
  431. xyz.len = 0;
  432. return 0;
  433. }
  434. else if (stat == xyzModem_timeout)
  435. {
  436. if (--crc_retries <= 0)
  437. xyz.crc_mode = false;
  438. CYGACC_CALL_IF_DELAY_US (5 * 100000); /* Extra delay for startup */
  439. CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
  440. xyz.total_retries++;
  441. ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__));
  442. }
  443. if (stat == xyzModem_cancel)
  444. {
  445. break;
  446. }
  447. }
  448. *err = stat;
  449. ZM_DEBUG (zm_flush ());
  450. return -1;
  451. }
  452. int
  453. xyzModem_stream_read (char *buf, int size, int *err)
  454. {
  455. int stat, total, len;
  456. int retries;
  457. total = 0;
  458. stat = xyzModem_cancel;
  459. /* Try and get 'size' bytes into the buffer */
  460. while (!xyz.at_eof && xyz.len >= 0 && (size > 0))
  461. {
  462. if (xyz.len == 0)
  463. {
  464. retries = xyzModem_MAX_RETRIES;
  465. while (retries-- > 0)
  466. {
  467. stat = xyzModem_get_hdr ();
  468. if (stat == 0)
  469. {
  470. if (xyz.blk == xyz.next_blk)
  471. {
  472. xyz.tx_ack = true;
  473. ZM_DEBUG (zm_dprintf
  474. ("ACK block %d (%d)\n", xyz.blk, __LINE__));
  475. xyz.next_blk = (xyz.next_blk + 1) & 0xFF;
  476. if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0)
  477. {
  478. /* Data blocks can be padded with ^Z (EOF) characters */
  479. /* This code tries to detect and remove them */
  480. if ((xyz.bufp[xyz.len - 1] == EOF) &&
  481. (xyz.bufp[xyz.len - 2] == EOF) &&
  482. (xyz.bufp[xyz.len - 3] == EOF))
  483. {
  484. while (xyz.len
  485. && (xyz.bufp[xyz.len - 1] == EOF))
  486. {
  487. xyz.len--;
  488. }
  489. }
  490. }
  491. /*
  492. * See if accumulated length exceeds that of the file.
  493. * If so, reduce size (i.e., cut out pad bytes)
  494. * Only do this for Y-modem (and Z-modem should it ever
  495. * be supported since it can fall back to Y-modem mode).
  496. */
  497. if (xyz.mode != xyzModem_xmodem && 0 != xyz.file_length)
  498. {
  499. xyz.read_length += xyz.len;
  500. if (xyz.read_length > xyz.file_length)
  501. {
  502. xyz.len -= (xyz.read_length - xyz.file_length);
  503. }
  504. }
  505. break;
  506. }
  507. else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF))
  508. {
  509. /* Just re-ACK this so sender will get on with it */
  510. CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
  511. continue; /* Need new header */
  512. }
  513. else
  514. {
  515. stat = xyzModem_sequence;
  516. }
  517. }
  518. if (stat == xyzModem_cancel)
  519. {
  520. break;
  521. }
  522. if (stat == xyzModem_eof)
  523. {
  524. CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
  525. ZM_DEBUG (zm_dprintf ("ACK (%d)\n", __LINE__));
  526. if (xyz.mode == xyzModem_ymodem)
  527. {
  528. CYGACC_COMM_IF_PUTC (*xyz.__chan,
  529. (xyz.crc_mode ? 'C' : NAK));
  530. xyz.total_retries++;
  531. ZM_DEBUG (zm_dprintf ("Reading Final Header\n"));
  532. stat = xyzModem_get_hdr ();
  533. CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK);
  534. ZM_DEBUG (zm_dprintf ("FINAL ACK (%d)\n", __LINE__));
  535. }
  536. else
  537. stat = 0;
  538. xyz.at_eof = true;
  539. break;
  540. }
  541. CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK));
  542. xyz.total_retries++;
  543. ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__));
  544. }
  545. if (stat < 0)
  546. {
  547. *err = stat;
  548. xyz.len = -1;
  549. return total;
  550. }
  551. }
  552. /* Don't "read" data from the EOF protocol package */
  553. if (!xyz.at_eof && xyz.len > 0)
  554. {
  555. len = xyz.len;
  556. if (size < len)
  557. len = size;
  558. memcpy (buf, xyz.bufp, len);
  559. size -= len;
  560. buf += len;
  561. total += len;
  562. xyz.len -= len;
  563. xyz.bufp += len;
  564. }
  565. }
  566. return total;
  567. }
  568. void
  569. xyzModem_stream_close (int *err)
  570. {
  571. ZM_DEBUG (zm_dprintf
  572. ("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n",
  573. xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX,
  574. xyz.total_CAN, xyz.total_retries));
  575. ZM_DEBUG (zm_flush ());
  576. }
  577. /* Need to be able to clean out the input buffer, so have to take the */
  578. /* getc */
  579. void
  580. xyzModem_stream_terminate (bool abort, int (*getc) (void))
  581. {
  582. int c;
  583. if (abort)
  584. {
  585. ZM_DEBUG (zm_dprintf ("!!!! TRANSFER ABORT !!!!\n"));
  586. switch (xyz.mode)
  587. {
  588. case xyzModem_xmodem:
  589. case xyzModem_ymodem:
  590. /* The X/YMODEM Spec seems to suggest that multiple CAN followed by an equal */
  591. /* number of Backspaces is a friendly way to get the other end to abort. */
  592. CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
  593. CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
  594. CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
  595. CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN);
  596. CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
  597. CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
  598. CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
  599. CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP);
  600. /* Now consume the rest of what's waiting on the line. */
  601. ZM_DEBUG (zm_dprintf ("Flushing serial line.\n"));
  602. xyzModem_flush ();
  603. xyz.at_eof = true;
  604. break;
  605. #ifdef xyzModem_zmodem
  606. case xyzModem_zmodem:
  607. /* Might support it some day I suppose. */
  608. #endif
  609. break;
  610. }
  611. }
  612. else
  613. {
  614. ZM_DEBUG (zm_dprintf ("Engaging cleanup mode...\n"));
  615. /*
  616. * Consume any trailing crap left in the inbuffer from
  617. * previous received blocks. Since very few files are an exact multiple
  618. * of the transfer block size, there will almost always be some gunk here.
  619. * If we don't eat it now, RedBoot will think the user typed it.
  620. */
  621. ZM_DEBUG (zm_dprintf ("Trailing gunk:\n"));
  622. while ((c = (*getc) ()) > -1)
  623. ;
  624. ZM_DEBUG (zm_dprintf ("\n"));
  625. /*
  626. * Make a small delay to give terminal programs like minicom
  627. * time to get control again after their file transfer program
  628. * exits.
  629. */
  630. CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000);
  631. }
  632. }
  633. char *
  634. xyzModem_error (int err)
  635. {
  636. switch (err)
  637. {
  638. case xyzModem_access:
  639. return "Can't access file";
  640. break;
  641. case xyzModem_noZmodem:
  642. return "Sorry, zModem not available yet";
  643. break;
  644. case xyzModem_timeout:
  645. return "Timed out";
  646. break;
  647. case xyzModem_eof:
  648. return "End of file";
  649. break;
  650. case xyzModem_cancel:
  651. return "Cancelled";
  652. break;
  653. case xyzModem_frame:
  654. return "Invalid framing";
  655. break;
  656. case xyzModem_cksum:
  657. return "CRC/checksum error";
  658. break;
  659. case xyzModem_sequence:
  660. return "Block sequence error";
  661. break;
  662. default:
  663. return "Unknown error";
  664. break;
  665. }
  666. }
  667. /*
  668. * RedBoot interface
  669. */