2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <cmd_autoscript.h>
36 #if (CONFIG_COMMANDS & CFG_CMD_LOADS)
37 static ulong load_serial (ulong offset);
38 static int read_record (char *buf, ulong len);
39 # if (CONFIG_COMMANDS & CFG_CMD_SAVES)
40 static int save_serial (ulong offset, ulong size);
41 static int write_record (char *buf);
42 # endif /* CFG_CMD_SAVES */
44 static int do_echo = 1;
45 #endif /* CFG_CMD_LOADS */
48 #if (CONFIG_COMMANDS & CFG_CMD_BDI)
49 static void print_num(const char *, ulong);
51 #ifndef CONFIG_ARM /* PowerPC and other */
54 static void print_str(const char *, const char *);
56 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
58 DECLARE_GLOBAL_DATA_PTR;
65 print_num ("bd address", (ulong)bd );
67 print_num ("memstart", bd->bi_memstart );
68 print_num ("memsize", bd->bi_memsize );
69 print_num ("flashstart", bd->bi_flashstart );
70 print_num ("flashsize", bd->bi_flashsize );
71 print_num ("flashoffset", bd->bi_flashoffset );
72 print_num ("sramstart", bd->bi_sramstart );
73 print_num ("sramsize", bd->bi_sramsize );
74 #if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260)
75 print_num ("immr_base", bd->bi_immr_base );
77 print_num ("bootflags", bd->bi_bootflags );
78 #if defined(CONFIG_405GP) || defined(CONFIG_405CR)
79 print_str ("procfreq", strmhz(buf, bd->bi_procfreq));
80 print_str ("plb_busfreq", strmhz(buf, bd->bi_plb_busfreq));
81 #if defined(CONFIG_405GP)
82 print_str ("pci_busfreq", strmhz(buf, bd->bi_pci_busfreq));
85 #if defined(CONFIG_8260)
86 print_str ("vco", strmhz(buf, bd->bi_vco));
87 print_str ("sccfreq", strmhz(buf, bd->bi_sccfreq));
88 print_str ("brgfreq", strmhz(buf, bd->bi_brgfreq));
90 print_str ("intfreq", strmhz(buf, bd->bi_intfreq));
91 #if defined(CONFIG_8260)
92 print_str ("cpmfreq", strmhz(buf, bd->bi_cpmfreq));
94 print_str ("busfreq", strmhz(buf, bd->bi_busfreq));
95 #endif /* defined(CONFIG_405GP) || defined(CONFIG_405CR) */
98 printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
101 printf ("\neth1addr =");
102 for (i=0; i<6; ++i) {
103 printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]);
105 #endif /* CONFIG_PN62 */
107 print_str ("ethspeed", strmhz(buf, bd->bi_ethspeed));
109 printf ("\nIP addr = "); print_IPaddr (bd->bi_ip_addr);
110 printf ("\nbaudrate = %6ld bps\n", bd->bi_baudrate );
116 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
118 DECLARE_GLOBAL_DATA_PTR;
123 print_num ("boot_params", (ulong)bd->bi_boot_params);
124 print_num ("memstart", (ulong)bd->bi_memstart);
125 print_num ("memsize", (ulong)bd->bi_memsize);
126 print_num ("flashstart", (ulong)bd->bi_flashstart);
127 print_num ("flashsize", (ulong)bd->bi_flashsize);
128 print_num ("flashoffset", (ulong)bd->bi_flashoffset);
130 printf ("ethaddr =");
131 for (i=0; i<6; ++i) {
132 printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
134 printf ("\nip_addr = ");
135 print_IPaddr (bd->bi_ip_addr);
136 printf ("\nbaudrate = %d bps\n", bd->bi_baudrate);
144 int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
146 DECLARE_GLOBAL_DATA_PTR;
151 print_num ("arch_number", bd->bi_arch_number);
152 print_num ("env_t", (ulong)bd->bi_env);
153 print_num ("boot_params", (ulong)bd->bi_boot_params);
155 for (i=0; i<CONFIG_NR_DRAM_BANKS; ++i) {
156 print_num("DRAM bank", i);
157 print_num("-> start", bd->bi_dram[i].start);
158 print_num("-> size", bd->bi_dram[i].size);
161 printf ("ethaddr =");
162 for (i=0; i<6; ++i) {
163 printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
167 print_IPaddr (bd->bi_ip_addr);
169 "baudrate = %d bps\n", bd->bi_baudrate);
174 #endif /* CONFIG_ARM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
176 static void print_num(const char *name, ulong value)
178 printf ("%-12s= 0x%08lX\n", name, value);
182 static void print_str(const char *name, const char *str)
184 printf ("%-12s= %6s MHz\n", name, str);
186 #endif /* CONFIG_PPC */
188 #endif /* CFG_CMD_BDI */
190 int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
196 printf ("Usage:\n%s\n", cmdtp->usage);
200 addr = simple_strtoul(argv[1], NULL, 16);
202 printf ("## Starting application at 0x%08lX ...\n", addr);
205 * pass address parameter as argv[0] (aka command name),
206 * and all remaining args
208 rc = ((ulong (*)(int, char *[]))addr) (--argc, &argv[1]);
209 if (rc != 0) rcode = 1;
211 printf ("## Application terminated, rc = 0x%lX\n", rc);
215 #if (CONFIG_COMMANDS & CFG_CMD_LOADS)
216 int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
223 #ifdef CFG_LOADS_BAUD_CHANGE
224 DECLARE_GLOBAL_DATA_PTR;
225 int load_baudrate, current_baudrate;
227 load_baudrate = current_baudrate = gd->baudrate;
230 if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
236 #ifdef CFG_LOADS_BAUD_CHANGE
238 offset = simple_strtoul(argv[1], NULL, 16);
241 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
243 /* default to current baudrate */
244 if (load_baudrate == 0)
245 load_baudrate = current_baudrate;
247 #else /* ! CFG_LOADS_BAUD_CHANGE */
249 offset = simple_strtoul(argv[1], NULL, 16);
251 #endif /* CFG_LOADS_BAUD_CHANGE */
253 #ifdef CFG_LOADS_BAUD_CHANGE
254 if (load_baudrate != current_baudrate) {
255 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
258 gd->baudrate = load_baudrate;
266 #endif /* CFG_LOADS_BAUD_CHANGE */
267 printf ("## Ready for S-Record download ...\n");
269 addr = load_serial (offset);
272 * Gather any trailing characters (for instance, the ^D which
273 * is sent by 'cu' after sending a file), and give the
274 * box some time (100 * 1 ms)
276 for (i=0; i<100; ++i) {
278 (void) serial_getc();
284 printf ("## S-Record download aborted\n");
287 printf ("## Start Addr = 0x%08lX\n", addr);
291 #ifdef CFG_LOADS_BAUD_CHANGE
292 if (load_baudrate != current_baudrate) {
293 printf ("## Switch baudrate to %d bps and press ESC ...\n",
296 gd->baudrate = current_baudrate;
300 if (getc() == 0x1B) /* ESC */
309 load_serial (ulong offset)
311 char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */
312 char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */
313 int binlen; /* no. of data bytes in S-Rec. */
314 int type; /* return code for record type */
315 ulong addr; /* load address from S-Record */
316 ulong size; /* number of bytes transferred */
319 ulong start_addr = ~0;
323 while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
324 type = srec_decode (record, &binlen, &addr, binbuf);
327 return (~0); /* Invalid S-Record */
334 store_addr = addr + offset;
335 if (addr2info(store_addr)) {
338 rc = flash_write((uchar *)binbuf,store_addr,binlen);
344 memcpy ((char *)(store_addr), binbuf, binlen);
346 if ((store_addr) < start_addr)
347 start_addr = store_addr;
348 if ((store_addr + binlen - 1) > end_addr)
349 end_addr = store_addr + binlen - 1;
355 size = end_addr - start_addr + 1;
357 "## First Load Addr = 0x%08lX\n"
358 "## Last Load Addr = 0x%08lX\n"
359 "## Total Size = 0x%08lX = %ld Bytes\n",
360 start_addr, end_addr, size, size
362 flush_cache (addr, size);
363 sprintf(buf, "%lX", size);
364 setenv("filesize", buf);
371 if (!do_echo) { /* print a '.' every 100 lines */
372 if ((++line_count % 100) == 0)
377 return (~0); /* Download aborted */
381 read_record (char *buf, ulong len)
386 --len; /* always leave room for terminating '\0' byte */
388 for (p=buf; p < buf+len; ++p) {
389 c = serial_getc(); /* read character */
391 serial_putc (c); /* ... and echo it */
399 case 0x03: /* ^C - Control C */
405 /* Check for the console hangup (if any different from serial) */
407 if (syscall_tbl[SYSCALL_GETC] != serial_getc) {
414 /* line too long - truncate */
419 #if (CONFIG_COMMANDS & CFG_CMD_SAVES)
421 int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
425 #ifdef CFG_LOADS_BAUD_CHANGE
426 DECLARE_GLOBAL_DATA_PTR;
427 int save_baudrate, current_baudrate;
429 save_baudrate = current_baudrate = gd->baudrate;
433 offset = simple_strtoul(argv[1], NULL, 16);
435 #ifdef CFG_LOADS_BAUD_CHANGE
437 size = simple_strtoul(argv[2], NULL, 16);
440 save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
442 /* default to current baudrate */
443 if (save_baudrate == 0)
444 save_baudrate = current_baudrate;
446 #else /* ! CFG_LOADS_BAUD_CHANGE */
448 size = simple_strtoul(argv[2], NULL, 16);
450 #endif /* CFG_LOADS_BAUD_CHANGE */
452 #ifdef CFG_LOADS_BAUD_CHANGE
453 if (save_baudrate != current_baudrate) {
454 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
457 gd->baudrate = save_baudrate;
465 #endif /* CFG_LOADS_BAUD_CHANGE */
466 printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
471 if(save_serial (offset, size)) {
472 printf ("## S-Record upload aborted\n");
474 printf ("## S-Record upload complete\n");
476 #ifdef CFG_LOADS_BAUD_CHANGE
477 if (save_baudrate != current_baudrate) {
478 printf ("## Switch baudrate to %d bps and press ESC ...\n",
479 (int)current_baudrate);
481 gd->baudrate = current_baudrate;
485 if (getc() == 0x1B) /* ESC */
493 #define SREC3_START "S0030000FC\n"
494 #define SREC3_FORMAT "S3%02X%08lX%s%02X\n"
495 #define SREC3_END "S70500000000FA\n"
496 #define SREC_BYTES_PER_RECORD 16
498 static int save_serial (ulong address, ulong count)
500 int i, c, reclen, checksum, length;
501 char *hex = "0123456789ABCDEF";
502 char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
503 char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */
508 if(write_record(SREC3_START)) /* write the header */
511 if(count) { /* collect hex data in the buffer */
512 c = *(volatile uchar*)(address + reclen); /* get one byte */
513 checksum += c; /* accumulate checksum */
514 data[2*reclen] = hex[(c>>4)&0x0f];
515 data[2*reclen+1] = hex[c & 0x0f];
516 data[2*reclen+2] = '\0';
520 if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
521 /* enough data collected for one record: dump it */
522 if(reclen) { /* build & write a data record: */
523 /* address + data + checksum */
524 length = 4 + reclen + 1;
526 /* accumulate length bytes into checksum */
527 for(i = 0; i < 2; i++)
528 checksum += (length >> (8*i)) & 0xff;
530 /* accumulate address bytes into checksum: */
531 for(i = 0; i < 4; i++)
532 checksum += (address >> (8*i)) & 0xff;
534 /* make proper checksum byte: */
535 checksum = ~checksum & 0xff;
537 /* output one record: */
538 sprintf(record, SREC3_FORMAT, length, address, data, checksum);
539 if(write_record(record))
542 address += reclen; /* increment address */
548 if(write_record(SREC3_END)) /* write the final record */
554 write_record (char *buf)
561 /* Check for the console hangup (if any different from serial) */
568 # endif /* CFG_CMD_SAVES */
570 #endif /* CFG_CMD_LOADS */
573 #if (CONFIG_COMMANDS & CFG_CMD_LOADB) /* loadb command (load binary) included */
577 #define START_CHAR 0x01
578 #define ETX_CHAR 0x03
579 #define END_CHAR 0x0D
581 #define K_ESCAPE 0x23
582 #define SEND_TYPE 'S'
583 #define DATA_TYPE 'D'
585 #define NACK_TYPE 'N'
586 #define BREAK_TYPE 'B'
587 #define tochar(x) ((char) (((x) + SPACE) & 0xff))
588 #define untochar(x) ((int) (((x) - SPACE) & 0xff))
590 extern int os_data_count;
591 extern int os_data_header[8];
593 static void set_kerm_bin_mode(unsigned long *);
594 static int k_recv(void);
595 static ulong load_serial_bin (ulong offset);
598 char his_eol; /* character he needs at end of packet */
599 int his_pad_count; /* number of pad chars he needs */
600 char his_pad_char; /* pad chars he needs */
601 char his_quote; /* quote chars he'll use */
603 int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
605 DECLARE_GLOBAL_DATA_PTR;
609 int load_baudrate, current_baudrate;
613 /* pre-set offset from CFG_LOAD_ADDR */
614 offset = CFG_LOAD_ADDR;
616 /* pre-set offset from $loadaddr */
617 if ((s = getenv("loadaddr")) != NULL) {
618 offset = simple_strtoul(s, NULL, 16);
621 load_baudrate = current_baudrate = gd->baudrate;
624 offset = simple_strtoul(argv[1], NULL, 16);
627 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
629 /* default to current baudrate */
630 if (load_baudrate == 0)
631 load_baudrate = current_baudrate;
634 if (load_baudrate != current_baudrate) {
635 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
638 gd->baudrate = load_baudrate;
647 printf ("## Ready for binary (kermit) download "
648 "to 0x%08lX at %d bps...\n",
651 addr = load_serial_bin (offset);
655 printf ("## Binary (kermit) download aborted\n");
658 printf ("## Start Addr = 0x%08lX\n", addr);
662 if (load_baudrate != current_baudrate) {
663 printf ("## Switch baudrate to %d bps and press ESC ...\n",
666 gd->baudrate = current_baudrate;
670 if (getc() == 0x1B) /* ESC */
675 #ifdef CONFIG_AUTOSCRIPT
679 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
680 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
681 rcode = autoscript (load_addr);
689 static ulong load_serial_bin (ulong offset)
694 set_kerm_bin_mode ((ulong *) offset);
696 flush_cache (offset, size);
698 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
699 sprintf(buf, "%X", size);
700 setenv("filesize", buf);
707 int count = his_pad_count;
710 serial_putc (his_pad_char);
713 /* converts escaped kermit char to binary char */
714 char ktrans (char in)
716 if ((in & 0x60) == 0x40) {
717 return (char) (in & ~0x40);
718 } else if ((in & 0x7f) == 0x3f) {
719 return (char) (in | 0x40);
724 int chk1 (char *buffer)
731 return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
734 void s1_sendpacket (char *packet)
738 serial_putc (*packet++);
743 void send_ack (int n)
750 a_b[4] = tochar (chk1 (&a_b[1]));
756 void send_nack (int n)
763 a_b[4] = tochar (chk1 (&a_b[1]));
771 /* os_data_* takes an OS Open image and puts it into memory, and
772 puts the boot header in an array named os_data_header
774 if image is binary, no header is stored in os_data_header.
776 void (*os_data_init) (void);
777 void (*os_data_char) (char new_char);
778 static int os_data_state, os_data_state_saved;
780 static int os_data_count_saved;
781 static char *os_data_addr, *os_data_addr_saved;
782 static char *bin_start_address;
783 int os_data_header[8];
784 static void bin_data_init (void)
788 os_data_addr = bin_start_address;
790 static void os_data_save (void)
792 os_data_state_saved = os_data_state;
793 os_data_count_saved = os_data_count;
794 os_data_addr_saved = os_data_addr;
796 static void os_data_restore (void)
798 os_data_state = os_data_state_saved;
799 os_data_count = os_data_count_saved;
800 os_data_addr = os_data_addr_saved;
802 static void bin_data_char (char new_char)
804 switch (os_data_state) {
806 *os_data_addr++ = new_char;
811 static void set_kerm_bin_mode (unsigned long *addr)
813 bin_start_address = (char *) addr;
814 os_data_init = bin_data_init;
815 os_data_char = bin_data_char;
819 /* k_data_* simply handles the kermit escape translations */
820 static int k_data_escape, k_data_escape_saved;
821 void k_data_init (void)
826 void k_data_save (void)
828 k_data_escape_saved = k_data_escape;
831 void k_data_restore (void)
833 k_data_escape = k_data_escape_saved;
836 void k_data_char (char new_char)
839 /* last char was escape - translate this character */
840 os_data_char (ktrans (new_char));
843 if (new_char == his_quote) {
844 /* this char is escape - remember */
847 /* otherwise send this char as-is */
848 os_data_char (new_char);
853 #define SEND_DATA_SIZE 20
854 char send_parms[SEND_DATA_SIZE];
857 /* handle_send_packet interprits the protocol info and builds and
858 sends an appropriate ack for what we can do */
859 void handle_send_packet (int n)
864 /* initialize some protocol parameters */
865 his_eol = END_CHAR; /* default end of line character */
868 his_quote = K_ESCAPE;
870 /* ignore last character if it filled the buffer */
871 if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
873 bytes = send_ptr - send_parms; /* how many bytes we'll process */
877 /* handle MAXL - max length */
878 /* ignore what he says - most I'll take (here) is 94 */
879 a_b[++length] = tochar (94);
882 /* handle TIME - time you should wait for my packets */
883 /* ignore what he says - don't wait for my ack longer than 1 second */
884 a_b[++length] = tochar (1);
887 /* handle NPAD - number of pad chars I need */
888 /* remember what he says - I need none */
889 his_pad_count = untochar (send_parms[2]);
890 a_b[++length] = tochar (0);
893 /* handle PADC - pad chars I need */
894 /* remember what he says - I need none */
895 his_pad_char = ktrans (send_parms[3]);
896 a_b[++length] = 0x40; /* He should ignore this */
899 /* handle EOL - end of line he needs */
900 /* remember what he says - I need CR */
901 his_eol = untochar (send_parms[4]);
902 a_b[++length] = tochar (END_CHAR);
905 /* handle QCTL - quote control char he'll use */
906 /* remember what he says - I'll use '#' */
907 his_quote = send_parms[5];
911 /* handle QBIN - 8-th bit prefixing */
912 /* ignore what he says - I refuse */
916 /* handle CHKT - the clock check type */
917 /* ignore what he says - I do type 1 (for now) */
921 /* handle REPT - the repeat prefix */
922 /* ignore what he says - I refuse (for now) */
926 /* handle CAPAS - the capabilities mask */
927 /* ignore what he says - I only do long packets - I don't do windows */
928 a_b[++length] = tochar (2); /* only long packets */
929 a_b[++length] = tochar (0); /* no windows */
930 a_b[++length] = tochar (94); /* large packet msb */
931 a_b[++length] = tochar (94); /* large packet lsb */
935 a_b[1] = tochar (length);
938 a_b[++length] = '\0';
939 a_b[length] = tochar (chk1 (&a_b[1]));
940 a_b[++length] = his_eol;
941 a_b[++length] = '\0';
945 /* k_recv receives a OS Open image file over kermit line */
946 static int k_recv (void)
949 char k_state, k_state_saved;
957 /* initialize some protocol parameters */
958 his_eol = END_CHAR; /* default end of line character */
961 his_quote = K_ESCAPE;
963 /* initialize the k_recv and k_data state machine */
967 k_state_saved = k_state;
969 n = 0; /* just to get rid of a warning */
972 /* expect this "type" sequence (but don't check):
977 B: break transmission
980 /* enter main loop */
982 /* set the send packet pointer to begining of send packet parms */
983 send_ptr = send_parms;
985 /* With each packet, start summing the bytes starting with the length.
986 Save the current sequence number.
987 Note the type of the packet.
988 If a character less than SPACE (0x20) is received - error.
992 /* OLD CODE, Prior to checking sequence numbers */
993 /* first have all state machines save current states */
994 k_state_saved = k_state;
999 /* wait for the starting character or ^C */
1001 switch (serial_getc ()) {
1002 case START_CHAR: /* start packet */
1004 case ETX_CHAR: /* ^C waiting for packet */
1011 /* get length of packet */
1013 new_char = serial_getc ();
1014 if ((new_char & 0xE0) == 0)
1016 sum += new_char & 0xff;
1017 length = untochar (new_char);
1018 /* get sequence number */
1019 new_char = serial_getc ();
1020 if ((new_char & 0xE0) == 0)
1022 sum += new_char & 0xff;
1023 n = untochar (new_char);
1026 /* NEW CODE - check sequence numbers for retried packets */
1027 /* Note - this new code assumes that the sequence number is correctly
1028 * received. Handling an invalid sequence number adds another layer
1029 * of complexity that may not be needed - yet! At this time, I'm hoping
1030 * that I don't need to buffer the incoming data packets and can write
1031 * the data into memory in real time.
1034 /* same sequence number, restore the previous state */
1035 k_state = k_state_saved;
1038 /* new sequence number, checkpoint the download */
1040 k_state_saved = k_state;
1045 /* get packet type */
1046 new_char = serial_getc ();
1047 if ((new_char & 0xE0) == 0)
1049 sum += new_char & 0xff;
1052 /* check for extended length */
1054 /* (length byte was 0, decremented twice) */
1055 /* get the two length bytes */
1056 new_char = serial_getc ();
1057 if ((new_char & 0xE0) == 0)
1059 sum += new_char & 0xff;
1060 len_hi = untochar (new_char);
1061 new_char = serial_getc ();
1062 if ((new_char & 0xE0) == 0)
1064 sum += new_char & 0xff;
1065 len_lo = untochar (new_char);
1066 length = len_hi * 95 + len_lo;
1067 /* check header checksum */
1068 new_char = serial_getc ();
1069 if ((new_char & 0xE0) == 0)
1071 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1073 sum += new_char & 0xff;
1074 /* --length; */ /* new length includes only data and block check to come */
1076 /* bring in rest of packet */
1077 while (length > 1) {
1078 new_char = serial_getc ();
1079 if ((new_char & 0xE0) == 0)
1081 sum += new_char & 0xff;
1083 if (k_state == DATA_TYPE) {
1084 /* pass on the data if this is a data packet */
1085 k_data_char (new_char);
1086 } else if (k_state == SEND_TYPE) {
1087 /* save send pack in buffer as is */
1088 *send_ptr++ = new_char;
1089 /* if too much data, back off the pointer */
1090 if (send_ptr >= &send_parms[SEND_DATA_SIZE])
1094 /* get and validate checksum character */
1095 new_char = serial_getc ();
1096 if ((new_char & 0xE0) == 0)
1098 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1101 new_char = serial_getc ();
1102 if (new_char != END_CHAR) {
1104 /* restore state machines */
1105 k_state = k_state_saved;
1107 /* send a negative acknowledge packet in */
1109 } else if (k_state == SEND_TYPE) {
1110 /* crack the protocol parms, build an appropriate ack packet */
1111 handle_send_packet (n);
1113 /* send simple acknowledge packet in */
1115 /* quit if end of transmission */
1116 if (k_state == BREAK_TYPE)
1121 return ((ulong) os_data_addr - (ulong) bin_start_address);
1123 #endif /* CFG_CMD_LOADB */
1124 #if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
1125 int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1127 extern int hwflow_onoff(int);
1130 if (strcmp(argv[1], "off") == 0)
1133 if (strcmp(argv[1], "on") == 0)
1136 printf("Usage: %s\n", cmdtp->usage);
1138 printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
1141 #endif /* CFG_CMD_HWFLOW */