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;
336 if (addr2info(store_addr)) {
339 rc = flash_write((uchar *)binbuf,store_addr,binlen);
347 memcpy ((char *)(store_addr), binbuf, binlen);
349 if ((store_addr) < start_addr)
350 start_addr = store_addr;
351 if ((store_addr + binlen - 1) > end_addr)
352 end_addr = store_addr + binlen - 1;
358 size = end_addr - start_addr + 1;
360 "## First Load Addr = 0x%08lX\n"
361 "## Last Load Addr = 0x%08lX\n"
362 "## Total Size = 0x%08lX = %ld Bytes\n",
363 start_addr, end_addr, size, size
365 flush_cache (addr, size);
366 sprintf(buf, "%lX", size);
367 setenv("filesize", buf);
374 if (!do_echo) { /* print a '.' every 100 lines */
375 if ((++line_count % 100) == 0)
380 return (~0); /* Download aborted */
384 read_record (char *buf, ulong len)
389 --len; /* always leave room for terminating '\0' byte */
391 for (p=buf; p < buf+len; ++p) {
392 c = serial_getc(); /* read character */
394 serial_putc (c); /* ... and echo it */
402 case 0x03: /* ^C - Control C */
408 /* Check for the console hangup (if any different from serial) */
410 if (syscall_tbl[SYSCALL_GETC] != serial_getc) {
417 /* line too long - truncate */
422 #if (CONFIG_COMMANDS & CFG_CMD_SAVES)
424 int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
428 #ifdef CFG_LOADS_BAUD_CHANGE
429 DECLARE_GLOBAL_DATA_PTR;
430 int save_baudrate, current_baudrate;
432 save_baudrate = current_baudrate = gd->baudrate;
436 offset = simple_strtoul(argv[1], NULL, 16);
438 #ifdef CFG_LOADS_BAUD_CHANGE
440 size = simple_strtoul(argv[2], NULL, 16);
443 save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
445 /* default to current baudrate */
446 if (save_baudrate == 0)
447 save_baudrate = current_baudrate;
449 #else /* ! CFG_LOADS_BAUD_CHANGE */
451 size = simple_strtoul(argv[2], NULL, 16);
453 #endif /* CFG_LOADS_BAUD_CHANGE */
455 #ifdef CFG_LOADS_BAUD_CHANGE
456 if (save_baudrate != current_baudrate) {
457 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
460 gd->baudrate = save_baudrate;
468 #endif /* CFG_LOADS_BAUD_CHANGE */
469 printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
474 if(save_serial (offset, size)) {
475 printf ("## S-Record upload aborted\n");
477 printf ("## S-Record upload complete\n");
479 #ifdef CFG_LOADS_BAUD_CHANGE
480 if (save_baudrate != current_baudrate) {
481 printf ("## Switch baudrate to %d bps and press ESC ...\n",
482 (int)current_baudrate);
484 gd->baudrate = current_baudrate;
488 if (getc() == 0x1B) /* ESC */
496 #define SREC3_START "S0030000FC\n"
497 #define SREC3_FORMAT "S3%02X%08lX%s%02X\n"
498 #define SREC3_END "S70500000000FA\n"
499 #define SREC_BYTES_PER_RECORD 16
501 static int save_serial (ulong address, ulong count)
503 int i, c, reclen, checksum, length;
504 char *hex = "0123456789ABCDEF";
505 char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
506 char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */
511 if(write_record(SREC3_START)) /* write the header */
514 if(count) { /* collect hex data in the buffer */
515 c = *(volatile uchar*)(address + reclen); /* get one byte */
516 checksum += c; /* accumulate checksum */
517 data[2*reclen] = hex[(c>>4)&0x0f];
518 data[2*reclen+1] = hex[c & 0x0f];
519 data[2*reclen+2] = '\0';
523 if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
524 /* enough data collected for one record: dump it */
525 if(reclen) { /* build & write a data record: */
526 /* address + data + checksum */
527 length = 4 + reclen + 1;
529 /* accumulate length bytes into checksum */
530 for(i = 0; i < 2; i++)
531 checksum += (length >> (8*i)) & 0xff;
533 /* accumulate address bytes into checksum: */
534 for(i = 0; i < 4; i++)
535 checksum += (address >> (8*i)) & 0xff;
537 /* make proper checksum byte: */
538 checksum = ~checksum & 0xff;
540 /* output one record: */
541 sprintf(record, SREC3_FORMAT, length, address, data, checksum);
542 if(write_record(record))
545 address += reclen; /* increment address */
551 if(write_record(SREC3_END)) /* write the final record */
557 write_record (char *buf)
564 /* Check for the console hangup (if any different from serial) */
571 # endif /* CFG_CMD_SAVES */
573 #endif /* CFG_CMD_LOADS */
576 #if (CONFIG_COMMANDS & CFG_CMD_LOADB) /* loadb command (load binary) included */
580 #define START_CHAR 0x01
581 #define ETX_CHAR 0x03
582 #define END_CHAR 0x0D
584 #define K_ESCAPE 0x23
585 #define SEND_TYPE 'S'
586 #define DATA_TYPE 'D'
588 #define NACK_TYPE 'N'
589 #define BREAK_TYPE 'B'
590 #define tochar(x) ((char) (((x) + SPACE) & 0xff))
591 #define untochar(x) ((int) (((x) - SPACE) & 0xff))
593 extern int os_data_count;
594 extern int os_data_header[8];
596 static void set_kerm_bin_mode(unsigned long *);
597 static int k_recv(void);
598 static ulong load_serial_bin (ulong offset);
601 char his_eol; /* character he needs at end of packet */
602 int his_pad_count; /* number of pad chars he needs */
603 char his_pad_char; /* pad chars he needs */
604 char his_quote; /* quote chars he'll use */
606 int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
608 DECLARE_GLOBAL_DATA_PTR;
612 int load_baudrate, current_baudrate;
616 /* pre-set offset from CFG_LOAD_ADDR */
617 offset = CFG_LOAD_ADDR;
619 /* pre-set offset from $loadaddr */
620 if ((s = getenv("loadaddr")) != NULL) {
621 offset = simple_strtoul(s, NULL, 16);
624 load_baudrate = current_baudrate = gd->baudrate;
627 offset = simple_strtoul(argv[1], NULL, 16);
630 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
632 /* default to current baudrate */
633 if (load_baudrate == 0)
634 load_baudrate = current_baudrate;
637 if (load_baudrate != current_baudrate) {
638 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
641 gd->baudrate = load_baudrate;
650 printf ("## Ready for binary (kermit) download "
651 "to 0x%08lX at %d bps...\n",
654 addr = load_serial_bin (offset);
658 printf ("## Binary (kermit) download aborted\n");
661 printf ("## Start Addr = 0x%08lX\n", addr);
665 if (load_baudrate != current_baudrate) {
666 printf ("## Switch baudrate to %d bps and press ESC ...\n",
669 gd->baudrate = current_baudrate;
673 if (getc() == 0x1B) /* ESC */
678 #ifdef CONFIG_AUTOSCRIPT
682 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
683 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
684 rcode = autoscript (load_addr);
692 static ulong load_serial_bin (ulong offset)
697 set_kerm_bin_mode ((ulong *) offset);
699 flush_cache (offset, size);
701 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
702 sprintf(buf, "%X", size);
703 setenv("filesize", buf);
710 int count = his_pad_count;
713 serial_putc (his_pad_char);
716 /* converts escaped kermit char to binary char */
717 char ktrans (char in)
719 if ((in & 0x60) == 0x40) {
720 return (char) (in & ~0x40);
721 } else if ((in & 0x7f) == 0x3f) {
722 return (char) (in | 0x40);
727 int chk1 (char *buffer)
734 return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
737 void s1_sendpacket (char *packet)
741 serial_putc (*packet++);
746 void send_ack (int n)
753 a_b[4] = tochar (chk1 (&a_b[1]));
759 void send_nack (int n)
766 a_b[4] = tochar (chk1 (&a_b[1]));
774 /* os_data_* takes an OS Open image and puts it into memory, and
775 puts the boot header in an array named os_data_header
777 if image is binary, no header is stored in os_data_header.
779 void (*os_data_init) (void);
780 void (*os_data_char) (char new_char);
781 static int os_data_state, os_data_state_saved;
783 static int os_data_count_saved;
784 static char *os_data_addr, *os_data_addr_saved;
785 static char *bin_start_address;
786 int os_data_header[8];
787 static void bin_data_init (void)
791 os_data_addr = bin_start_address;
793 static void os_data_save (void)
795 os_data_state_saved = os_data_state;
796 os_data_count_saved = os_data_count;
797 os_data_addr_saved = os_data_addr;
799 static void os_data_restore (void)
801 os_data_state = os_data_state_saved;
802 os_data_count = os_data_count_saved;
803 os_data_addr = os_data_addr_saved;
805 static void bin_data_char (char new_char)
807 switch (os_data_state) {
809 *os_data_addr++ = new_char;
814 static void set_kerm_bin_mode (unsigned long *addr)
816 bin_start_address = (char *) addr;
817 os_data_init = bin_data_init;
818 os_data_char = bin_data_char;
822 /* k_data_* simply handles the kermit escape translations */
823 static int k_data_escape, k_data_escape_saved;
824 void k_data_init (void)
829 void k_data_save (void)
831 k_data_escape_saved = k_data_escape;
834 void k_data_restore (void)
836 k_data_escape = k_data_escape_saved;
839 void k_data_char (char new_char)
842 /* last char was escape - translate this character */
843 os_data_char (ktrans (new_char));
846 if (new_char == his_quote) {
847 /* this char is escape - remember */
850 /* otherwise send this char as-is */
851 os_data_char (new_char);
856 #define SEND_DATA_SIZE 20
857 char send_parms[SEND_DATA_SIZE];
860 /* handle_send_packet interprits the protocol info and builds and
861 sends an appropriate ack for what we can do */
862 void handle_send_packet (int n)
867 /* initialize some protocol parameters */
868 his_eol = END_CHAR; /* default end of line character */
871 his_quote = K_ESCAPE;
873 /* ignore last character if it filled the buffer */
874 if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
876 bytes = send_ptr - send_parms; /* how many bytes we'll process */
880 /* handle MAXL - max length */
881 /* ignore what he says - most I'll take (here) is 94 */
882 a_b[++length] = tochar (94);
885 /* handle TIME - time you should wait for my packets */
886 /* ignore what he says - don't wait for my ack longer than 1 second */
887 a_b[++length] = tochar (1);
890 /* handle NPAD - number of pad chars I need */
891 /* remember what he says - I need none */
892 his_pad_count = untochar (send_parms[2]);
893 a_b[++length] = tochar (0);
896 /* handle PADC - pad chars I need */
897 /* remember what he says - I need none */
898 his_pad_char = ktrans (send_parms[3]);
899 a_b[++length] = 0x40; /* He should ignore this */
902 /* handle EOL - end of line he needs */
903 /* remember what he says - I need CR */
904 his_eol = untochar (send_parms[4]);
905 a_b[++length] = tochar (END_CHAR);
908 /* handle QCTL - quote control char he'll use */
909 /* remember what he says - I'll use '#' */
910 his_quote = send_parms[5];
914 /* handle QBIN - 8-th bit prefixing */
915 /* ignore what he says - I refuse */
919 /* handle CHKT - the clock check type */
920 /* ignore what he says - I do type 1 (for now) */
924 /* handle REPT - the repeat prefix */
925 /* ignore what he says - I refuse (for now) */
929 /* handle CAPAS - the capabilities mask */
930 /* ignore what he says - I only do long packets - I don't do windows */
931 a_b[++length] = tochar (2); /* only long packets */
932 a_b[++length] = tochar (0); /* no windows */
933 a_b[++length] = tochar (94); /* large packet msb */
934 a_b[++length] = tochar (94); /* large packet lsb */
938 a_b[1] = tochar (length);
941 a_b[++length] = '\0';
942 a_b[length] = tochar (chk1 (&a_b[1]));
943 a_b[++length] = his_eol;
944 a_b[++length] = '\0';
948 /* k_recv receives a OS Open image file over kermit line */
949 static int k_recv (void)
952 char k_state, k_state_saved;
960 /* initialize some protocol parameters */
961 his_eol = END_CHAR; /* default end of line character */
964 his_quote = K_ESCAPE;
966 /* initialize the k_recv and k_data state machine */
970 k_state_saved = k_state;
972 n = 0; /* just to get rid of a warning */
975 /* expect this "type" sequence (but don't check):
980 B: break transmission
983 /* enter main loop */
985 /* set the send packet pointer to begining of send packet parms */
986 send_ptr = send_parms;
988 /* With each packet, start summing the bytes starting with the length.
989 Save the current sequence number.
990 Note the type of the packet.
991 If a character less than SPACE (0x20) is received - error.
995 /* OLD CODE, Prior to checking sequence numbers */
996 /* first have all state machines save current states */
997 k_state_saved = k_state;
1002 /* wait for the starting character or ^C */
1004 switch (serial_getc ()) {
1005 case START_CHAR: /* start packet */
1007 case ETX_CHAR: /* ^C waiting for packet */
1014 /* get length of packet */
1016 new_char = serial_getc ();
1017 if ((new_char & 0xE0) == 0)
1019 sum += new_char & 0xff;
1020 length = untochar (new_char);
1021 /* get sequence number */
1022 new_char = serial_getc ();
1023 if ((new_char & 0xE0) == 0)
1025 sum += new_char & 0xff;
1026 n = untochar (new_char);
1029 /* NEW CODE - check sequence numbers for retried packets */
1030 /* Note - this new code assumes that the sequence number is correctly
1031 * received. Handling an invalid sequence number adds another layer
1032 * of complexity that may not be needed - yet! At this time, I'm hoping
1033 * that I don't need to buffer the incoming data packets and can write
1034 * the data into memory in real time.
1037 /* same sequence number, restore the previous state */
1038 k_state = k_state_saved;
1041 /* new sequence number, checkpoint the download */
1043 k_state_saved = k_state;
1048 /* get packet type */
1049 new_char = serial_getc ();
1050 if ((new_char & 0xE0) == 0)
1052 sum += new_char & 0xff;
1055 /* check for extended length */
1057 /* (length byte was 0, decremented twice) */
1058 /* get the two length bytes */
1059 new_char = serial_getc ();
1060 if ((new_char & 0xE0) == 0)
1062 sum += new_char & 0xff;
1063 len_hi = untochar (new_char);
1064 new_char = serial_getc ();
1065 if ((new_char & 0xE0) == 0)
1067 sum += new_char & 0xff;
1068 len_lo = untochar (new_char);
1069 length = len_hi * 95 + len_lo;
1070 /* check header checksum */
1071 new_char = serial_getc ();
1072 if ((new_char & 0xE0) == 0)
1074 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1076 sum += new_char & 0xff;
1077 /* --length; */ /* new length includes only data and block check to come */
1079 /* bring in rest of packet */
1080 while (length > 1) {
1081 new_char = serial_getc ();
1082 if ((new_char & 0xE0) == 0)
1084 sum += new_char & 0xff;
1086 if (k_state == DATA_TYPE) {
1087 /* pass on the data if this is a data packet */
1088 k_data_char (new_char);
1089 } else if (k_state == SEND_TYPE) {
1090 /* save send pack in buffer as is */
1091 *send_ptr++ = new_char;
1092 /* if too much data, back off the pointer */
1093 if (send_ptr >= &send_parms[SEND_DATA_SIZE])
1097 /* get and validate checksum character */
1098 new_char = serial_getc ();
1099 if ((new_char & 0xE0) == 0)
1101 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1104 new_char = serial_getc ();
1105 if (new_char != END_CHAR) {
1107 /* restore state machines */
1108 k_state = k_state_saved;
1110 /* send a negative acknowledge packet in */
1112 } else if (k_state == SEND_TYPE) {
1113 /* crack the protocol parms, build an appropriate ack packet */
1114 handle_send_packet (n);
1116 /* send simple acknowledge packet in */
1118 /* quit if end of transmission */
1119 if (k_state == BREAK_TYPE)
1124 return ((ulong) os_data_addr - (ulong) bin_start_address);
1126 #endif /* CFG_CMD_LOADB */
1127 #if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
1128 int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1130 extern int hwflow_onoff(int);
1133 if (strcmp(argv[1], "off") == 0)
1136 if (strcmp(argv[1], "on") == 0)
1139 printf("Usage: %s\n", cmdtp->usage);
1141 printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
1144 #endif /* CFG_CMD_HWFLOW */