Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
last_n = n;
k_state_saved = k_state;
k_data_save ();
}
/* END NEW CODE */
/* get packet type */
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
k_state = new_char;
--length;
/* check for extended length */
if (length == -2) {
/* (length byte was 0, decremented twice) */
/* get the two length bytes */
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_hi = untochar (new_char);
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_lo = untochar (new_char);
length = len_hi * 95 + len_lo;
/* check header checksum */
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error;
sum += new_char & 0xff;
/* --length; */ /* new length includes only data and block check to come */
}
/* bring in rest of packet */
while (length > 1) {
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
--length;
if (k_state == DATA_TYPE) {
/* pass on the data if this is a data packet */
k_data_char (new_char);
} else if (k_state == SEND_TYPE) {
/* save send pack in buffer as is */
*send_ptr++ = new_char;
/* if too much data, back off the pointer */
if (send_ptr >= &send_parms[SEND_DATA_SIZE])
--send_ptr;
}
}
/* get and validate checksum character */
new_char = serial_getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error;
/* get END_CHAR */
new_char = serial_getc ();
if (new_char != END_CHAR) {
packet_error:
/* restore state machines */
k_state = k_state_saved;
k_data_restore ();
/* send a negative acknowledge packet in */
send_nack (n);
} else if (k_state == SEND_TYPE) {
/* crack the protocol parms, build an appropriate ack packet */
handle_send_packet (n);
} else {
/* send simple acknowledge packet in */
send_ack (n);
/* quit if end of transmission */
if (k_state == BREAK_TYPE)
done = 1;
}
++z;
}
return ((ulong) os_data_addr - (ulong) bin_start_address);
}
#endif /* CFG_CMD_LOADB */
#if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
extern int hwflow_onoff(int);
if (argc == 2) {
if (strcmp(argv[1], "off") == 0)
hwflow_onoff(-1);
else
if (strcmp(argv[1], "on") == 0)
hwflow_onoff(1);
else
printf("Usage: %s\n", cmdtp->usage);
}
printf("RTS/CTS hardware flow control: %s\n", hwflow_onoff(0) ? "on" : "off");
return 0;
}
#endif /* CFG_CMD_HWFLOW */