Commit e85427fd66a21b39145a47e67871a8863c0e5591
Committed by
Tom Rini
1 parent
a53002f4fa
Exists in
master
and in
53 other branches
Add eCos-2.0 SPDX-License-Identifier to source files
Signed-off-by: Wolfgang Denk <wd@denx.de>
Showing 6 changed files with 48 additions and 131 deletions Inline Diff
Licenses/README
1 | U-Boot is Free Software. It is copyrighted by Wolfgang Denk and | 1 | U-Boot is Free Software. It is copyrighted by Wolfgang Denk and |
2 | many others who contributed code (see the actual source code and the | 2 | many others who contributed code (see the actual source code and the |
3 | git commit messages for details). You can redistribute U-Boot and/or | 3 | git commit messages for details). You can redistribute U-Boot and/or |
4 | modify it under the terms of version 2 of the GNU General Public | 4 | modify it under the terms of version 2 of the GNU General Public |
5 | License as published by the Free Software Foundation. Most of it can | 5 | License as published by the Free Software Foundation. Most of it can |
6 | also be distributed, at your option, under any later version of the | 6 | also be distributed, at your option, under any later version of the |
7 | GNU General Public License -- see individual files for exceptions. | 7 | GNU General Public License -- see individual files for exceptions. |
8 | 8 | ||
9 | NOTE! This license does *not* cover the so-called "standalone" | 9 | NOTE! This license does *not* cover the so-called "standalone" |
10 | applications that use U-Boot services by means of the jump table | 10 | applications that use U-Boot services by means of the jump table |
11 | provided by U-Boot exactly for this purpose - this is merely | 11 | provided by U-Boot exactly for this purpose - this is merely |
12 | considered normal use of U-Boot, and does *not* fall under the | 12 | considered normal use of U-Boot, and does *not* fall under the |
13 | heading of "derived work" -- see file Licenses/Exceptions for | 13 | heading of "derived work" -- see file Licenses/Exceptions for |
14 | details. | 14 | details. |
15 | 15 | ||
16 | Also note that the GPL and the other licenses are copyrighted by | 16 | Also note that the GPL and the other licenses are copyrighted by |
17 | the Free Software Foundation and other organizations, but the | 17 | the Free Software Foundation and other organizations, but the |
18 | instance of code that they refer to (the U-Boot source code) is | 18 | instance of code that they refer to (the U-Boot source code) is |
19 | copyrighted by me and others who actually wrote it. | 19 | copyrighted by me and others who actually wrote it. |
20 | -- Wolfgang Denk | 20 | -- Wolfgang Denk |
21 | 21 | ||
22 | 22 | ||
23 | Like many other projects, U-Boot has a tradition of including big | 23 | Like many other projects, U-Boot has a tradition of including big |
24 | blocks of License headers in all files. This not only blows up the | 24 | blocks of License headers in all files. This not only blows up the |
25 | source code with mostly redundant information, but also makes it very | 25 | source code with mostly redundant information, but also makes it very |
26 | difficult to generate License Clearing Reports. An additional problem | 26 | difficult to generate License Clearing Reports. An additional problem |
27 | is that even the same licenses are referred to by a number of | 27 | is that even the same licenses are referred to by a number of |
28 | slightly varying text blocks (full, abbreviated, different | 28 | slightly varying text blocks (full, abbreviated, different |
29 | indentation, line wrapping and/or white space, with obsolete address | 29 | indentation, line wrapping and/or white space, with obsolete address |
30 | information, ...) which makes automatic processing a nightmare. | 30 | information, ...) which makes automatic processing a nightmare. |
31 | 31 | ||
32 | To make this easier, such license headers in the source files will be | 32 | To make this easier, such license headers in the source files will be |
33 | replaced with a single line reference to Unique License Identifiers | 33 | replaced with a single line reference to Unique License Identifiers |
34 | as defined by the Linux Foundation's SPDX project [1]. For example, | 34 | as defined by the Linux Foundation's SPDX project [1]. For example, |
35 | in a source file the full "GPL v2.0 or later" header text will be | 35 | in a source file the full "GPL v2.0 or later" header text will be |
36 | replaced by a single line: | 36 | replaced by a single line: |
37 | 37 | ||
38 | SPDX-License-Identifier: GPL-2.0+ | 38 | SPDX-License-Identifier: GPL-2.0+ |
39 | 39 | ||
40 | We use the SPDX Unique License Identifiers here; these are available | 40 | We use the SPDX Unique License Identifiers here; these are available |
41 | at [2]. | 41 | at [2]. |
42 | 42 | ||
43 | [1] http://spdx.org/ | 43 | [1] http://spdx.org/ |
44 | [2] http://spdx.org/licenses/ | 44 | [2] http://spdx.org/licenses/ |
45 | 45 | ||
46 | Full name SPDX Identifier OSI Approved File name URI | 46 | Full name SPDX Identifier OSI Approved File name URI |
47 | ======================================================================================================================================= | 47 | ======================================================================================================================================= |
48 | GNU General Public License v2.0 only GPL-2.0 Y gpl-2.0.txt http://www.gnu.org/licenses/gpl-2.0.txt | 48 | GNU General Public License v2.0 only GPL-2.0 Y gpl-2.0.txt http://www.gnu.org/licenses/gpl-2.0.txt |
49 | GNU General Public License v2.0 or later GPL-2.0+ Y gpl-2.0.txt http://www.gnu.org/licenses/gpl-2.0.txt | 49 | GNU General Public License v2.0 or later GPL-2.0+ Y gpl-2.0.txt http://www.gnu.org/licenses/gpl-2.0.txt |
50 | GNU Library General Public License v2 or later LGPL-2.0+ Y lgpl-2.0.txt http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt | 50 | GNU Library General Public License v2 or later LGPL-2.0+ Y lgpl-2.0.txt http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt |
51 | GNU Lesser General Public License v2.1 or later LGPL-2.1+ Y lgpl-2.1.txt http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | 51 | GNU Lesser General Public License v2.1 or later LGPL-2.1+ Y lgpl-2.1.txt http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt |
52 | eCos license version 2.0 eCos-2.0 eCos-2.0.txt http://www.gnu.org/licenses/ecos-license.html | ||
52 | 53 |
Licenses/eCos-2.0.txt
File was created | 1 | Note that this license is not endorsed by the Free Software Foundation. | |
2 | It is available here as a convenience to readers of [1]the license | ||
3 | list. | ||
4 | |||
5 | The eCos license version 2.0 | ||
6 | |||
7 | This file is part of eCos, the Embedded Configurable Operating System. | ||
8 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | ||
9 | |||
10 | eCos is free software; you can redistribute it and/or modify it under | ||
11 | the terms of the GNU General Public License as published by the Free | ||
12 | Software Foundation; either version 2 or (at your option) any later | ||
13 | version. | ||
14 | |||
15 | eCos is distributed in the hope that it will be useful, but WITHOUT ANY | ||
16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
18 | for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License along | ||
21 | with eCos; if not, write to the Free Software Foundation, Inc., 51 | ||
22 | Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
23 | |||
24 | As a special exception, if other files instantiate templates or use | ||
25 | macros or inline functions from this file, or you compile this file and | ||
26 | link it with other works to produce a work based on this file, this | ||
27 | file does not by itself cause the resulting work to be covered by the | ||
28 | GNU General Public License. However the source code for this file must | ||
29 | still be made available in accordance with section (3) of the GNU | ||
30 | General Public License. | ||
31 | |||
32 | This exception does not invalidate any other reasons why a work based | ||
33 | on this file might be covered by the GNU General Public License. | ||
34 | |||
35 | Alternative licenses for eCos may be arranged by contacting Red Hat, | ||
36 | Inc. at http://sources.redhat.com/ecos/ecos-license/ | ||
37 | ------------------------------------------- | ||
38 | |||
39 | ####ECOSGPLCOPYRIGHTEND#### | ||
40 | |||
41 | References | ||
42 | |||
43 | 1. http://www.gnu.org/licenses/license-list.html | ||
44 |
common/xyzModem.c
1 | /* | 1 | /* |
2 | *========================================================================== | 2 | *========================================================================== |
3 | * | 3 | * |
4 | * xyzModem.c | 4 | * xyzModem.c |
5 | * | 5 | * |
6 | * RedBoot stream handler for xyzModem protocol | 6 | * RedBoot stream handler for xyzModem protocol |
7 | * | 7 | * |
8 | *========================================================================== | 8 | *========================================================================== |
9 | *####ECOSGPLCOPYRIGHTBEGIN#### | 9 | * SPDX-License-Identifier: eCos-2.0 |
10 | * ------------------------------------------- | ||
11 | * This file is part of eCos, the Embedded Configurable Operating System. | ||
12 | * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | ||
13 | * Copyright (C) 2002 Gary Thomas | ||
14 | * | ||
15 | * eCos is free software; you can redistribute it and/or modify it under | ||
16 | * the terms of the GNU General Public License as published by the Free | ||
17 | * Software Foundation; either version 2 or (at your option) any later version. | ||
18 | * | ||
19 | * eCos is distributed in the hope that it will be useful, but WITHOUT ANY | ||
20 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
22 | * for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License along | ||
25 | * with eCos; if not, write to the Free Software Foundation, Inc., | ||
26 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
27 | * | ||
28 | * As a special exception, if other files instantiate templates or use macros | ||
29 | * or inline functions from this file, or you compile this file and link it | ||
30 | * with other works to produce a work based on this file, this file does not | ||
31 | * by itself cause the resulting work to be covered by the GNU General Public | ||
32 | * License. However the source code for this file must still be made available | ||
33 | * in accordance with section (3) of the GNU General Public License. | ||
34 | * | ||
35 | * This exception does not invalidate any other reasons why a work based on | ||
36 | * this file might be covered by the GNU General Public License. | ||
37 | * | ||
38 | * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | ||
39 | * at http: *sources.redhat.com/ecos/ecos-license/ | ||
40 | * ------------------------------------------- | ||
41 | *####ECOSGPLCOPYRIGHTEND#### | ||
42 | *========================================================================== | 10 | *========================================================================== |
43 | *#####DESCRIPTIONBEGIN#### | 11 | *#####DESCRIPTIONBEGIN#### |
44 | * | 12 | * |
45 | * Author(s): gthomas | 13 | * Author(s): gthomas |
46 | * Contributors: gthomas, tsmith, Yoshinori Sato | 14 | * Contributors: gthomas, tsmith, Yoshinori Sato |
47 | * Date: 2000-07-14 | 15 | * Date: 2000-07-14 |
48 | * Purpose: | 16 | * Purpose: |
49 | * Description: | 17 | * Description: |
50 | * | 18 | * |
51 | * This code is part of RedBoot (tm). | 19 | * This code is part of RedBoot (tm). |
52 | * | 20 | * |
53 | *####DESCRIPTIONEND#### | 21 | *####DESCRIPTIONEND#### |
54 | * | 22 | * |
55 | *========================================================================== | 23 | *========================================================================== |
56 | */ | 24 | */ |
57 | #include <common.h> | 25 | #include <common.h> |
58 | #include <xyzModem.h> | 26 | #include <xyzModem.h> |
59 | #include <stdarg.h> | 27 | #include <stdarg.h> |
60 | #include <crc.h> | 28 | #include <crc.h> |
61 | 29 | ||
62 | /* Assumption - run xyzModem protocol over the console port */ | 30 | /* Assumption - run xyzModem protocol over the console port */ |
63 | 31 | ||
64 | /* Values magic to the protocol */ | 32 | /* Values magic to the protocol */ |
65 | #define SOH 0x01 | 33 | #define SOH 0x01 |
66 | #define STX 0x02 | 34 | #define STX 0x02 |
67 | #define EOT 0x04 | 35 | #define EOT 0x04 |
68 | #define ACK 0x06 | 36 | #define ACK 0x06 |
69 | #define BSP 0x08 | 37 | #define BSP 0x08 |
70 | #define NAK 0x15 | 38 | #define NAK 0x15 |
71 | #define CAN 0x18 | 39 | #define CAN 0x18 |
72 | #define EOF 0x1A /* ^Z for DOS officionados */ | 40 | #define EOF 0x1A /* ^Z for DOS officionados */ |
73 | 41 | ||
74 | #define USE_YMODEM_LENGTH | 42 | #define USE_YMODEM_LENGTH |
75 | 43 | ||
76 | /* Data & state local to the protocol */ | 44 | /* Data & state local to the protocol */ |
77 | static struct | 45 | static struct |
78 | { | 46 | { |
79 | #ifdef REDBOOT | 47 | #ifdef REDBOOT |
80 | hal_virtual_comm_table_t *__chan; | 48 | hal_virtual_comm_table_t *__chan; |
81 | #else | 49 | #else |
82 | int *__chan; | 50 | int *__chan; |
83 | #endif | 51 | #endif |
84 | unsigned char pkt[1024], *bufp; | 52 | unsigned char pkt[1024], *bufp; |
85 | unsigned char blk, cblk, crc1, crc2; | 53 | unsigned char blk, cblk, crc1, crc2; |
86 | unsigned char next_blk; /* Expected block */ | 54 | unsigned char next_blk; /* Expected block */ |
87 | int len, mode, total_retries; | 55 | int len, mode, total_retries; |
88 | int total_SOH, total_STX, total_CAN; | 56 | int total_SOH, total_STX, total_CAN; |
89 | bool crc_mode, at_eof, tx_ack; | 57 | bool crc_mode, at_eof, tx_ack; |
90 | #ifdef USE_YMODEM_LENGTH | 58 | #ifdef USE_YMODEM_LENGTH |
91 | unsigned long file_length, read_length; | 59 | unsigned long file_length, read_length; |
92 | #endif | 60 | #endif |
93 | } xyz; | 61 | } xyz; |
94 | 62 | ||
95 | #define xyzModem_CHAR_TIMEOUT 2000 /* 2 seconds */ | 63 | #define xyzModem_CHAR_TIMEOUT 2000 /* 2 seconds */ |
96 | #define xyzModem_MAX_RETRIES 20 | 64 | #define xyzModem_MAX_RETRIES 20 |
97 | #define xyzModem_MAX_RETRIES_WITH_CRC 10 | 65 | #define xyzModem_MAX_RETRIES_WITH_CRC 10 |
98 | #define xyzModem_CAN_COUNT 3 /* Wait for 3 CAN before quitting */ | 66 | #define xyzModem_CAN_COUNT 3 /* Wait for 3 CAN before quitting */ |
99 | 67 | ||
100 | 68 | ||
101 | #ifndef REDBOOT /*SB */ | 69 | #ifndef REDBOOT /*SB */ |
102 | typedef int cyg_int32; | 70 | typedef int cyg_int32; |
103 | static int | 71 | static int |
104 | CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c) | 72 | CYGACC_COMM_IF_GETC_TIMEOUT (char chan, char *c) |
105 | { | 73 | { |
106 | #define DELAY 20 | 74 | #define DELAY 20 |
107 | unsigned long counter = 0; | 75 | unsigned long counter = 0; |
108 | while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT * 1000 / DELAY)) | 76 | while (!tstc () && (counter < xyzModem_CHAR_TIMEOUT * 1000 / DELAY)) |
109 | { | 77 | { |
110 | udelay (DELAY); | 78 | udelay (DELAY); |
111 | counter++; | 79 | counter++; |
112 | } | 80 | } |
113 | if (tstc ()) | 81 | if (tstc ()) |
114 | { | 82 | { |
115 | *c = getc (); | 83 | *c = getc (); |
116 | return 1; | 84 | return 1; |
117 | } | 85 | } |
118 | return 0; | 86 | return 0; |
119 | } | 87 | } |
120 | 88 | ||
121 | static void | 89 | static void |
122 | CYGACC_COMM_IF_PUTC (char x, char y) | 90 | CYGACC_COMM_IF_PUTC (char x, char y) |
123 | { | 91 | { |
124 | putc (y); | 92 | putc (y); |
125 | } | 93 | } |
126 | 94 | ||
127 | /* Validate a hex character */ | 95 | /* Validate a hex character */ |
128 | __inline__ static bool | 96 | __inline__ static bool |
129 | _is_hex (char c) | 97 | _is_hex (char c) |
130 | { | 98 | { |
131 | return (((c >= '0') && (c <= '9')) || | 99 | return (((c >= '0') && (c <= '9')) || |
132 | ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f'))); | 100 | ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f'))); |
133 | } | 101 | } |
134 | 102 | ||
135 | /* Convert a single hex nibble */ | 103 | /* Convert a single hex nibble */ |
136 | __inline__ static int | 104 | __inline__ static int |
137 | _from_hex (char c) | 105 | _from_hex (char c) |
138 | { | 106 | { |
139 | int ret = 0; | 107 | int ret = 0; |
140 | 108 | ||
141 | if ((c >= '0') && (c <= '9')) | 109 | if ((c >= '0') && (c <= '9')) |
142 | { | 110 | { |
143 | ret = (c - '0'); | 111 | ret = (c - '0'); |
144 | } | 112 | } |
145 | else if ((c >= 'a') && (c <= 'f')) | 113 | else if ((c >= 'a') && (c <= 'f')) |
146 | { | 114 | { |
147 | ret = (c - 'a' + 0x0a); | 115 | ret = (c - 'a' + 0x0a); |
148 | } | 116 | } |
149 | else if ((c >= 'A') && (c <= 'F')) | 117 | else if ((c >= 'A') && (c <= 'F')) |
150 | { | 118 | { |
151 | ret = (c - 'A' + 0x0A); | 119 | ret = (c - 'A' + 0x0A); |
152 | } | 120 | } |
153 | return ret; | 121 | return ret; |
154 | } | 122 | } |
155 | 123 | ||
156 | /* Convert a character to lower case */ | 124 | /* Convert a character to lower case */ |
157 | __inline__ static char | 125 | __inline__ static char |
158 | _tolower (char c) | 126 | _tolower (char c) |
159 | { | 127 | { |
160 | if ((c >= 'A') && (c <= 'Z')) | 128 | if ((c >= 'A') && (c <= 'Z')) |
161 | { | 129 | { |
162 | c = (c - 'A') + 'a'; | 130 | c = (c - 'A') + 'a'; |
163 | } | 131 | } |
164 | return c; | 132 | return c; |
165 | } | 133 | } |
166 | 134 | ||
167 | /* Parse (scan) a number */ | 135 | /* Parse (scan) a number */ |
168 | static bool | 136 | static bool |
169 | parse_num (char *s, unsigned long *val, char **es, char *delim) | 137 | parse_num (char *s, unsigned long *val, char **es, char *delim) |
170 | { | 138 | { |
171 | bool first = true; | 139 | bool first = true; |
172 | int radix = 10; | 140 | int radix = 10; |
173 | char c; | 141 | char c; |
174 | unsigned long result = 0; | 142 | unsigned long result = 0; |
175 | int digit; | 143 | int digit; |
176 | 144 | ||
177 | while (*s == ' ') | 145 | while (*s == ' ') |
178 | s++; | 146 | s++; |
179 | while (*s) | 147 | while (*s) |
180 | { | 148 | { |
181 | if (first && (s[0] == '0') && (_tolower (s[1]) == 'x')) | 149 | if (first && (s[0] == '0') && (_tolower (s[1]) == 'x')) |
182 | { | 150 | { |
183 | radix = 16; | 151 | radix = 16; |
184 | s += 2; | 152 | s += 2; |
185 | } | 153 | } |
186 | first = false; | 154 | first = false; |
187 | c = *s++; | 155 | c = *s++; |
188 | if (_is_hex (c) && ((digit = _from_hex (c)) < radix)) | 156 | if (_is_hex (c) && ((digit = _from_hex (c)) < radix)) |
189 | { | 157 | { |
190 | /* Valid digit */ | 158 | /* Valid digit */ |
191 | #ifdef CYGPKG_HAL_MIPS | 159 | #ifdef CYGPKG_HAL_MIPS |
192 | /* FIXME: tx49 compiler generates 0x2539018 for MUL which */ | 160 | /* FIXME: tx49 compiler generates 0x2539018 for MUL which */ |
193 | /* isn't any good. */ | 161 | /* isn't any good. */ |
194 | if (16 == radix) | 162 | if (16 == radix) |
195 | result = result << 4; | 163 | result = result << 4; |
196 | else | 164 | else |
197 | result = 10 * result; | 165 | result = 10 * result; |
198 | result += digit; | 166 | result += digit; |
199 | #else | 167 | #else |
200 | result = (result * radix) + digit; | 168 | result = (result * radix) + digit; |
201 | #endif | 169 | #endif |
202 | } | 170 | } |
203 | else | 171 | else |
204 | { | 172 | { |
205 | if (delim != (char *) 0) | 173 | if (delim != (char *) 0) |
206 | { | 174 | { |
207 | /* See if this character is one of the delimiters */ | 175 | /* See if this character is one of the delimiters */ |
208 | char *dp = delim; | 176 | char *dp = delim; |
209 | while (*dp && (c != *dp)) | 177 | while (*dp && (c != *dp)) |
210 | dp++; | 178 | dp++; |
211 | if (*dp) | 179 | if (*dp) |
212 | break; /* Found a good delimiter */ | 180 | break; /* Found a good delimiter */ |
213 | } | 181 | } |
214 | return false; /* Malformatted number */ | 182 | return false; /* Malformatted number */ |
215 | } | 183 | } |
216 | } | 184 | } |
217 | *val = result; | 185 | *val = result; |
218 | if (es != (char **) 0) | 186 | if (es != (char **) 0) |
219 | { | 187 | { |
220 | *es = s; | 188 | *es = s; |
221 | } | 189 | } |
222 | return true; | 190 | return true; |
223 | } | 191 | } |
224 | 192 | ||
225 | #endif | 193 | #endif |
226 | 194 | ||
227 | #define USE_SPRINTF | 195 | #define USE_SPRINTF |
228 | #ifdef DEBUG | 196 | #ifdef DEBUG |
229 | #ifndef USE_SPRINTF | 197 | #ifndef USE_SPRINTF |
230 | /* | 198 | /* |
231 | * Note: this debug setup only works if the target platform has two serial ports | 199 | * Note: this debug setup only works if the target platform has two serial ports |
232 | * available so that the other one (currently only port 1) can be used for debug | 200 | * available so that the other one (currently only port 1) can be used for debug |
233 | * messages. | 201 | * messages. |
234 | */ | 202 | */ |
235 | static int | 203 | static int |
236 | zm_dprintf (char *fmt, ...) | 204 | zm_dprintf (char *fmt, ...) |
237 | { | 205 | { |
238 | int cur_console; | 206 | int cur_console; |
239 | va_list args; | 207 | va_list args; |
240 | 208 | ||
241 | va_start (args, fmt); | 209 | va_start (args, fmt); |
242 | #ifdef REDBOOT | 210 | #ifdef REDBOOT |
243 | cur_console = | 211 | cur_console = |
244 | CYGACC_CALL_IF_SET_CONSOLE_COMM | 212 | CYGACC_CALL_IF_SET_CONSOLE_COMM |
245 | (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); | 213 | (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); |
246 | CYGACC_CALL_IF_SET_CONSOLE_COMM (1); | 214 | CYGACC_CALL_IF_SET_CONSOLE_COMM (1); |
247 | #endif | 215 | #endif |
248 | diag_vprintf (fmt, args); | 216 | diag_vprintf (fmt, args); |
249 | #ifdef REDBOOT | 217 | #ifdef REDBOOT |
250 | CYGACC_CALL_IF_SET_CONSOLE_COMM (cur_console); | 218 | CYGACC_CALL_IF_SET_CONSOLE_COMM (cur_console); |
251 | #endif | 219 | #endif |
252 | } | 220 | } |
253 | 221 | ||
254 | static void | 222 | static void |
255 | zm_flush (void) | 223 | zm_flush (void) |
256 | { | 224 | { |
257 | } | 225 | } |
258 | 226 | ||
259 | #else | 227 | #else |
260 | /* | 228 | /* |
261 | * Note: this debug setup works by storing the strings in a fixed buffer | 229 | * Note: this debug setup works by storing the strings in a fixed buffer |
262 | */ | 230 | */ |
263 | #define FINAL | 231 | #define FINAL |
264 | #ifdef FINAL | 232 | #ifdef FINAL |
265 | static char *zm_out = (char *) 0x00380000; | 233 | static char *zm_out = (char *) 0x00380000; |
266 | static char *zm_out_start = (char *) 0x00380000; | 234 | static char *zm_out_start = (char *) 0x00380000; |
267 | #else | 235 | #else |
268 | static char zm_buf[8192]; | 236 | static char zm_buf[8192]; |
269 | static char *zm_out = zm_buf; | 237 | static char *zm_out = zm_buf; |
270 | static char *zm_out_start = zm_buf; | 238 | static char *zm_out_start = zm_buf; |
271 | 239 | ||
272 | #endif | 240 | #endif |
273 | static int | 241 | static int |
274 | zm_dprintf (char *fmt, ...) | 242 | zm_dprintf (char *fmt, ...) |
275 | { | 243 | { |
276 | int len; | 244 | int len; |
277 | va_list args; | 245 | va_list args; |
278 | 246 | ||
279 | va_start (args, fmt); | 247 | va_start (args, fmt); |
280 | len = diag_vsprintf (zm_out, fmt, args); | 248 | len = diag_vsprintf (zm_out, fmt, args); |
281 | zm_out += len; | 249 | zm_out += len; |
282 | return len; | 250 | return len; |
283 | } | 251 | } |
284 | 252 | ||
285 | static void | 253 | static void |
286 | zm_flush (void) | 254 | zm_flush (void) |
287 | { | 255 | { |
288 | #ifdef REDBOOT | 256 | #ifdef REDBOOT |
289 | char *p = zm_out_start; | 257 | char *p = zm_out_start; |
290 | while (*p) | 258 | while (*p) |
291 | mon_write_char (*p++); | 259 | mon_write_char (*p++); |
292 | #endif | 260 | #endif |
293 | zm_out = zm_out_start; | 261 | zm_out = zm_out_start; |
294 | } | 262 | } |
295 | #endif | 263 | #endif |
296 | 264 | ||
297 | static void | 265 | static void |
298 | zm_dump_buf (void *buf, int len) | 266 | zm_dump_buf (void *buf, int len) |
299 | { | 267 | { |
300 | #ifdef REDBOOT | 268 | #ifdef REDBOOT |
301 | diag_vdump_buf_with_offset (zm_dprintf, buf, len, 0); | 269 | diag_vdump_buf_with_offset (zm_dprintf, buf, len, 0); |
302 | #else | 270 | #else |
303 | 271 | ||
304 | #endif | 272 | #endif |
305 | } | 273 | } |
306 | 274 | ||
307 | static unsigned char zm_buf[2048]; | 275 | static unsigned char zm_buf[2048]; |
308 | static unsigned char *zm_bp; | 276 | static unsigned char *zm_bp; |
309 | 277 | ||
310 | static void | 278 | static void |
311 | zm_new (void) | 279 | zm_new (void) |
312 | { | 280 | { |
313 | zm_bp = zm_buf; | 281 | zm_bp = zm_buf; |
314 | } | 282 | } |
315 | 283 | ||
316 | static void | 284 | static void |
317 | zm_save (unsigned char c) | 285 | zm_save (unsigned char c) |
318 | { | 286 | { |
319 | *zm_bp++ = c; | 287 | *zm_bp++ = c; |
320 | } | 288 | } |
321 | 289 | ||
322 | static void | 290 | static void |
323 | zm_dump (int line) | 291 | zm_dump (int line) |
324 | { | 292 | { |
325 | zm_dprintf ("Packet at line: %d\n", line); | 293 | zm_dprintf ("Packet at line: %d\n", line); |
326 | zm_dump_buf (zm_buf, zm_bp - zm_buf); | 294 | zm_dump_buf (zm_buf, zm_bp - zm_buf); |
327 | } | 295 | } |
328 | 296 | ||
329 | #define ZM_DEBUG(x) x | 297 | #define ZM_DEBUG(x) x |
330 | #else | 298 | #else |
331 | #define ZM_DEBUG(x) | 299 | #define ZM_DEBUG(x) |
332 | #endif | 300 | #endif |
333 | 301 | ||
334 | /* Wait for the line to go idle */ | 302 | /* Wait for the line to go idle */ |
335 | static void | 303 | static void |
336 | xyzModem_flush (void) | 304 | xyzModem_flush (void) |
337 | { | 305 | { |
338 | int res; | 306 | int res; |
339 | char c; | 307 | char c; |
340 | while (true) | 308 | while (true) |
341 | { | 309 | { |
342 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); | 310 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); |
343 | if (!res) | 311 | if (!res) |
344 | return; | 312 | return; |
345 | } | 313 | } |
346 | } | 314 | } |
347 | 315 | ||
348 | static int | 316 | static int |
349 | xyzModem_get_hdr (void) | 317 | xyzModem_get_hdr (void) |
350 | { | 318 | { |
351 | char c; | 319 | char c; |
352 | int res; | 320 | int res; |
353 | bool hdr_found = false; | 321 | bool hdr_found = false; |
354 | int i, can_total, hdr_chars; | 322 | int i, can_total, hdr_chars; |
355 | unsigned short cksum; | 323 | unsigned short cksum; |
356 | 324 | ||
357 | ZM_DEBUG (zm_new ()); | 325 | ZM_DEBUG (zm_new ()); |
358 | /* Find the start of a header */ | 326 | /* Find the start of a header */ |
359 | can_total = 0; | 327 | can_total = 0; |
360 | hdr_chars = 0; | 328 | hdr_chars = 0; |
361 | 329 | ||
362 | if (xyz.tx_ack) | 330 | if (xyz.tx_ack) |
363 | { | 331 | { |
364 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); | 332 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); |
365 | xyz.tx_ack = false; | 333 | xyz.tx_ack = false; |
366 | } | 334 | } |
367 | while (!hdr_found) | 335 | while (!hdr_found) |
368 | { | 336 | { |
369 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); | 337 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); |
370 | ZM_DEBUG (zm_save (c)); | 338 | ZM_DEBUG (zm_save (c)); |
371 | if (res) | 339 | if (res) |
372 | { | 340 | { |
373 | hdr_chars++; | 341 | hdr_chars++; |
374 | switch (c) | 342 | switch (c) |
375 | { | 343 | { |
376 | case SOH: | 344 | case SOH: |
377 | xyz.total_SOH++; | 345 | xyz.total_SOH++; |
378 | case STX: | 346 | case STX: |
379 | if (c == STX) | 347 | if (c == STX) |
380 | xyz.total_STX++; | 348 | xyz.total_STX++; |
381 | hdr_found = true; | 349 | hdr_found = true; |
382 | break; | 350 | break; |
383 | case CAN: | 351 | case CAN: |
384 | xyz.total_CAN++; | 352 | xyz.total_CAN++; |
385 | ZM_DEBUG (zm_dump (__LINE__)); | 353 | ZM_DEBUG (zm_dump (__LINE__)); |
386 | if (++can_total == xyzModem_CAN_COUNT) | 354 | if (++can_total == xyzModem_CAN_COUNT) |
387 | { | 355 | { |
388 | return xyzModem_cancel; | 356 | return xyzModem_cancel; |
389 | } | 357 | } |
390 | else | 358 | else |
391 | { | 359 | { |
392 | /* Wait for multiple CAN to avoid early quits */ | 360 | /* Wait for multiple CAN to avoid early quits */ |
393 | break; | 361 | break; |
394 | } | 362 | } |
395 | case EOT: | 363 | case EOT: |
396 | /* EOT only supported if no noise */ | 364 | /* EOT only supported if no noise */ |
397 | if (hdr_chars == 1) | 365 | if (hdr_chars == 1) |
398 | { | 366 | { |
399 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); | 367 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); |
400 | ZM_DEBUG (zm_dprintf ("ACK on EOT #%d\n", __LINE__)); | 368 | ZM_DEBUG (zm_dprintf ("ACK on EOT #%d\n", __LINE__)); |
401 | ZM_DEBUG (zm_dump (__LINE__)); | 369 | ZM_DEBUG (zm_dump (__LINE__)); |
402 | return xyzModem_eof; | 370 | return xyzModem_eof; |
403 | } | 371 | } |
404 | default: | 372 | default: |
405 | /* Ignore, waiting for start of header */ | 373 | /* Ignore, waiting for start of header */ |
406 | ; | 374 | ; |
407 | } | 375 | } |
408 | } | 376 | } |
409 | else | 377 | else |
410 | { | 378 | { |
411 | /* Data stream timed out */ | 379 | /* Data stream timed out */ |
412 | xyzModem_flush (); /* Toss any current input */ | 380 | xyzModem_flush (); /* Toss any current input */ |
413 | ZM_DEBUG (zm_dump (__LINE__)); | 381 | ZM_DEBUG (zm_dump (__LINE__)); |
414 | CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000); | 382 | CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000); |
415 | return xyzModem_timeout; | 383 | return xyzModem_timeout; |
416 | } | 384 | } |
417 | } | 385 | } |
418 | 386 | ||
419 | /* Header found, now read the data */ | 387 | /* Header found, now read the data */ |
420 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.blk); | 388 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.blk); |
421 | ZM_DEBUG (zm_save (xyz.blk)); | 389 | ZM_DEBUG (zm_save (xyz.blk)); |
422 | if (!res) | 390 | if (!res) |
423 | { | 391 | { |
424 | ZM_DEBUG (zm_dump (__LINE__)); | 392 | ZM_DEBUG (zm_dump (__LINE__)); |
425 | return xyzModem_timeout; | 393 | return xyzModem_timeout; |
426 | } | 394 | } |
427 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.cblk); | 395 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.cblk); |
428 | ZM_DEBUG (zm_save (xyz.cblk)); | 396 | ZM_DEBUG (zm_save (xyz.cblk)); |
429 | if (!res) | 397 | if (!res) |
430 | { | 398 | { |
431 | ZM_DEBUG (zm_dump (__LINE__)); | 399 | ZM_DEBUG (zm_dump (__LINE__)); |
432 | return xyzModem_timeout; | 400 | return xyzModem_timeout; |
433 | } | 401 | } |
434 | xyz.len = (c == SOH) ? 128 : 1024; | 402 | xyz.len = (c == SOH) ? 128 : 1024; |
435 | xyz.bufp = xyz.pkt; | 403 | xyz.bufp = xyz.pkt; |
436 | for (i = 0; i < xyz.len; i++) | 404 | for (i = 0; i < xyz.len; i++) |
437 | { | 405 | { |
438 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); | 406 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, &c); |
439 | ZM_DEBUG (zm_save (c)); | 407 | ZM_DEBUG (zm_save (c)); |
440 | if (res) | 408 | if (res) |
441 | { | 409 | { |
442 | xyz.pkt[i] = c; | 410 | xyz.pkt[i] = c; |
443 | } | 411 | } |
444 | else | 412 | else |
445 | { | 413 | { |
446 | ZM_DEBUG (zm_dump (__LINE__)); | 414 | ZM_DEBUG (zm_dump (__LINE__)); |
447 | return xyzModem_timeout; | 415 | return xyzModem_timeout; |
448 | } | 416 | } |
449 | } | 417 | } |
450 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc1); | 418 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc1); |
451 | ZM_DEBUG (zm_save (xyz.crc1)); | 419 | ZM_DEBUG (zm_save (xyz.crc1)); |
452 | if (!res) | 420 | if (!res) |
453 | { | 421 | { |
454 | ZM_DEBUG (zm_dump (__LINE__)); | 422 | ZM_DEBUG (zm_dump (__LINE__)); |
455 | return xyzModem_timeout; | 423 | return xyzModem_timeout; |
456 | } | 424 | } |
457 | if (xyz.crc_mode) | 425 | if (xyz.crc_mode) |
458 | { | 426 | { |
459 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc2); | 427 | res = CYGACC_COMM_IF_GETC_TIMEOUT (*xyz.__chan, (char *) &xyz.crc2); |
460 | ZM_DEBUG (zm_save (xyz.crc2)); | 428 | ZM_DEBUG (zm_save (xyz.crc2)); |
461 | if (!res) | 429 | if (!res) |
462 | { | 430 | { |
463 | ZM_DEBUG (zm_dump (__LINE__)); | 431 | ZM_DEBUG (zm_dump (__LINE__)); |
464 | return xyzModem_timeout; | 432 | return xyzModem_timeout; |
465 | } | 433 | } |
466 | } | 434 | } |
467 | ZM_DEBUG (zm_dump (__LINE__)); | 435 | ZM_DEBUG (zm_dump (__LINE__)); |
468 | /* Validate the message */ | 436 | /* Validate the message */ |
469 | if ((xyz.blk ^ xyz.cblk) != (unsigned char) 0xFF) | 437 | if ((xyz.blk ^ xyz.cblk) != (unsigned char) 0xFF) |
470 | { | 438 | { |
471 | ZM_DEBUG (zm_dprintf | 439 | ZM_DEBUG (zm_dprintf |
472 | ("Framing error - blk: %x/%x/%x\n", xyz.blk, xyz.cblk, | 440 | ("Framing error - blk: %x/%x/%x\n", xyz.blk, xyz.cblk, |
473 | (xyz.blk ^ xyz.cblk))); | 441 | (xyz.blk ^ xyz.cblk))); |
474 | ZM_DEBUG (zm_dump_buf (xyz.pkt, xyz.len)); | 442 | ZM_DEBUG (zm_dump_buf (xyz.pkt, xyz.len)); |
475 | xyzModem_flush (); | 443 | xyzModem_flush (); |
476 | return xyzModem_frame; | 444 | return xyzModem_frame; |
477 | } | 445 | } |
478 | /* Verify checksum/CRC */ | 446 | /* Verify checksum/CRC */ |
479 | if (xyz.crc_mode) | 447 | if (xyz.crc_mode) |
480 | { | 448 | { |
481 | cksum = cyg_crc16 (xyz.pkt, xyz.len); | 449 | cksum = cyg_crc16 (xyz.pkt, xyz.len); |
482 | if (cksum != ((xyz.crc1 << 8) | xyz.crc2)) | 450 | if (cksum != ((xyz.crc1 << 8) | xyz.crc2)) |
483 | { | 451 | { |
484 | ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n", | 452 | ZM_DEBUG (zm_dprintf ("CRC error - recvd: %02x%02x, computed: %x\n", |
485 | xyz.crc1, xyz.crc2, cksum & 0xFFFF)); | 453 | xyz.crc1, xyz.crc2, cksum & 0xFFFF)); |
486 | return xyzModem_cksum; | 454 | return xyzModem_cksum; |
487 | } | 455 | } |
488 | } | 456 | } |
489 | else | 457 | else |
490 | { | 458 | { |
491 | cksum = 0; | 459 | cksum = 0; |
492 | for (i = 0; i < xyz.len; i++) | 460 | for (i = 0; i < xyz.len; i++) |
493 | { | 461 | { |
494 | cksum += xyz.pkt[i]; | 462 | cksum += xyz.pkt[i]; |
495 | } | 463 | } |
496 | if (xyz.crc1 != (cksum & 0xFF)) | 464 | if (xyz.crc1 != (cksum & 0xFF)) |
497 | { | 465 | { |
498 | ZM_DEBUG (zm_dprintf | 466 | ZM_DEBUG (zm_dprintf |
499 | ("Checksum error - recvd: %x, computed: %x\n", xyz.crc1, | 467 | ("Checksum error - recvd: %x, computed: %x\n", xyz.crc1, |
500 | cksum & 0xFF)); | 468 | cksum & 0xFF)); |
501 | return xyzModem_cksum; | 469 | return xyzModem_cksum; |
502 | } | 470 | } |
503 | } | 471 | } |
504 | /* If we get here, the message passes [structural] muster */ | 472 | /* If we get here, the message passes [structural] muster */ |
505 | return 0; | 473 | return 0; |
506 | } | 474 | } |
507 | 475 | ||
508 | int | 476 | int |
509 | xyzModem_stream_open (connection_info_t * info, int *err) | 477 | xyzModem_stream_open (connection_info_t * info, int *err) |
510 | { | 478 | { |
511 | #ifdef REDBOOT | 479 | #ifdef REDBOOT |
512 | int console_chan; | 480 | int console_chan; |
513 | #endif | 481 | #endif |
514 | int stat = 0; | 482 | int stat = 0; |
515 | int retries = xyzModem_MAX_RETRIES; | 483 | int retries = xyzModem_MAX_RETRIES; |
516 | int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC; | 484 | int crc_retries = xyzModem_MAX_RETRIES_WITH_CRC; |
517 | 485 | ||
518 | /* ZM_DEBUG(zm_out = zm_out_start); */ | 486 | /* ZM_DEBUG(zm_out = zm_out_start); */ |
519 | #ifdef xyzModem_zmodem | 487 | #ifdef xyzModem_zmodem |
520 | if (info->mode == xyzModem_zmodem) | 488 | if (info->mode == xyzModem_zmodem) |
521 | { | 489 | { |
522 | *err = xyzModem_noZmodem; | 490 | *err = xyzModem_noZmodem; |
523 | return -1; | 491 | return -1; |
524 | } | 492 | } |
525 | #endif | 493 | #endif |
526 | 494 | ||
527 | #ifdef REDBOOT | 495 | #ifdef REDBOOT |
528 | /* Set up the I/O channel. Note: this allows for using a different port in the future */ | 496 | /* Set up the I/O channel. Note: this allows for using a different port in the future */ |
529 | console_chan = | 497 | console_chan = |
530 | CYGACC_CALL_IF_SET_CONSOLE_COMM | 498 | CYGACC_CALL_IF_SET_CONSOLE_COMM |
531 | (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); | 499 | (CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); |
532 | if (info->chan >= 0) | 500 | if (info->chan >= 0) |
533 | { | 501 | { |
534 | CYGACC_CALL_IF_SET_CONSOLE_COMM (info->chan); | 502 | CYGACC_CALL_IF_SET_CONSOLE_COMM (info->chan); |
535 | } | 503 | } |
536 | else | 504 | else |
537 | { | 505 | { |
538 | CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan); | 506 | CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan); |
539 | } | 507 | } |
540 | xyz.__chan = CYGACC_CALL_IF_CONSOLE_PROCS (); | 508 | xyz.__chan = CYGACC_CALL_IF_CONSOLE_PROCS (); |
541 | 509 | ||
542 | CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan); | 510 | CYGACC_CALL_IF_SET_CONSOLE_COMM (console_chan); |
543 | CYGACC_COMM_IF_CONTROL (*xyz.__chan, __COMMCTL_SET_TIMEOUT, | 511 | CYGACC_COMM_IF_CONTROL (*xyz.__chan, __COMMCTL_SET_TIMEOUT, |
544 | xyzModem_CHAR_TIMEOUT); | 512 | xyzModem_CHAR_TIMEOUT); |
545 | #else | 513 | #else |
546 | /* TODO: CHECK ! */ | 514 | /* TODO: CHECK ! */ |
547 | int dummy = 0; | 515 | int dummy = 0; |
548 | xyz.__chan = &dummy; | 516 | xyz.__chan = &dummy; |
549 | #endif | 517 | #endif |
550 | xyz.len = 0; | 518 | xyz.len = 0; |
551 | xyz.crc_mode = true; | 519 | xyz.crc_mode = true; |
552 | xyz.at_eof = false; | 520 | xyz.at_eof = false; |
553 | xyz.tx_ack = false; | 521 | xyz.tx_ack = false; |
554 | xyz.mode = info->mode; | 522 | xyz.mode = info->mode; |
555 | xyz.total_retries = 0; | 523 | xyz.total_retries = 0; |
556 | xyz.total_SOH = 0; | 524 | xyz.total_SOH = 0; |
557 | xyz.total_STX = 0; | 525 | xyz.total_STX = 0; |
558 | xyz.total_CAN = 0; | 526 | xyz.total_CAN = 0; |
559 | #ifdef USE_YMODEM_LENGTH | 527 | #ifdef USE_YMODEM_LENGTH |
560 | xyz.read_length = 0; | 528 | xyz.read_length = 0; |
561 | xyz.file_length = 0; | 529 | xyz.file_length = 0; |
562 | #endif | 530 | #endif |
563 | 531 | ||
564 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); | 532 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); |
565 | 533 | ||
566 | if (xyz.mode == xyzModem_xmodem) | 534 | if (xyz.mode == xyzModem_xmodem) |
567 | { | 535 | { |
568 | /* X-modem doesn't have an information header - exit here */ | 536 | /* X-modem doesn't have an information header - exit here */ |
569 | xyz.next_blk = 1; | 537 | xyz.next_blk = 1; |
570 | return 0; | 538 | return 0; |
571 | } | 539 | } |
572 | 540 | ||
573 | while (retries-- > 0) | 541 | while (retries-- > 0) |
574 | { | 542 | { |
575 | stat = xyzModem_get_hdr (); | 543 | stat = xyzModem_get_hdr (); |
576 | if (stat == 0) | 544 | if (stat == 0) |
577 | { | 545 | { |
578 | /* Y-modem file information header */ | 546 | /* Y-modem file information header */ |
579 | if (xyz.blk == 0) | 547 | if (xyz.blk == 0) |
580 | { | 548 | { |
581 | #ifdef USE_YMODEM_LENGTH | 549 | #ifdef USE_YMODEM_LENGTH |
582 | /* skip filename */ | 550 | /* skip filename */ |
583 | while (*xyz.bufp++); | 551 | while (*xyz.bufp++); |
584 | /* get the length */ | 552 | /* get the length */ |
585 | parse_num ((char *) xyz.bufp, &xyz.file_length, NULL, " "); | 553 | parse_num ((char *) xyz.bufp, &xyz.file_length, NULL, " "); |
586 | #endif | 554 | #endif |
587 | /* The rest of the file name data block quietly discarded */ | 555 | /* The rest of the file name data block quietly discarded */ |
588 | xyz.tx_ack = true; | 556 | xyz.tx_ack = true; |
589 | } | 557 | } |
590 | xyz.next_blk = 1; | 558 | xyz.next_blk = 1; |
591 | xyz.len = 0; | 559 | xyz.len = 0; |
592 | return 0; | 560 | return 0; |
593 | } | 561 | } |
594 | else if (stat == xyzModem_timeout) | 562 | else if (stat == xyzModem_timeout) |
595 | { | 563 | { |
596 | if (--crc_retries <= 0) | 564 | if (--crc_retries <= 0) |
597 | xyz.crc_mode = false; | 565 | xyz.crc_mode = false; |
598 | CYGACC_CALL_IF_DELAY_US (5 * 100000); /* Extra delay for startup */ | 566 | CYGACC_CALL_IF_DELAY_US (5 * 100000); /* Extra delay for startup */ |
599 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); | 567 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); |
600 | xyz.total_retries++; | 568 | xyz.total_retries++; |
601 | ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__)); | 569 | ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__)); |
602 | } | 570 | } |
603 | if (stat == xyzModem_cancel) | 571 | if (stat == xyzModem_cancel) |
604 | { | 572 | { |
605 | break; | 573 | break; |
606 | } | 574 | } |
607 | } | 575 | } |
608 | *err = stat; | 576 | *err = stat; |
609 | ZM_DEBUG (zm_flush ()); | 577 | ZM_DEBUG (zm_flush ()); |
610 | return -1; | 578 | return -1; |
611 | } | 579 | } |
612 | 580 | ||
613 | int | 581 | int |
614 | xyzModem_stream_read (char *buf, int size, int *err) | 582 | xyzModem_stream_read (char *buf, int size, int *err) |
615 | { | 583 | { |
616 | int stat, total, len; | 584 | int stat, total, len; |
617 | int retries; | 585 | int retries; |
618 | 586 | ||
619 | total = 0; | 587 | total = 0; |
620 | stat = xyzModem_cancel; | 588 | stat = xyzModem_cancel; |
621 | /* Try and get 'size' bytes into the buffer */ | 589 | /* Try and get 'size' bytes into the buffer */ |
622 | while (!xyz.at_eof && (size > 0)) | 590 | while (!xyz.at_eof && (size > 0)) |
623 | { | 591 | { |
624 | if (xyz.len == 0) | 592 | if (xyz.len == 0) |
625 | { | 593 | { |
626 | retries = xyzModem_MAX_RETRIES; | 594 | retries = xyzModem_MAX_RETRIES; |
627 | while (retries-- > 0) | 595 | while (retries-- > 0) |
628 | { | 596 | { |
629 | stat = xyzModem_get_hdr (); | 597 | stat = xyzModem_get_hdr (); |
630 | if (stat == 0) | 598 | if (stat == 0) |
631 | { | 599 | { |
632 | if (xyz.blk == xyz.next_blk) | 600 | if (xyz.blk == xyz.next_blk) |
633 | { | 601 | { |
634 | xyz.tx_ack = true; | 602 | xyz.tx_ack = true; |
635 | ZM_DEBUG (zm_dprintf | 603 | ZM_DEBUG (zm_dprintf |
636 | ("ACK block %d (%d)\n", xyz.blk, __LINE__)); | 604 | ("ACK block %d (%d)\n", xyz.blk, __LINE__)); |
637 | xyz.next_blk = (xyz.next_blk + 1) & 0xFF; | 605 | xyz.next_blk = (xyz.next_blk + 1) & 0xFF; |
638 | 606 | ||
639 | #if defined(xyzModem_zmodem) || defined(USE_YMODEM_LENGTH) | 607 | #if defined(xyzModem_zmodem) || defined(USE_YMODEM_LENGTH) |
640 | if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0) | 608 | if (xyz.mode == xyzModem_xmodem || xyz.file_length == 0) |
641 | { | 609 | { |
642 | #else | 610 | #else |
643 | if (1) | 611 | if (1) |
644 | { | 612 | { |
645 | #endif | 613 | #endif |
646 | /* Data blocks can be padded with ^Z (EOF) characters */ | 614 | /* Data blocks can be padded with ^Z (EOF) characters */ |
647 | /* This code tries to detect and remove them */ | 615 | /* This code tries to detect and remove them */ |
648 | if ((xyz.bufp[xyz.len - 1] == EOF) && | 616 | if ((xyz.bufp[xyz.len - 1] == EOF) && |
649 | (xyz.bufp[xyz.len - 2] == EOF) && | 617 | (xyz.bufp[xyz.len - 2] == EOF) && |
650 | (xyz.bufp[xyz.len - 3] == EOF)) | 618 | (xyz.bufp[xyz.len - 3] == EOF)) |
651 | { | 619 | { |
652 | while (xyz.len | 620 | while (xyz.len |
653 | && (xyz.bufp[xyz.len - 1] == EOF)) | 621 | && (xyz.bufp[xyz.len - 1] == EOF)) |
654 | { | 622 | { |
655 | xyz.len--; | 623 | xyz.len--; |
656 | } | 624 | } |
657 | } | 625 | } |
658 | } | 626 | } |
659 | 627 | ||
660 | #ifdef USE_YMODEM_LENGTH | 628 | #ifdef USE_YMODEM_LENGTH |
661 | /* | 629 | /* |
662 | * See if accumulated length exceeds that of the file. | 630 | * See if accumulated length exceeds that of the file. |
663 | * If so, reduce size (i.e., cut out pad bytes) | 631 | * If so, reduce size (i.e., cut out pad bytes) |
664 | * Only do this for Y-modem (and Z-modem should it ever | 632 | * Only do this for Y-modem (and Z-modem should it ever |
665 | * be supported since it can fall back to Y-modem mode). | 633 | * be supported since it can fall back to Y-modem mode). |
666 | */ | 634 | */ |
667 | if (xyz.mode != xyzModem_xmodem && 0 != xyz.file_length) | 635 | if (xyz.mode != xyzModem_xmodem && 0 != xyz.file_length) |
668 | { | 636 | { |
669 | xyz.read_length += xyz.len; | 637 | xyz.read_length += xyz.len; |
670 | if (xyz.read_length > xyz.file_length) | 638 | if (xyz.read_length > xyz.file_length) |
671 | { | 639 | { |
672 | xyz.len -= (xyz.read_length - xyz.file_length); | 640 | xyz.len -= (xyz.read_length - xyz.file_length); |
673 | } | 641 | } |
674 | } | 642 | } |
675 | #endif | 643 | #endif |
676 | break; | 644 | break; |
677 | } | 645 | } |
678 | else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF)) | 646 | else if (xyz.blk == ((xyz.next_blk - 1) & 0xFF)) |
679 | { | 647 | { |
680 | /* Just re-ACK this so sender will get on with it */ | 648 | /* Just re-ACK this so sender will get on with it */ |
681 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); | 649 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); |
682 | continue; /* Need new header */ | 650 | continue; /* Need new header */ |
683 | } | 651 | } |
684 | else | 652 | else |
685 | { | 653 | { |
686 | stat = xyzModem_sequence; | 654 | stat = xyzModem_sequence; |
687 | } | 655 | } |
688 | } | 656 | } |
689 | if (stat == xyzModem_cancel) | 657 | if (stat == xyzModem_cancel) |
690 | { | 658 | { |
691 | break; | 659 | break; |
692 | } | 660 | } |
693 | if (stat == xyzModem_eof) | 661 | if (stat == xyzModem_eof) |
694 | { | 662 | { |
695 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); | 663 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); |
696 | ZM_DEBUG (zm_dprintf ("ACK (%d)\n", __LINE__)); | 664 | ZM_DEBUG (zm_dprintf ("ACK (%d)\n", __LINE__)); |
697 | if (xyz.mode == xyzModem_ymodem) | 665 | if (xyz.mode == xyzModem_ymodem) |
698 | { | 666 | { |
699 | CYGACC_COMM_IF_PUTC (*xyz.__chan, | 667 | CYGACC_COMM_IF_PUTC (*xyz.__chan, |
700 | (xyz.crc_mode ? 'C' : NAK)); | 668 | (xyz.crc_mode ? 'C' : NAK)); |
701 | xyz.total_retries++; | 669 | xyz.total_retries++; |
702 | ZM_DEBUG (zm_dprintf ("Reading Final Header\n")); | 670 | ZM_DEBUG (zm_dprintf ("Reading Final Header\n")); |
703 | stat = xyzModem_get_hdr (); | 671 | stat = xyzModem_get_hdr (); |
704 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); | 672 | CYGACC_COMM_IF_PUTC (*xyz.__chan, ACK); |
705 | ZM_DEBUG (zm_dprintf ("FINAL ACK (%d)\n", __LINE__)); | 673 | ZM_DEBUG (zm_dprintf ("FINAL ACK (%d)\n", __LINE__)); |
706 | } | 674 | } |
707 | xyz.at_eof = true; | 675 | xyz.at_eof = true; |
708 | break; | 676 | break; |
709 | } | 677 | } |
710 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); | 678 | CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); |
711 | xyz.total_retries++; | 679 | xyz.total_retries++; |
712 | ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__)); | 680 | ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__)); |
713 | } | 681 | } |
714 | if (stat < 0) | 682 | if (stat < 0) |
715 | { | 683 | { |
716 | *err = stat; | 684 | *err = stat; |
717 | xyz.len = -1; | 685 | xyz.len = -1; |
718 | return total; | 686 | return total; |
719 | } | 687 | } |
720 | } | 688 | } |
721 | /* Don't "read" data from the EOF protocol package */ | 689 | /* Don't "read" data from the EOF protocol package */ |
722 | if (!xyz.at_eof) | 690 | if (!xyz.at_eof) |
723 | { | 691 | { |
724 | len = xyz.len; | 692 | len = xyz.len; |
725 | if (size < len) | 693 | if (size < len) |
726 | len = size; | 694 | len = size; |
727 | memcpy (buf, xyz.bufp, len); | 695 | memcpy (buf, xyz.bufp, len); |
728 | size -= len; | 696 | size -= len; |
729 | buf += len; | 697 | buf += len; |
730 | total += len; | 698 | total += len; |
731 | xyz.len -= len; | 699 | xyz.len -= len; |
732 | xyz.bufp += len; | 700 | xyz.bufp += len; |
733 | } | 701 | } |
734 | } | 702 | } |
735 | return total; | 703 | return total; |
736 | } | 704 | } |
737 | 705 | ||
738 | void | 706 | void |
739 | xyzModem_stream_close (int *err) | 707 | xyzModem_stream_close (int *err) |
740 | { | 708 | { |
741 | diag_printf | 709 | diag_printf |
742 | ("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n", | 710 | ("xyzModem - %s mode, %d(SOH)/%d(STX)/%d(CAN) packets, %d retries\n", |
743 | xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX, | 711 | xyz.crc_mode ? "CRC" : "Cksum", xyz.total_SOH, xyz.total_STX, |
744 | xyz.total_CAN, xyz.total_retries); | 712 | xyz.total_CAN, xyz.total_retries); |
745 | ZM_DEBUG (zm_flush ()); | 713 | ZM_DEBUG (zm_flush ()); |
746 | } | 714 | } |
747 | 715 | ||
748 | /* Need to be able to clean out the input buffer, so have to take the */ | 716 | /* Need to be able to clean out the input buffer, so have to take the */ |
749 | /* getc */ | 717 | /* getc */ |
750 | void | 718 | void |
751 | xyzModem_stream_terminate (bool abort, int (*getc) (void)) | 719 | xyzModem_stream_terminate (bool abort, int (*getc) (void)) |
752 | { | 720 | { |
753 | int c; | 721 | int c; |
754 | 722 | ||
755 | if (abort) | 723 | if (abort) |
756 | { | 724 | { |
757 | ZM_DEBUG (zm_dprintf ("!!!! TRANSFER ABORT !!!!\n")); | 725 | ZM_DEBUG (zm_dprintf ("!!!! TRANSFER ABORT !!!!\n")); |
758 | switch (xyz.mode) | 726 | switch (xyz.mode) |
759 | { | 727 | { |
760 | case xyzModem_xmodem: | 728 | case xyzModem_xmodem: |
761 | case xyzModem_ymodem: | 729 | case xyzModem_ymodem: |
762 | /* The X/YMODEM Spec seems to suggest that multiple CAN followed by an equal */ | 730 | /* The X/YMODEM Spec seems to suggest that multiple CAN followed by an equal */ |
763 | /* number of Backspaces is a friendly way to get the other end to abort. */ | 731 | /* number of Backspaces is a friendly way to get the other end to abort. */ |
764 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); | 732 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); |
765 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); | 733 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); |
766 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); | 734 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); |
767 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); | 735 | CYGACC_COMM_IF_PUTC (*xyz.__chan, CAN); |
768 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); | 736 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); |
769 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); | 737 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); |
770 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); | 738 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); |
771 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); | 739 | CYGACC_COMM_IF_PUTC (*xyz.__chan, BSP); |
772 | /* Now consume the rest of what's waiting on the line. */ | 740 | /* Now consume the rest of what's waiting on the line. */ |
773 | ZM_DEBUG (zm_dprintf ("Flushing serial line.\n")); | 741 | ZM_DEBUG (zm_dprintf ("Flushing serial line.\n")); |
774 | xyzModem_flush (); | 742 | xyzModem_flush (); |
775 | xyz.at_eof = true; | 743 | xyz.at_eof = true; |
776 | break; | 744 | break; |
777 | #ifdef xyzModem_zmodem | 745 | #ifdef xyzModem_zmodem |
778 | case xyzModem_zmodem: | 746 | case xyzModem_zmodem: |
779 | /* Might support it some day I suppose. */ | 747 | /* Might support it some day I suppose. */ |
780 | #endif | 748 | #endif |
781 | break; | 749 | break; |
782 | } | 750 | } |
783 | } | 751 | } |
784 | else | 752 | else |
785 | { | 753 | { |
786 | ZM_DEBUG (zm_dprintf ("Engaging cleanup mode...\n")); | 754 | ZM_DEBUG (zm_dprintf ("Engaging cleanup mode...\n")); |
787 | /* | 755 | /* |
788 | * Consume any trailing crap left in the inbuffer from | 756 | * Consume any trailing crap left in the inbuffer from |
789 | * previous received blocks. Since very few files are an exact multiple | 757 | * previous received blocks. Since very few files are an exact multiple |
790 | * of the transfer block size, there will almost always be some gunk here. | 758 | * of the transfer block size, there will almost always be some gunk here. |
791 | * If we don't eat it now, RedBoot will think the user typed it. | 759 | * If we don't eat it now, RedBoot will think the user typed it. |
792 | */ | 760 | */ |
793 | ZM_DEBUG (zm_dprintf ("Trailing gunk:\n")); | 761 | ZM_DEBUG (zm_dprintf ("Trailing gunk:\n")); |
794 | while ((c = (*getc) ()) > -1); | 762 | while ((c = (*getc) ()) > -1); |
795 | ZM_DEBUG (zm_dprintf ("\n")); | 763 | ZM_DEBUG (zm_dprintf ("\n")); |
796 | /* | 764 | /* |
797 | * Make a small delay to give terminal programs like minicom | 765 | * Make a small delay to give terminal programs like minicom |
798 | * time to get control again after their file transfer program | 766 | * time to get control again after their file transfer program |
799 | * exits. | 767 | * exits. |
800 | */ | 768 | */ |
801 | CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000); | 769 | CYGACC_CALL_IF_DELAY_US ((cyg_int32) 250000); |
802 | } | 770 | } |
803 | } | 771 | } |
804 | 772 | ||
805 | char * | 773 | char * |
806 | xyzModem_error (int err) | 774 | xyzModem_error (int err) |
807 | { | 775 | { |
808 | switch (err) | 776 | switch (err) |
809 | { | 777 | { |
810 | case xyzModem_access: | 778 | case xyzModem_access: |
811 | return "Can't access file"; | 779 | return "Can't access file"; |
812 | break; | 780 | break; |
813 | case xyzModem_noZmodem: | 781 | case xyzModem_noZmodem: |
814 | return "Sorry, zModem not available yet"; | 782 | return "Sorry, zModem not available yet"; |
815 | break; | 783 | break; |
816 | case xyzModem_timeout: | 784 | case xyzModem_timeout: |
817 | return "Timed out"; | 785 | return "Timed out"; |
818 | break; | 786 | break; |
819 | case xyzModem_eof: | 787 | case xyzModem_eof: |
820 | return "End of file"; | 788 | return "End of file"; |
821 | break; | 789 | break; |
822 | case xyzModem_cancel: | 790 | case xyzModem_cancel: |
823 | return "Cancelled"; | 791 | return "Cancelled"; |
824 | break; | 792 | break; |
825 | case xyzModem_frame: | 793 | case xyzModem_frame: |
826 | return "Invalid framing"; | 794 | return "Invalid framing"; |
827 | break; | 795 | break; |
828 | case xyzModem_cksum: | 796 | case xyzModem_cksum: |
829 | return "CRC/checksum error"; | 797 | return "CRC/checksum error"; |
830 | break; | 798 | break; |
831 | case xyzModem_sequence: | 799 | case xyzModem_sequence: |
832 | return "Block sequence error"; | 800 | return "Block sequence error"; |
833 | break; | 801 | break; |
834 | default: | 802 | default: |
835 | return "Unknown error"; | 803 | return "Unknown error"; |
836 | break; | 804 | break; |
837 | } | 805 | } |
838 | } | 806 | } |
839 | 807 | ||
840 | /* | 808 | /* |
841 | * RedBoot interface | 809 | * RedBoot interface |
842 | */ | 810 | */ |
843 | #if 0 /* SB */ | 811 | #if 0 /* SB */ |
844 | GETC_IO_FUNCS (xyzModem_io, xyzModem_stream_open, xyzModem_stream_close, | 812 | GETC_IO_FUNCS (xyzModem_io, xyzModem_stream_open, xyzModem_stream_close, |
845 | xyzModem_stream_terminate, xyzModem_stream_read, | 813 | xyzModem_stream_terminate, xyzModem_stream_read, |
846 | xyzModem_error); | 814 | xyzModem_error); |
847 | RedBoot_load (xmodem, xyzModem_io, false, false, xyzModem_xmodem); | 815 | RedBoot_load (xmodem, xyzModem_io, false, false, xyzModem_xmodem); |
848 | RedBoot_load (ymodem, xyzModem_io, false, false, xyzModem_ymodem); | 816 | RedBoot_load (ymodem, xyzModem_io, false, false, xyzModem_ymodem); |
849 | #endif | 817 | #endif |
850 | 818 |
include/crc.h
1 | /* | 1 | /* |
2 | *========================================================================== | 2 | *========================================================================== |
3 | * | 3 | * |
4 | * crc.h | 4 | * crc.h |
5 | * | 5 | * |
6 | * Interface for the CRC algorithms. | 6 | * Interface for the CRC algorithms. |
7 | * | 7 | * |
8 | *========================================================================== | 8 | *========================================================================== |
9 | *####ECOSGPLCOPYRIGHTBEGIN#### | 9 | * SPDX-License-Identifier: eCos-2.0 |
10 | * ------------------------------------------- | ||
11 | * This file is part of eCos, the Embedded Configurable Operating System. | ||
12 | * Copyright (C) 2002 Andrew Lunn | ||
13 | * | ||
14 | * eCos is free software; you can redistribute it and/or modify it under | ||
15 | * the terms of the GNU General Public License as published by the Free | ||
16 | * Software Foundation; either version 2 or (at your option) any later version. | ||
17 | * | ||
18 | * eCos is distributed in the hope that it will be useful, but WITHOUT ANY | ||
19 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
21 | * for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License along | ||
24 | * with eCos; if not, write to the Free Software Foundation, Inc., | ||
25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
26 | * | ||
27 | * As a special exception, if other files instantiate templates or use macros | ||
28 | * or inline functions from this file, or you compile this file and link it | ||
29 | * with other works to produce a work based on this file, this file does not | ||
30 | * by itself cause the resulting work to be covered by the GNU General Public | ||
31 | * License. However the source code for this file must still be made available | ||
32 | * in accordance with section (3) of the GNU General Public License. | ||
33 | * | ||
34 | * This exception does not invalidate any other reasons why a work based on | ||
35 | * this file might be covered by the GNU General Public License. | ||
36 | * | ||
37 | * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | ||
38 | * at http: *sources.redhat.com/ecos/ecos-license/ | ||
39 | * ------------------------------------------- | ||
40 | *####ECOSGPLCOPYRIGHTEND#### | ||
41 | *========================================================================== | 10 | *========================================================================== |
42 | *#####DESCRIPTIONBEGIN#### | 11 | *#####DESCRIPTIONBEGIN#### |
43 | * | 12 | * |
44 | * Author(s): Andrew Lunn | 13 | * Author(s): Andrew Lunn |
45 | * Contributors: Andrew Lunn | 14 | * Contributors: Andrew Lunn |
46 | * Date: 2002-08-06 | 15 | * Date: 2002-08-06 |
47 | * Purpose: | 16 | * Purpose: |
48 | * Description: | 17 | * Description: |
49 | * | 18 | * |
50 | * This code is part of eCos (tm). | 19 | * This code is part of eCos (tm). |
51 | * | 20 | * |
52 | *####DESCRIPTIONEND#### | 21 | *####DESCRIPTIONEND#### |
53 | * | 22 | * |
54 | *========================================================================== | 23 | *========================================================================== |
55 | */ | 24 | */ |
56 | 25 | ||
57 | #ifndef _SERVICES_CRC_CRC_H_ | 26 | #ifndef _SERVICES_CRC_CRC_H_ |
58 | #define _SERVICES_CRC_CRC_H_ | 27 | #define _SERVICES_CRC_CRC_H_ |
59 | 28 | ||
60 | #include <linux/types.h> | 29 | #include <linux/types.h> |
61 | 30 | ||
62 | #ifndef __externC | 31 | #ifndef __externC |
63 | # ifdef __cplusplus | 32 | # ifdef __cplusplus |
64 | # define __externC extern "C" | 33 | # define __externC extern "C" |
65 | # else | 34 | # else |
66 | # define __externC extern | 35 | # define __externC extern |
67 | # endif | 36 | # endif |
68 | #endif | 37 | #endif |
69 | 38 | ||
70 | /* Compute a CRC, using the POSIX 1003 definition */ | 39 | /* Compute a CRC, using the POSIX 1003 definition */ |
71 | extern uint32_t | 40 | extern uint32_t |
72 | cyg_posix_crc32(unsigned char *s, int len); | 41 | cyg_posix_crc32(unsigned char *s, int len); |
73 | 42 | ||
74 | /* Gary S. Brown's 32 bit CRC */ | 43 | /* Gary S. Brown's 32 bit CRC */ |
75 | 44 | ||
76 | extern uint32_t | 45 | extern uint32_t |
77 | cyg_crc32(unsigned char *s, int len); | 46 | cyg_crc32(unsigned char *s, int len); |
78 | 47 | ||
79 | /* Gary S. Brown's 32 bit CRC, but accumulate the result from a */ | 48 | /* Gary S. Brown's 32 bit CRC, but accumulate the result from a */ |
80 | /* previous CRC calculation */ | 49 | /* previous CRC calculation */ |
81 | 50 | ||
82 | extern uint32_t | 51 | extern uint32_t |
83 | cyg_crc32_accumulate(uint32_t crc, unsigned char *s, int len); | 52 | cyg_crc32_accumulate(uint32_t crc, unsigned char *s, int len); |
84 | 53 | ||
85 | /* Ethernet FCS Algorithm */ | 54 | /* Ethernet FCS Algorithm */ |
86 | 55 | ||
87 | extern uint32_t | 56 | extern uint32_t |
88 | cyg_ether_crc32(unsigned char *s, int len); | 57 | cyg_ether_crc32(unsigned char *s, int len); |
89 | 58 | ||
90 | /* Ethernet FCS algorithm, but accumulate the result from a previous */ | 59 | /* Ethernet FCS algorithm, but accumulate the result from a previous */ |
91 | /* CRC calculation. */ | 60 | /* CRC calculation. */ |
92 | 61 | ||
93 | extern uint32_t | 62 | extern uint32_t |
94 | cyg_ether_crc32_accumulate(uint32_t crc, unsigned char *s, int len); | 63 | cyg_ether_crc32_accumulate(uint32_t crc, unsigned char *s, int len); |
95 | 64 | ||
96 | /* 16 bit CRC with polynomial x^16+x^12+x^5+1 */ | 65 | /* 16 bit CRC with polynomial x^16+x^12+x^5+1 */ |
97 | 66 | ||
98 | extern uint16_t cyg_crc16(unsigned char *s, int len); | 67 | extern uint16_t cyg_crc16(unsigned char *s, int len); |
99 | 68 | ||
100 | #endif /* _SERVICES_CRC_CRC_H_ */ | 69 | #endif /* _SERVICES_CRC_CRC_H_ */ |
101 | 70 |
include/xyzModem.h
1 | /* | 1 | /* |
2 | *========================================================================== | 2 | *========================================================================== |
3 | * | 3 | * |
4 | * xyzModem.h | 4 | * xyzModem.h |
5 | * | 5 | * |
6 | * RedBoot stream handler for xyzModem protocol | 6 | * RedBoot stream handler for xyzModem protocol |
7 | * | 7 | * |
8 | *========================================================================== | 8 | *========================================================================== |
9 | *####ECOSGPLCOPYRIGHTBEGIN#### | 9 | * SPDX-License-Identifier: eCos-2.0 |
10 | * ------------------------------------------- | ||
11 | * This file is part of eCos, the Embedded Configurable Operating System. | ||
12 | * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | ||
13 | * Copyright (C) 2002 Gary Thomas | ||
14 | * | ||
15 | * eCos is free software; you can redistribute it and/or modify it under | ||
16 | * the terms of the GNU General Public License as published by the Free | ||
17 | * Software Foundation; either version 2 or (at your option) any later version. | ||
18 | * | ||
19 | * eCos is distributed in the hope that it will be useful, but WITHOUT ANY | ||
20 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
22 | * for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License along | ||
25 | * with eCos; if not, write to the Free Software Foundation, Inc., | ||
26 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
27 | * | ||
28 | * As a special exception, if other files instantiate templates or use macros | ||
29 | * or inline functions from this file, or you compile this file and link it | ||
30 | * with other works to produce a work based on this file, this file does not | ||
31 | * by itself cause the resulting work to be covered by the GNU General Public | ||
32 | * License. However the source code for this file must still be made available | ||
33 | * in accordance with section (3) of the GNU General Public License. | ||
34 | * | ||
35 | * This exception does not invalidate any other reasons why a work based on | ||
36 | * this file might be covered by the GNU General Public License. | ||
37 | * | ||
38 | * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | ||
39 | * at http: *sources.redhat.com/ecos/ecos-license/ | ||
40 | * ------------------------------------------- | ||
41 | *####ECOSGPLCOPYRIGHTEND#### | ||
42 | *========================================================================== | 10 | *========================================================================== |
43 | *#####DESCRIPTIONBEGIN#### | 11 | *#####DESCRIPTIONBEGIN#### |
44 | * | 12 | * |
45 | * Author(s): gthomas | 13 | * Author(s): gthomas |
46 | * Contributors: gthomas | 14 | * Contributors: gthomas |
47 | * Date: 2000-07-14 | 15 | * Date: 2000-07-14 |
48 | * Purpose: | 16 | * Purpose: |
49 | * Description: | 17 | * Description: |
50 | * | 18 | * |
51 | * This code is part of RedBoot (tm). | 19 | * This code is part of RedBoot (tm). |
52 | * | 20 | * |
53 | *####DESCRIPTIONEND#### | 21 | *####DESCRIPTIONEND#### |
54 | * | 22 | * |
55 | *========================================================================== | 23 | *========================================================================== |
56 | */ | 24 | */ |
57 | 25 | ||
58 | #ifndef _XYZMODEM_H_ | 26 | #ifndef _XYZMODEM_H_ |
59 | #define _XYZMODEM_H_ | 27 | #define _XYZMODEM_H_ |
60 | 28 | ||
61 | #define xyzModem_xmodem 1 | 29 | #define xyzModem_xmodem 1 |
62 | #define xyzModem_ymodem 2 | 30 | #define xyzModem_ymodem 2 |
63 | /* Don't define this until the protocol support is in place */ | 31 | /* Don't define this until the protocol support is in place */ |
64 | /*#define xyzModem_zmodem 3 */ | 32 | /*#define xyzModem_zmodem 3 */ |
65 | 33 | ||
66 | #define xyzModem_access -1 | 34 | #define xyzModem_access -1 |
67 | #define xyzModem_noZmodem -2 | 35 | #define xyzModem_noZmodem -2 |
68 | #define xyzModem_timeout -3 | 36 | #define xyzModem_timeout -3 |
69 | #define xyzModem_eof -4 | 37 | #define xyzModem_eof -4 |
70 | #define xyzModem_cancel -5 | 38 | #define xyzModem_cancel -5 |
71 | #define xyzModem_frame -6 | 39 | #define xyzModem_frame -6 |
72 | #define xyzModem_cksum -7 | 40 | #define xyzModem_cksum -7 |
73 | #define xyzModem_sequence -8 | 41 | #define xyzModem_sequence -8 |
74 | 42 | ||
75 | #define xyzModem_close 1 | 43 | #define xyzModem_close 1 |
76 | #define xyzModem_abort 2 | 44 | #define xyzModem_abort 2 |
77 | 45 | ||
78 | 46 | ||
79 | #ifdef REDBOOT | 47 | #ifdef REDBOOT |
80 | extern getc_io_funcs_t xyzModem_io; | 48 | extern getc_io_funcs_t xyzModem_io; |
81 | #else | 49 | #else |
82 | #define CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT | 50 | #define CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT |
83 | #define CYGACC_CALL_IF_SET_CONSOLE_COMM(x) | 51 | #define CYGACC_CALL_IF_SET_CONSOLE_COMM(x) |
84 | 52 | ||
85 | #define diag_vprintf vprintf | 53 | #define diag_vprintf vprintf |
86 | #define diag_printf printf | 54 | #define diag_printf printf |
87 | #define diag_vsprintf vsprintf | 55 | #define diag_vsprintf vsprintf |
88 | 56 | ||
89 | #define CYGACC_CALL_IF_DELAY_US(x) udelay(x) | 57 | #define CYGACC_CALL_IF_DELAY_US(x) udelay(x) |
90 | 58 | ||
91 | typedef struct { | 59 | typedef struct { |
92 | char *filename; | 60 | char *filename; |
93 | int mode; | 61 | int mode; |
94 | int chan; | 62 | int chan; |
95 | #ifdef CYGPKG_REDBOOT_NETWORKING | 63 | #ifdef CYGPKG_REDBOOT_NETWORKING |
96 | struct sockaddr_in *server; | 64 | struct sockaddr_in *server; |
97 | #endif | 65 | #endif |
98 | } connection_info_t; | 66 | } connection_info_t; |
99 | 67 | ||
100 | #endif | 68 | #endif |
101 | 69 | ||
102 | 70 | ||
103 | int xyzModem_stream_open(connection_info_t *info, int *err); | 71 | int xyzModem_stream_open(connection_info_t *info, int *err); |
104 | void xyzModem_stream_close(int *err); | 72 | void xyzModem_stream_close(int *err); |
105 | void xyzModem_stream_terminate(bool method, int (*getc)(void)); | 73 | void xyzModem_stream_terminate(bool method, int (*getc)(void)); |
106 | int xyzModem_stream_read(char *buf, int size, int *err); | 74 | int xyzModem_stream_read(char *buf, int size, int *err); |
107 | char *xyzModem_error(int err); | 75 | char *xyzModem_error(int err); |
108 | 76 | ||
109 | #endif /* _XYZMODEM_H_ */ | 77 | #endif /* _XYZMODEM_H_ */ |
110 | 78 |
lib/crc16.c
1 | /* | 1 | /* |
2 | *========================================================================== | 2 | *========================================================================== |
3 | * | 3 | * |
4 | * crc16.c | 4 | * crc16.c |
5 | * | 5 | * |
6 | * 16 bit CRC with polynomial x^16+x^12+x^5+1 | 6 | * 16 bit CRC with polynomial x^16+x^12+x^5+1 |
7 | * | 7 | * |
8 | *========================================================================== | 8 | *========================================================================== |
9 | *####ECOSGPLCOPYRIGHTBEGIN#### | 9 | * SPDX-License-Identifier: eCos-2.0 |
10 | * ------------------------------------------- | ||
11 | * This file is part of eCos, the Embedded Configurable Operating System. | ||
12 | * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | ||
13 | * Copyright (C) 2002 Gary Thomas | ||
14 | * | ||
15 | * eCos is free software; you can redistribute it and/or modify it under | ||
16 | * the terms of the GNU General Public License as published by the Free | ||
17 | * Software Foundation; either version 2 or (at your option) any later version. | ||
18 | * | ||
19 | * eCos is distributed in the hope that it will be useful, but WITHOUT ANY | ||
20 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
22 | * for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License along | ||
25 | * with eCos; if not, write to the Free Software Foundation, Inc., | ||
26 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
27 | * | ||
28 | * As a special exception, if other files instantiate templates or use macros | ||
29 | * or inline functions from this file, or you compile this file and link it | ||
30 | * with other works to produce a work based on this file, this file does not | ||
31 | * by itself cause the resulting work to be covered by the GNU General Public | ||
32 | * License. However the source code for this file must still be made available | ||
33 | * in accordance with section (3) of the GNU General Public License. | ||
34 | * | ||
35 | * This exception does not invalidate any other reasons why a work based on | ||
36 | * this file might be covered by the GNU General Public License. | ||
37 | * | ||
38 | * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | ||
39 | * at http: *sources.redhat.com/ecos/ecos-license/ | ||
40 | * ------------------------------------------- | ||
41 | *####ECOSGPLCOPYRIGHTEND#### | ||
42 | *========================================================================== | 10 | *========================================================================== |
43 | *#####DESCRIPTIONBEGIN#### | 11 | *#####DESCRIPTIONBEGIN#### |
44 | * | 12 | * |
45 | * Author(s): gthomas | 13 | * Author(s): gthomas |
46 | * Contributors: gthomas,asl | 14 | * Contributors: gthomas,asl |
47 | * Date: 2001-01-31 | 15 | * Date: 2001-01-31 |
48 | * Purpose: | 16 | * Purpose: |
49 | * Description: | 17 | * Description: |
50 | * | 18 | * |
51 | * This code is part of eCos (tm). | 19 | * This code is part of eCos (tm). |
52 | * | 20 | * |
53 | *####DESCRIPTIONEND#### | 21 | *####DESCRIPTIONEND#### |
54 | * | 22 | * |
55 | *========================================================================== | 23 | *========================================================================== |
56 | */ | 24 | */ |
57 | 25 | ||
58 | #include "crc.h" | 26 | #include "crc.h" |
59 | 27 | ||
60 | /* Table of CRC constants - implements x^16+x^12+x^5+1 */ | 28 | /* Table of CRC constants - implements x^16+x^12+x^5+1 */ |
61 | static const uint16_t crc16_tab[] = { | 29 | static const uint16_t crc16_tab[] = { |
62 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, | 30 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, |
63 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, | 31 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, |
64 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, | 32 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, |
65 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, | 33 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, |
66 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, | 34 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, |
67 | 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, | 35 | 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, |
68 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, | 36 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, |
69 | 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, | 37 | 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, |
70 | 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, | 38 | 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, |
71 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, | 39 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, |
72 | 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, | 40 | 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, |
73 | 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, | 41 | 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, |
74 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, | 42 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, |
75 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, | 43 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, |
76 | 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, | 44 | 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, |
77 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, | 45 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, |
78 | 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, | 46 | 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, |
79 | 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, | 47 | 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, |
80 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, | 48 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, |
81 | 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, | 49 | 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, |
82 | 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, | 50 | 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, |
83 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, | 51 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, |
84 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, | 52 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, |
85 | 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, | 53 | 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, |
86 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, | 54 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, |
87 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, | 55 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, |
88 | 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, | 56 | 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, |
89 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, | 57 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, |
90 | 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, | 58 | 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, |
91 | 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, | 59 | 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, |
92 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, | 60 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, |
93 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, | 61 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, |
94 | }; | 62 | }; |
95 | 63 | ||
96 | uint16_t | 64 | uint16_t |
97 | cyg_crc16(unsigned char *buf, int len) | 65 | cyg_crc16(unsigned char *buf, int len) |
98 | { | 66 | { |
99 | int i; | 67 | int i; |
100 | uint16_t cksum; | 68 | uint16_t cksum; |
101 | 69 | ||
102 | cksum = 0; | 70 | cksum = 0; |
103 | for (i = 0; i < len; i++) { | 71 | for (i = 0; i < len; i++) { |
104 | cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8); | 72 | cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8); |
105 | } | 73 | } |
106 | return cksum; | 74 | return cksum; |
107 | } | 75 | } |
108 | 76 |