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 printf ("DRAM:%02d.start = %08lX\n",
157 i, bd->bi_dram[i].start);
158 printf ("DRAM:%02d.size = %08lX\n",
159 i, bd->bi_dram[i].size);
162 printf ("ethaddr =");
163 for (i=0; i<6; ++i) {
164 printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);
168 print_IPaddr (bd->bi_ip_addr);
170 "baudrate = %d bps\n", bd->bi_baudrate);
175 #endif /* CONFIG_ARM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
177 static void print_num(const char *name, ulong value)
179 printf ("%-12s= 0x%08lX\n", name, value);
183 static void print_str(const char *name, const char *str)
185 printf ("%-12s= %6s MHz\n", name, str);
187 #endif /* CONFIG_PPC */
189 #endif /* CFG_CMD_BDI */
191 int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
197 printf ("Usage:\n%s\n", cmdtp->usage);
201 addr = simple_strtoul(argv[1], NULL, 16);
203 printf ("## Starting application at 0x%08lx ...\n", addr);
206 * pass address parameter as argv[0] (aka command name),
207 * and all remaining args
209 rc = ((ulong (*)(int, char *[]))addr) (--argc, &argv[1]);
210 if (rc != 0) rcode = 1;
212 printf ("## Application terminated, rc = 0x%lx\n", rc);
216 #if (CONFIG_COMMANDS & CFG_CMD_LOADS)
217 int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
224 #ifdef CFG_LOADS_BAUD_CHANGE
225 DECLARE_GLOBAL_DATA_PTR;
226 int load_baudrate, current_baudrate;
228 load_baudrate = current_baudrate = gd->baudrate;
231 if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
237 #ifdef CFG_LOADS_BAUD_CHANGE
239 offset = simple_strtoul(argv[1], NULL, 16);
242 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
244 /* default to current baudrate */
245 if (load_baudrate == 0)
246 load_baudrate = current_baudrate;
248 #else /* ! CFG_LOADS_BAUD_CHANGE */
250 offset = simple_strtoul(argv[1], NULL, 16);
252 #endif /* CFG_LOADS_BAUD_CHANGE */
254 #ifdef CFG_LOADS_BAUD_CHANGE
255 if (load_baudrate != current_baudrate) {
256 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
259 gd->baudrate = load_baudrate;
267 #endif /* CFG_LOADS_BAUD_CHANGE */
268 printf ("## Ready for S-Record download ...\n");
270 addr = load_serial (offset);
273 * Gather any trailing characters (for instance, the ^D which
274 * is sent by 'cu' after sending a file), and give the
275 * box some time (100 * 1 ms)
277 for (i=0; i<100; ++i) {
279 (void) serial_getc();
285 printf ("## S-Record download aborted\n");
288 printf ("## Start Addr = 0x%08lx\n", addr);
292 #ifdef CFG_LOADS_BAUD_CHANGE
293 if (load_baudrate != current_baudrate) {
294 printf ("## Switch baudrate to %d bps and press ESC ...\n",
297 gd->baudrate = current_baudrate;
301 if (getc() == 0x1B) /* ESC */
310 load_serial (ulong offset)
312 char record[SREC_MAXRECLEN + 1]; /* buffer for one S-Record */
313 char binbuf[SREC_MAXBINLEN]; /* buffer for binary data */
314 int binlen; /* no. of data bytes in S-Rec. */
315 int type; /* return code for record type */
316 ulong addr; /* load address from S-Record */
317 ulong size; /* number of bytes transferred */
320 ulong start_addr = ~0;
324 while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
325 type = srec_decode (record, &binlen, &addr, binbuf);
328 return (~0); /* Invalid S-Record */
335 store_addr = addr + offset;
336 if (addr2info(store_addr)) {
339 rc = flash_write((uchar *)binbuf,store_addr,binlen);
345 memcpy ((char *)(store_addr), binbuf, binlen);
347 if ((store_addr) < start_addr)
348 start_addr = store_addr;
349 if ((store_addr + binlen - 1) > end_addr)
350 end_addr = store_addr + binlen - 1;
356 size = end_addr - start_addr + 1;
358 "## First Load Addr = 0x%08lX\n"
359 "## Last Load Addr = 0x%08lX\n"
360 "## Total Size = 0x%08lX = %ld Bytes\n",
361 start_addr, end_addr, size, size
363 flush_cache (addr, size);
364 sprintf(buf, "%lX", size);
365 setenv("filesize", buf);
372 if (!do_echo) { /* print a '.' every 100 lines */
373 if ((++line_count % 100) == 0)
378 return (~0); /* Download aborted */
382 read_record (char *buf, ulong len)
387 --len; /* always leave room for terminating '\0' byte */
389 for (p=buf; p < buf+len; ++p) {
390 c = serial_getc(); /* read character */
392 serial_putc (c); /* ... and echo it */
400 case 0x03: /* ^C - Control C */
406 /* Check for the console hangup (if any different from serial) */
408 if (syscall_tbl[SYSCALL_GETC] != serial_getc) {
415 /* line too long - truncate */
420 #if (CONFIG_COMMANDS & CFG_CMD_SAVES)
422 int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
426 #ifdef CFG_LOADS_BAUD_CHANGE
427 DECLARE_GLOBAL_DATA_PTR;
428 int save_baudrate, current_baudrate;
430 save_baudrate = current_baudrate = gd->baudrate;
434 offset = simple_strtoul(argv[1], NULL, 16);
436 #ifdef CFG_LOADS_BAUD_CHANGE
438 size = simple_strtoul(argv[2], NULL, 16);
441 save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
443 /* default to current baudrate */
444 if (save_baudrate == 0)
445 save_baudrate = current_baudrate;
447 #else /* ! CFG_LOADS_BAUD_CHANGE */
449 size = simple_strtoul(argv[2], NULL, 16);
451 #endif /* CFG_LOADS_BAUD_CHANGE */
453 #ifdef CFG_LOADS_BAUD_CHANGE
454 if (save_baudrate != current_baudrate) {
455 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
458 gd->baudrate = save_baudrate;
466 #endif /* CFG_LOADS_BAUD_CHANGE */
467 printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
472 if(save_serial (offset, size)) {
473 printf ("## S-Record upload aborted\n");
475 printf ("## S-Record upload complete\n");
477 #ifdef CFG_LOADS_BAUD_CHANGE
478 if (save_baudrate != current_baudrate) {
479 printf ("## Switch baudrate to %d bps and press ESC ...\n",
480 (int)current_baudrate);
482 gd->baudrate = current_baudrate;
486 if (getc() == 0x1B) /* ESC */
494 #define SREC3_START "S0030000FC\n"
495 #define SREC3_FORMAT "S3%02X%08lX%s%02X\n"
496 #define SREC3_END "S70500000000FA\n"
497 #define SREC_BYTES_PER_RECORD 16
499 static int save_serial (ulong address, ulong count)
501 int i, c, reclen, checksum, length;
502 char *hex = "0123456789ABCDEF";
503 char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
504 char data[2*SREC_BYTES_PER_RECORD+1]; /* buffer for hex data */
509 if(write_record(SREC3_START)) /* write the header */
512 if(count) { /* collect hex data in the buffer */
513 c = *(volatile uchar*)(address + reclen); /* get one byte */
514 checksum += c; /* accumulate checksum */
515 data[2*reclen] = hex[(c>>4)&0x0f];
516 data[2*reclen+1] = hex[c & 0x0f];
517 data[2*reclen+2] = '\0';
521 if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
522 /* enough data collected for one record: dump it */
523 if(reclen) { /* build & write a data record: */
524 /* address + data + checksum */
525 length = 4 + reclen + 1;
527 /* accumulate length bytes into checksum */
528 for(i = 0; i < 2; i++)
529 checksum += (length >> (8*i)) & 0xff;
531 /* accumulate address bytes into checksum: */
532 for(i = 0; i < 4; i++)
533 checksum += (address >> (8*i)) & 0xff;
535 /* make proper checksum byte: */
536 checksum = ~checksum & 0xff;
538 /* output one record: */
539 sprintf(record, SREC3_FORMAT, length, address, data, checksum);
540 if(write_record(record))
543 address += reclen; /* increment address */
549 if(write_record(SREC3_END)) /* write the final record */
555 write_record (char *buf)
562 /* Check for the console hangup (if any different from serial) */
569 # endif /* CFG_CMD_SAVES */
571 #endif /* CFG_CMD_LOADS */
574 #if (CONFIG_COMMANDS & CFG_CMD_LOADB) /* loadb command (load binary) included */
578 #define START_CHAR 0x01
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;
610 int load_baudrate, current_baudrate;
613 load_baudrate = current_baudrate = gd->baudrate;
616 offset = simple_strtoul(argv[1], NULL, 16);
619 load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
621 /* default to current baudrate */
622 if (load_baudrate == 0)
623 load_baudrate = current_baudrate;
626 if (load_baudrate != current_baudrate) {
627 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
630 gd->baudrate = load_baudrate;
638 printf ("## Ready for binary (kermit) download ...\n");
640 addr = load_serial_bin (offset);
643 * Gather any trailing characters (for instance, the ^D which
644 * is sent by 'cu' after sending a file), and give the
645 * box some time (100 * 1 ms)
647 for (i=0; i<100; ++i) {
649 (void) serial_getc();
656 printf ("## Binary (kermit) download aborted\n");
659 printf ("## Start Addr = 0x%08lx\n", addr);
663 if (load_baudrate != current_baudrate) {
664 printf ("## Switch baudrate to %d bps and press ESC ...\n",
667 gd->baudrate = current_baudrate;
671 if (getc() == 0x1B) /* ESC */
676 #ifdef CONFIG_AUTOSCRIPT
680 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
681 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
682 rcode = autoscript (load_addr);
690 static ulong load_serial_bin (ulong offset)
695 set_kerm_bin_mode ((ulong *) offset);
697 flush_cache (offset, size);
699 printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
700 sprintf(buf, "%X", size);
701 setenv("filesize", buf);
708 int count = his_pad_count;
711 serial_putc (his_pad_char);
714 /* converts escaped kermit char to binary char */
715 char ktrans (char in)
717 if ((in & 0x60) == 0x40) {
718 return (char) (in & ~0x40);
719 } else if ((in & 0x7f) == 0x3f) {
720 return (char) (in | 0x40);
725 int chk1 (char *buffer)
732 return (int) ((total + ((total >> 6) & 0x03)) & 0x3f);
735 void s1_sendpacket (char *packet)
739 serial_putc (*packet++);
744 void send_ack (int n)
751 a_b[4] = tochar (chk1 (&a_b[1]));
757 void send_nack (int n)
764 a_b[4] = tochar (chk1 (&a_b[1]));
772 /* os_data_* takes an OS Open image and puts it into memory, and
773 puts the boot header in an array named os_data_header
775 if image is binary, no header is stored in os_data_header.
777 void (*os_data_init) (void);
778 void (*os_data_char) (char new_char);
779 static int os_data_state, os_data_state_saved;
781 static int os_data_count_saved;
782 static char *os_data_addr, *os_data_addr_saved;
783 static char *bin_start_address;
784 int os_data_header[8];
785 static void bin_data_init (void)
789 os_data_addr = bin_start_address;
791 static void os_data_save (void)
793 os_data_state_saved = os_data_state;
794 os_data_count_saved = os_data_count;
795 os_data_addr_saved = os_data_addr;
797 static void os_data_restore (void)
799 os_data_state = os_data_state_saved;
800 os_data_count = os_data_count_saved;
801 os_data_addr = os_data_addr_saved;
803 static void bin_data_char (char new_char)
805 switch (os_data_state) {
807 *os_data_addr++ = new_char;
812 static void set_kerm_bin_mode (unsigned long *addr)
814 bin_start_address = (char *) addr;
815 os_data_init = bin_data_init;
816 os_data_char = bin_data_char;
820 /* k_data_* simply handles the kermit escape translations */
821 static int k_data_escape, k_data_escape_saved;
822 void k_data_init (void)
827 void k_data_save (void)
829 k_data_escape_saved = k_data_escape;
832 void k_data_restore (void)
834 k_data_escape = k_data_escape_saved;
837 void k_data_char (char new_char)
840 /* last char was escape - translate this character */
841 os_data_char (ktrans (new_char));
844 if (new_char == his_quote) {
845 /* this char is escape - remember */
848 /* otherwise send this char as-is */
849 os_data_char (new_char);
854 #define SEND_DATA_SIZE 20
855 char send_parms[SEND_DATA_SIZE];
858 /* handle_send_packet interprits the protocol info and builds and
859 sends an appropriate ack for what we can do */
860 void handle_send_packet (int n)
865 /* initialize some protocol parameters */
866 his_eol = END_CHAR; /* default end of line character */
869 his_quote = K_ESCAPE;
871 /* ignore last character if it filled the buffer */
872 if (send_ptr == &send_parms[SEND_DATA_SIZE - 1])
874 bytes = send_ptr - send_parms; /* how many bytes we'll process */
878 /* handle MAXL - max length */
879 /* ignore what he says - most I'll take (here) is 94 */
880 a_b[++length] = tochar (94);
883 /* handle TIME - time you should wait for my packets */
884 /* ignore what he says - don't wait for my ack longer than 1 second */
885 a_b[++length] = tochar (1);
888 /* handle NPAD - number of pad chars I need */
889 /* remember what he says - I need none */
890 his_pad_count = untochar (send_parms[2]);
891 a_b[++length] = tochar (0);
894 /* handle PADC - pad chars I need */
895 /* remember what he says - I need none */
896 his_pad_char = ktrans (send_parms[3]);
897 a_b[++length] = 0x40; /* He should ignore this */
900 /* handle EOL - end of line he needs */
901 /* remember what he says - I need CR */
902 his_eol = untochar (send_parms[4]);
903 a_b[++length] = tochar (END_CHAR);
906 /* handle QCTL - quote control char he'll use */
907 /* remember what he says - I'll use '#' */
908 his_quote = send_parms[5];
912 /* handle QBIN - 8-th bit prefixing */
913 /* ignore what he says - I refuse */
917 /* handle CHKT - the clock check type */
918 /* ignore what he says - I do type 1 (for now) */
922 /* handle REPT - the repeat prefix */
923 /* ignore what he says - I refuse (for now) */
927 /* handle CAPAS - the capabilities mask */
928 /* ignore what he says - I only do long packets - I don't do windows */
929 a_b[++length] = tochar (2); /* only long packets */
930 a_b[++length] = tochar (0); /* no windows */
931 a_b[++length] = tochar (94); /* large packet msb */
932 a_b[++length] = tochar (94); /* large packet lsb */
936 a_b[1] = tochar (length);
939 a_b[++length] = '\0';
940 a_b[length] = tochar (chk1 (&a_b[1]));
941 a_b[++length] = his_eol;
942 a_b[++length] = '\0';
946 /* k_recv receives a OS Open image file over kermit line */
947 static int k_recv (void)
950 char k_state, k_state_saved;
958 /* initialize some protocol parameters */
959 his_eol = END_CHAR; /* default end of line character */
962 his_quote = K_ESCAPE;
964 /* initialize the k_recv and k_data state machine */
968 k_state_saved = k_state;
970 n = 0; /* just to get rid of a warning */
973 /* expect this "type" sequence (but don't check):
978 B: break transmission
981 /* enter main loop */
983 /* set the send packet pointer to begining of send packet parms */
984 send_ptr = send_parms;
986 /* With each packet, start summing the bytes starting with the length.
987 Save the current sequence number.
988 Note the type of the packet.
989 If a character less than SPACE (0x20) is received - error.
993 /* OLD CODE, Prior to checking sequence numbers */
994 /* first have all state machines save current states */
995 k_state_saved = k_state;
1000 /* wait for the starting character */
1001 while (serial_getc () != START_CHAR);
1002 /* get length of packet */
1004 new_char = serial_getc ();
1005 if ((new_char & 0xE0) == 0)
1007 sum += new_char & 0xff;
1008 length = untochar (new_char);
1009 /* get sequence number */
1010 new_char = serial_getc ();
1011 if ((new_char & 0xE0) == 0)
1013 sum += new_char & 0xff;
1014 n = untochar (new_char);
1017 /* NEW CODE - check sequence numbers for retried packets */
1018 /* Note - this new code assumes that the sequence number is correctly
1019 * received. Handling an invalid sequence number adds another layer
1020 * of complexity that may not be needed - yet! At this time, I'm hoping
1021 * that I don't need to buffer the incoming data packets and can write
1022 * the data into memory in real time.
1025 /* same sequence number, restore the previous state */
1026 k_state = k_state_saved;
1029 /* new sequence number, checkpoint the download */
1031 k_state_saved = k_state;
1036 /* get packet type */
1037 new_char = serial_getc ();
1038 if ((new_char & 0xE0) == 0)
1040 sum += new_char & 0xff;
1043 /* check for extended length */
1045 /* (length byte was 0, decremented twice) */
1046 /* get the two length bytes */
1047 new_char = serial_getc ();
1048 if ((new_char & 0xE0) == 0)
1050 sum += new_char & 0xff;
1051 len_hi = untochar (new_char);
1052 new_char = serial_getc ();
1053 if ((new_char & 0xE0) == 0)
1055 sum += new_char & 0xff;
1056 len_lo = untochar (new_char);
1057 length = len_hi * 95 + len_lo;
1058 /* check header checksum */
1059 new_char = serial_getc ();
1060 if ((new_char & 0xE0) == 0)
1062 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1064 sum += new_char & 0xff;
1065 /* --length; */ /* new length includes only data and block check to come */
1067 /* bring in rest of packet */
1068 while (length > 1) {
1069 new_char = serial_getc ();
1070 if ((new_char & 0xE0) == 0)
1072 sum += new_char & 0xff;
1074 if (k_state == DATA_TYPE) {
1075 /* pass on the data if this is a data packet */
1076 k_data_char (new_char);
1077 } else if (k_state == SEND_TYPE) {
1078 /* save send pack in buffer as is */
1079 *send_ptr++ = new_char;
1080 /* if too much data, back off the pointer */
1081 if (send_ptr >= &send_parms[SEND_DATA_SIZE])
1085 /* get and validate checksum character */
1086 new_char = serial_getc ();
1087 if ((new_char & 0xE0) == 0)
1089 if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
1092 new_char = serial_getc ();
1093 if (new_char != END_CHAR) {
1095 /* restore state machines */
1096 k_state = k_state_saved;
1098 /* send a negative acknowledge packet in */
1100 } else if (k_state == SEND_TYPE) {
1101 /* crack the protocol parms, build an appropriate ack packet */
1102 handle_send_packet (n);
1104 /* send simple acknowledge packet in */
1106 /* quit if end of transmission */
1107 if (k_state == BREAK_TYPE)
1112 return ((ulong) os_data_addr - (ulong) bin_start_address);
1114 #endif /* CFG_CMD_LOADB */
1115 #if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
1116 int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1118 extern int hwflow_onoff(int);
1121 if (strcmp(argv[1], "off") == 0)
1124 if (strcmp(argv[1], "on") == 0)
1127 printf("Usage: %s\n", cmdtp->usage);
1129 printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
1132 #endif /* CFG_CMD_HWFLOW */