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_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 END_CHAR 0x0D
580 #define K_ESCAPE 0x23
581 #define SEND_TYPE 'S'
582 #define DATA_TYPE 'D'
584 #define NACK_TYPE 'N'
585 #define BREAK_TYPE 'B'
586 #define tochar(x) ((char) (((x) + SPACE) & 0xff))
587 #define untochar(x) ((int) (((x) - SPACE) & 0xff))
589 extern int os_data_count;
590 extern int os_data_header[8];
592 static void set_kerm_bin_mode(unsigned long *);
593 static int k_recv(void);
594 static ulong load_serial_bin (ulong offset);
597 char his_eol; /* character he needs at end of packet */
598 int his_pad_count; /* number of pad chars he needs */
599 char his_pad_char; /* pad chars he needs */
600 char his_quote; /* quote chars he'll use */
602 int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
604 DECLARE_GLOBAL_DATA_PTR;
608 int load_baudrate, current_baudrate;
612 /* pre-set offset from CFG_LOAD_ADDR */
613 offset = CFG_LOAD_ADDR;
615 /* pre-set offset from $loadaddr */
616 if ((s = getenv("loadaddr")) != NULL) {
617 offset = simple_strtoul(s, NULL, 16);
620 load_baudrate = current_baudrate = gd->baudrate;
623 offset = simple_strtoul(argv[1], NULL, 16);
626 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
628 /* default to current baudrate */
629 if (load_baudrate == 0)
630 load_baudrate = current_baudrate;
633 if (load_baudrate != current_baudrate) {
634 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
637 gd->baudrate = load_baudrate;
646 printf ("## Ready for binary (kermit) download "
647 "to 0x%08lX at %d bps...\n",
650 addr = load_serial_bin (offset);
654 printf ("## Binary (kermit) download aborted\n");
657 printf ("## Start Addr = 0x%08lX\n", addr);
661 if (load_baudrate != current_baudrate) {
662 printf ("## Switch baudrate to %d bps and press ESC ...\n",
665 gd->baudrate = current_baudrate;
669 if (getc() == 0x1B) /* ESC */
674 #ifdef CONFIG_AUTOSCRIPT
678 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
679 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
680 rcode = autoscript (load_addr);
688 static ulong load_serial_bin (ulong offset)
693 set_kerm_bin_mode ((ulong *) offset);
695 flush_cache (offset, size);
697 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
698 sprintf(buf, "%X", size);
699 setenv("filesize", buf);
706 int count = his_pad_count;
709 serial_putc (his_pad_char);
712 /* converts escaped kermit char to binary char */
713 char ktrans (char in)
715 if ((in & 0x60) == 0x40) {
716 return (char) (in & ~0x40);
717 } else if ((in & 0x7f) == 0x3f) {
718 return (char) (in | 0x40);
723 int chk1 (char *buffer)
730 return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
733 void s1_sendpacket (char *packet)
737 serial_putc (*packet++);
742 void send_ack (int n)
749 a_b[4] = tochar (chk1 (&a_b[1]));
755 void send_nack (int n)
762 a_b[4] = tochar (chk1 (&a_b[1]));
770 /* os_data_* takes an OS Open image and puts it into memory, and
771 puts the boot header in an array named os_data_header
773 if image is binary, no header is stored in os_data_header.
775 void (*os_data_init) (void);
776 void (*os_data_char) (char new_char);
777 static int os_data_state, os_data_state_saved;
779 static int os_data_count_saved;
780 static char *os_data_addr, *os_data_addr_saved;
781 static char *bin_start_address;
782 int os_data_header[8];
783 static void bin_data_init (void)
787 os_data_addr = bin_start_address;
789 static void os_data_save (void)
791 os_data_state_saved = os_data_state;
792 os_data_count_saved = os_data_count;
793 os_data_addr_saved = os_data_addr;
795 static void os_data_restore (void)
797 os_data_state = os_data_state_saved;
798 os_data_count = os_data_count_saved;
799 os_data_addr = os_data_addr_saved;
801 static void bin_data_char (char new_char)
803 switch (os_data_state) {
805 *os_data_addr++ = new_char;
810 static void set_kerm_bin_mode (unsigned long *addr)
812 bin_start_address = (char *) addr;
813 os_data_init = bin_data_init;
814 os_data_char = bin_data_char;
818 /* k_data_* simply handles the kermit escape translations */
819 static int k_data_escape, k_data_escape_saved;
820 void k_data_init (void)
825 void k_data_save (void)
827 k_data_escape_saved = k_data_escape;
830 void k_data_restore (void)
832 k_data_escape = k_data_escape_saved;
835 void k_data_char (char new_char)
838 /* last char was escape - translate this character */
839 os_data_char (ktrans (new_char));
842 if (new_char == his_quote) {
843 /* this char is escape - remember */
846 /* otherwise send this char as-is */
847 os_data_char (new_char);
852 #define SEND_DATA_SIZE 20
853 char send_parms[SEND_DATA_SIZE];
856 /* handle_send_packet interprits the protocol info and builds and
857 sends an appropriate ack for what we can do */
858 void handle_send_packet (int n)
863 /* initialize some protocol parameters */
864 his_eol = END_CHAR; /* default end of line character */
867 his_quote = K_ESCAPE;
869 /* ignore last character if it filled the buffer */
870 if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
872 bytes = send_ptr - send_parms; /* how many bytes we'll process */
876 /* handle MAXL - max length */
877 /* ignore what he says - most I'll take (here) is 94 */
878 a_b[++length] = tochar (94);
881 /* handle TIME - time you should wait for my packets */
882 /* ignore what he says - don't wait for my ack longer than 1 second */
883 a_b[++length] = tochar (1);
886 /* handle NPAD - number of pad chars I need */
887 /* remember what he says - I need none */
888 his_pad_count = untochar (send_parms[2]);
889 a_b[++length] = tochar (0);
892 /* handle PADC - pad chars I need */
893 /* remember what he says - I need none */
894 his_pad_char = ktrans (send_parms[3]);
895 a_b[++length] = 0x40; /* He should ignore this */
898 /* handle EOL - end of line he needs */
899 /* remember what he says - I need CR */
900 his_eol = untochar (send_parms[4]);
901 a_b[++length] = tochar (END_CHAR);
904 /* handle QCTL - quote control char he'll use */
905 /* remember what he says - I'll use '#' */
906 his_quote = send_parms[5];
910 /* handle QBIN - 8-th bit prefixing */
911 /* ignore what he says - I refuse */
915 /* handle CHKT - the clock check type */
916 /* ignore what he says - I do type 1 (for now) */
920 /* handle REPT - the repeat prefix */
921 /* ignore what he says - I refuse (for now) */
925 /* handle CAPAS - the capabilities mask */
926 /* ignore what he says - I only do long packets - I don't do windows */
927 a_b[++length] = tochar (2); /* only long packets */
928 a_b[++length] = tochar (0); /* no windows */
929 a_b[++length] = tochar (94); /* large packet msb */
930 a_b[++length] = tochar (94); /* large packet lsb */
934 a_b[1] = tochar (length);
937 a_b[++length] = '\0';
938 a_b[length] = tochar (chk1 (&a_b[1]));
939 a_b[++length] = his_eol;
940 a_b[++length] = '\0';
944 /* k_recv receives a OS Open image file over kermit line */
945 static int k_recv (void)
948 char k_state, k_state_saved;
956 /* initialize some protocol parameters */
957 his_eol = END_CHAR; /* default end of line character */
960 his_quote = K_ESCAPE;
962 /* initialize the k_recv and k_data state machine */
966 k_state_saved = k_state;
968 n = 0; /* just to get rid of a warning */
971 /* expect this "type" sequence (but don't check):
976 B: break transmission
979 /* enter main loop */
981 /* set the send packet pointer to begining of send packet parms */
982 send_ptr = send_parms;
984 /* With each packet, start summing the bytes starting with the length.
985 Save the current sequence number.
986 Note the type of the packet.
987 If a character less than SPACE (0x20) is received - error.
991 /* OLD CODE, Prior to checking sequence numbers */
992 /* first have all state machines save current states */
993 k_state_saved = k_state;
998 /* wait for the starting character */
999 while (serial_getc () != START_CHAR);
1000 /* get length of packet */
1002 new_char = serial_getc ();
1003 if ((new_char & 0xE0) == 0)
1005 sum += new_char & 0xff;
1006 length = untochar (new_char);
1007 /* get sequence number */
1008 new_char = serial_getc ();
1009 if ((new_char & 0xE0) == 0)
1011 sum += new_char & 0xff;
1012 n = untochar (new_char);
1015 /* NEW CODE - check sequence numbers for retried packets */
1016 /* Note - this new code assumes that the sequence number is correctly
1017 * received. Handling an invalid sequence number adds another layer
1018 * of complexity that may not be needed - yet! At this time, I'm hoping
1019 * that I don't need to buffer the incoming data packets and can write
1020 * the data into memory in real time.
1023 /* same sequence number, restore the previous state */
1024 k_state = k_state_saved;
1027 /* new sequence number, checkpoint the download */
1029 k_state_saved = k_state;
1034 /* get packet type */
1035 new_char = serial_getc ();
1036 if ((new_char & 0xE0) == 0)
1038 sum += new_char & 0xff;
1041 /* check for extended length */
1043 /* (length byte was 0, decremented twice) */
1044 /* get the two length bytes */
1045 new_char = serial_getc ();
1046 if ((new_char & 0xE0) == 0)
1048 sum += new_char & 0xff;
1049 len_hi = untochar (new_char);
1050 new_char = serial_getc ();
1051 if ((new_char & 0xE0) == 0)
1053 sum += new_char & 0xff;
1054 len_lo = untochar (new_char);
1055 length = len_hi * 95 + len_lo;
1056 /* check header checksum */
1057 new_char = serial_getc ();
1058 if ((new_char & 0xE0) == 0)
1060 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1062 sum += new_char & 0xff;
1063 /* --length; */ /* new length includes only data and block check to come */
1065 /* bring in rest of packet */
1066 while (length > 1) {
1067 new_char = serial_getc ();
1068 if ((new_char & 0xE0) == 0)
1070 sum += new_char & 0xff;
1072 if (k_state == DATA_TYPE) {
1073 /* pass on the data if this is a data packet */
1074 k_data_char (new_char);
1075 } else if (k_state == SEND_TYPE) {
1076 /* save send pack in buffer as is */
1077 *send_ptr++ = new_char;
1078 /* if too much data, back off the pointer */
1079 if (send_ptr >= &send_parms[SEND_DATA_SIZE])
1083 /* get and validate checksum character */
1084 new_char = serial_getc ();
1085 if ((new_char & 0xE0) == 0)
1087 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1090 new_char = serial_getc ();
1091 if (new_char != END_CHAR) {
1093 /* restore state machines */
1094 k_state = k_state_saved;
1096 /* send a negative acknowledge packet in */
1098 } else if (k_state == SEND_TYPE) {
1099 /* crack the protocol parms, build an appropriate ack packet */
1100 handle_send_packet (n);
1102 /* send simple acknowledge packet in */
1104 /* quit if end of transmission */
1105 if (k_state == BREAK_TYPE)
1110 return ((ulong) os_data_addr - (ulong) bin_start_address);
1112 #endif /* CFG_CMD_LOADB */
1113 #if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
1114 int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1116 extern int hwflow_onoff(int);
1119 if (strcmp(argv[1], "off") == 0)
1122 if (strcmp(argv[1], "on") == 0)
1125 printf("Usage: %s\n", cmdtp->usage);
1127 printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
1130 #endif /* CFG_CMD_HWFLOW */