├── .gitignore
├── .travis.yml
├── Makefile
├── Makefile.vc
├── README
├── StdAfx.h
├── adprog.c
├── adprog.h
├── gpl.txt
├── lgpl-3.0.txt
├── lpc21isp.c
├── lpc21isp.cbp
├── lpc21isp.h
├── lpcprog.c
├── lpcprog.dsp
├── lpcprog.dsw
├── lpcprog.h
├── lpcterm.c
└── lpcterm.h
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | *.depend
4 | *.layout
5 | *.*~
6 | *.o
7 | lpc21isp
8 | .*/
9 | .DS_Store
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 | compiler:
3 | - gcc
4 | # Change this to your needs
5 | script: make
6 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all: lpc21isp
2 |
3 | GLOBAL_DEP = adprog.h lpc21isp.h lpcprog.h lpcterm.h
4 | CC = gcc
5 |
6 | ifneq ($(findstring(freebsd, $(OSTYPE))),)
7 | CFLAGS+=-D__FREEBSD__
8 | endif
9 |
10 | ifeq ($(OSTYPE),)
11 | OSTYPE = $(shell uname)
12 | endif
13 |
14 | CFLAGS += -Wall
15 |
16 | ifneq ($(findstring darwin,$(OSTYPE)),)
17 | CFLAGS+=-D__APPLE__
18 | else
19 | CFLAGS += -static
20 | endif
21 |
22 | adprog.o: adprog.c $(GLOBAL_DEP)
23 | $(CC) $(CDEBUG) $(CFLAGS) -c -o adprog.o adprog.c
24 |
25 | lpcprog.o: lpcprog.c $(GLOBAL_DEP)
26 | $(CC) $(CDEBUG) $(CFLAGS) -c -o lpcprog.o lpcprog.c
27 |
28 | lpcterm.o: lpcterm.c $(GLOBAL_DEP)
29 | $(CC) $(CDEBUG) $(CFLAGS) -c -o lpcterm.o lpcterm.c
30 |
31 | lpc21isp: lpc21isp.c adprog.o lpcprog.o lpcterm.o $(GLOBAL_DEP)
32 | $(CC) $(CDEBUG) $(CFLAGS) -o lpc21isp lpc21isp.c adprog.o lpcprog.o lpcterm.o
33 |
34 | clean:
35 | $(RM) adprog.o lpcprog.o lpcterm.o lpc21isp
36 |
--------------------------------------------------------------------------------
/Makefile.vc:
--------------------------------------------------------------------------------
1 | all: lpc21isp.exe
2 |
3 | GLOBAL_DEP = lpc21isp.h adprog.h lpcprog.h lpcterm.h
4 | RM = del
5 | CC = cl
6 |
7 | # CFLAGS = -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS
8 | CFLAGS =
9 |
10 | adprog.obj: adprog.c $(GLOBAL_DEP)
11 | $(CC) -c $(CFLAGS) adprog.c
12 |
13 | lpcprog.obj: lpcprog.c $(GLOBAL_DEP)
14 | $(CC) -c $(CFLAGS) lpcprog.c
15 |
16 | lpcterm.obj: lpcterm.c $(GLOBAL_DEP)
17 | $(CC) -c $(CFLAGS) lpcterm.c
18 |
19 | lpc21isp.obj: lpc21isp.c $(GLOBAL_DEP)
20 | $(CC) -c $(CFLAGS) lpc21isp.c
21 |
22 | lpc21isp.exe: lpc21isp.obj adprog.obj lpcprog.obj lpcterm.obj
23 | $(CC) /Felpc21isp.exe lpc21isp.obj adprog.obj lpcprog.obj lpcterm.obj winmm.lib
24 |
25 | clean:
26 | $(RM) adprog.obj lpcprog.obj lpcterm.obj lpc21isp.obj lpc21isp.exe vc*.pdb
27 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: README
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2013, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 |
34 | To compile with microsoft visual studio:
35 | - Open console. Execute bat file from your installation, e.g.
36 | "c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
37 | - Go to directory where you unpacked the source.
38 | - Run
39 | nmake /f Makefile.vc clean all
40 |
41 | To compile with gcc (linux, cygwin, ...)
42 | - Open shell / terminal windows
43 | - Run (if you want to use make and gcc)
44 | make -f Makefile.gnu clean all
45 | - Run (if you want to use gmake and gcc)
46 | gmake -f Makefile.gnu clean all
47 |
--------------------------------------------------------------------------------
/StdAfx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/capiman/lpc21isp/cf89d0b122ef02358e0f130b8f32cb804c11a54e/StdAfx.h
--------------------------------------------------------------------------------
/adprog.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: adprog.c
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2014, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | #if defined(_WIN32)
34 | #if !defined __BORLANDC__
35 | #include "StdAfx.h"
36 | #endif
37 | #endif // defined(_WIN32)
38 | #include "lpc21isp.h"
39 |
40 | #ifdef AD_SUPPORT
41 | #include "adprog.h"
42 |
43 | /***************************** AnalogDevicesSync ************************/
44 | /** Attempt to synchronize with an Analog Device ARM micro. Sends a
45 | backspace and reads back the microcontrollers response. Performs
46 | multiple retries. Exits the program on error, returns to caller in the
47 | case of success.
48 | */
49 | static void AnalogDevicesSync(ISP_ENVIRONMENT *IspEnvironment)
50 | {
51 | BINARY sync; /* Holds sync command. */
52 | AD_SYNC_RESPONSE response; /* Response from micro. */
53 | int sync_attempts; /* Number of retries. */
54 |
55 | /* Make sure we don't read garbage later instead of the */
56 | /* response we expect from the micro. */
57 | ClearSerialPortBuffers(IspEnvironment);
58 |
59 | DebugPrintf(2, "Synchronizing\n"); /* Progress report. */
60 |
61 | sync = ANALOG_DEVICES_SYNC_CHAR; /* Build up sync command. */
62 |
63 | /* Perform the actual sync attempt. First send the sync */
64 | /* character, the attempt to read back the response. For the */
65 | /* AD ARM micro this is a fixed length block. If response is */
66 | /* received attempt to validate it by comparing the first */
67 | /* characters to those expected. If the received block does */
68 | /* not validate or is incomplete empty the serial buffer and */
69 | /* retry. */
70 | for (sync_attempts = 0; sync_attempts < 5; sync_attempts++)
71 | {
72 | SendComPortBlock(IspEnvironment, &sync, 1);
73 |
74 | if (ReceiveComPortBlockComplete(IspEnvironment, &response, sizeof(response),
75 | 500) == 0)
76 | {
77 |
78 | if (memcmp(response.product_id, ANALOG_DEVICES_SYNC_RESPONSE,
79 | ANALOG_DEVICES_SYNC_SIZE) == 0)
80 | {
81 | return;
82 | }
83 | else
84 | {
85 | DumpString(3, &response, sizeof(response),
86 | "Unexpected response to sync attempt ");
87 | }
88 | }
89 | else
90 | {
91 | DebugPrintf(3, "No (or incomplete) answer on sync attempt\n");
92 | }
93 |
94 | ClearSerialPortBuffers(IspEnvironment);
95 | }
96 |
97 | DebugPrintf(1, "No (or unacceptable) answer on sync attempt\n");
98 | exit(4);
99 | }
100 |
101 | typedef struct {
102 | char start1;
103 | char start2;
104 | BINARY bytes;
105 | char cmd;
106 | BINARY address_h;
107 | BINARY address_u;
108 | BINARY address_m;
109 | BINARY address_l;
110 | BINARY data[251];
111 | } AD_PACKET;
112 |
113 | /***************************** AnalogDevicesFormPacket ******************/
114 | /** Create an Analog Devices communication packet from the constituent
115 | elements.
116 | \param [in] cmd The command being sent, one of 'E' for erase, 'W' for
117 | write, 'V' for verify or 'R' for run..
118 | \param [in] no_bytes the number of data bytes to send with the command in
119 | the packet.
120 | \param [in] address the address to apply the command to.
121 | \param [in] data the data to send with the packet, may be null if no_bytes
122 | is zero.
123 | \param[out] packet that will be filled.
124 | */
125 | static void AnalogDevicesFormPacket(ISP_ENVIRONMENT *IspEnvironment,
126 | char cmd, int no_bytes, unsigned int address,
127 | const void *data, AD_PACKET *packet)
128 | {
129 | BINARY checksum;
130 | const BINARY *data_in;
131 | int i;
132 |
133 | (void)IspEnvironment; /* never used in this function */
134 |
135 | /* Some sanity checking on the arguments. These should only */
136 | /* fail if there is a bug in the caller. */
137 | /* Check 1) that the number of data bytes is in an acceptable */
138 | /* range, 2) that we have a non-null pointer if data is being */
139 | /* put in the packet and 3) that we have a non-null pointer to */
140 | /* the packet to be filled. We just exit with an error message */
141 | /* if any of these tests fail. */
142 | if ((no_bytes < 0) || (no_bytes > 250))
143 | {
144 | DebugPrintf(1,
145 | "The number of bytes (%d) passed to FormPacket is invalid.\n",
146 | no_bytes);
147 | exit(-1);
148 | }
149 | if ((data == 0) && (no_bytes != 0))
150 | {
151 | DebugPrintf(1,
152 | "A null pointer to data paased to FormPacket when data was expected.\n");
153 | exit(-1);
154 | }
155 | if (packet == 0)
156 | {
157 | DebugPrintf(1,
158 | "A null packet pointer was passed to FormPacket.\n");
159 | exit(-1);
160 | }
161 |
162 | checksum = 0; /* Checksum starts at zero. */
163 |
164 | data_in = (BINARY*) data; /* Pointer pun so we can walk through */
165 | /* the data. */
166 |
167 | packet->start1 = 0x7; /* The start of the packet is constant.*/
168 | packet->start2 = 0xE;
169 |
170 | /* Fill in the rest of the packet and calculate the checksum */
171 | /* as we go. */
172 |
173 | /* The number of bytes is the number of data bytes + the */
174 | /* address bytes + the command byte. */
175 | packet->bytes = (BINARY)(no_bytes + 5);
176 |
177 | checksum += packet->bytes;
178 |
179 | /* The command for the packet being sent. No error checking */
180 | /* done on this. */
181 | packet->cmd = cmd;
182 |
183 | checksum += cmd;
184 |
185 | /* Now break up the address and place in the proper packet */
186 | /* locations. */
187 | packet->address_l = (BINARY)(address & 0xFF);
188 | packet->address_m = (BINARY)((address >> 8) & 0xFF);
189 | packet->address_u = (BINARY)((address >> 16) & 0xFF);
190 | packet->address_h = (BINARY)((address >> 24) & 0xFF);
191 |
192 | checksum += packet->address_l;
193 | checksum += packet->address_m;
194 | checksum += packet->address_u;
195 | checksum += packet->address_h;
196 |
197 | /* Copy the data bytes into the packet. We could use memcpy */
198 | /* but we have to calculate the checksum anyway. */
199 | for (i = 0; i < no_bytes; i++)
200 | {
201 | packet->data[i] = data_in[i];
202 | checksum += data_in[i];
203 | }
204 |
205 | /* Finally, add the checksum to the end of the packet. */
206 | packet->data[i] = (BINARY)-checksum;
207 | }
208 |
209 | /***************************** AnalogDevicesSendPacket ******************/
210 | /** Send a previously form Analog Devices communication. Retry a
211 | couple of times if needed but fail by exiting the program if no ACK is
212 | forthcoming.
213 | \param [in] packet the packet to send.
214 | */
215 | static void AnalogDevicesSendPacket(ISP_ENVIRONMENT *IspEnvironment,
216 | const AD_PACKET * packet)
217 | {
218 | BINARY response;
219 | int retry = 0;
220 |
221 | do {
222 | retry++;
223 |
224 | /* Make sure we don't read garbage later instead of */
225 | /* the response we expect from the micro. */
226 | ClearSerialPortBuffers(IspEnvironment);
227 |
228 | /* Send the packet, the size is the number of data */
229 | /* bytes in the packet plus 3 bytes worth of header */
230 | /* plus checksum. */
231 | SendComPortBlock(IspEnvironment, packet, packet->bytes + 4);
232 |
233 | /* Receive the response and check, return to caller */
234 | /* if successful. */
235 | if (ReceiveComPortBlockComplete(IspEnvironment, &response, 1, 5000) == 0)
236 | {
237 | if (response == ANALOG_DEVICES_ACK)
238 | {
239 | DebugPrintf(3, "Packet Sent\n");
240 | return;
241 | }
242 | if (response != ANALOG_DEVICES_NAK)
243 | {
244 | DebugPrintf(3, "Unexpected response to packet (%x)\n", (int)response);
245 | }
246 | DebugPrintf(2, "*");
247 | }
248 | } while (retry < 3);
249 |
250 | DebugPrintf(1, "Send packet failed\n");
251 | exit(-1);
252 | }
253 |
254 | /***************************** AnalogDevicesErase ***********************/
255 | /** Erase the Analog Devices micro. We take the simple way out and
256 | just erase the whole thing.
257 | */
258 | static void AnalogDevicesErase(ISP_ENVIRONMENT *IspEnvironment)
259 | {
260 | BINARY pages;
261 | AD_PACKET packet;
262 |
263 | pages = 0;
264 | DebugPrintf(2, "Erasing .. ");
265 | AnalogDevicesFormPacket(IspEnvironment, 'E', 1, 0, &pages, &packet);
266 | AnalogDevicesSendPacket(IspEnvironment, &packet);
267 | DebugPrintf(2, "Erased\n");
268 | }
269 |
270 | #define AD_PACKET_SIZE (250)
271 |
272 | /***************************** AnalogDevicesWrite ***********************/
273 | /** Write the program.
274 | \param [in] data the program to download to the micro.
275 | \param [in] address where to start placing the program.
276 | \param [in] bytes the size of the progrm to download.
277 | */
278 | static void AnalogDevicesWrite(ISP_ENVIRONMENT *IspEnvironment,
279 | const void *data, long address, size_t bytes)
280 | {
281 | AD_PACKET packet;
282 | const BINARY *prog_data;
283 |
284 | DebugPrintf(2, "Writing %d bytes ", bytes);
285 | prog_data = (const BINARY*) data;
286 | while (bytes > AD_PACKET_SIZE)
287 | {
288 | AnalogDevicesFormPacket(IspEnvironment, 'W', AD_PACKET_SIZE, address, prog_data, &packet);
289 | AnalogDevicesSendPacket(IspEnvironment, &packet);
290 | address += AD_PACKET_SIZE;
291 | prog_data += AD_PACKET_SIZE;
292 | bytes -= AD_PACKET_SIZE;
293 | DebugPrintf(2, ".");
294 | }
295 | if (bytes > 0)
296 | {
297 | AnalogDevicesFormPacket(IspEnvironment, 'W', bytes, address, prog_data, &packet);
298 | AnalogDevicesSendPacket(IspEnvironment, &packet);
299 | DebugPrintf(2, ".");
300 | }
301 | }
302 |
303 | /***************************** AnalogDevicesDownload ********************/
304 | /** Perform the download into an Analog Devices micro. As a quick and
305 | * dirty hack against flash relocations at 0x80000
306 | * \return 0 if ok, error code else
307 | * \ToDo: possible to implement the return value instead of calling
308 | * exit() in sub-functions
309 | */
310 | int AnalogDevicesDownload(ISP_ENVIRONMENT *IspEnvironment)
311 | {
312 | AnalogDevicesSync(IspEnvironment);
313 | AnalogDevicesErase(IspEnvironment);
314 | if (IspEnvironment->BinaryLength > 0x80000)
315 | {
316 | DebugPrintf(2, "Note: Flash remapped 0x80000 to 0.\n");
317 | AnalogDevicesWrite(IspEnvironment, IspEnvironment->BinaryContent + 0x80000, 0, IspEnvironment->BinaryLength-0x80000);
318 | }
319 | else
320 | {
321 | AnalogDevicesWrite(IspEnvironment, IspEnvironment->BinaryContent, 0, IspEnvironment->BinaryLength);
322 | }
323 | return (0);
324 | }
325 | #endif // AD_SUPPORT
326 |
--------------------------------------------------------------------------------
/adprog.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: adprog.h
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2011, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | #define ANALOG_DEVICES_SYNC_CHAR ((BINARY)0x08)
34 | #define ANALOG_DEVICES_SYNC_RESPONSE ("ADuC")
35 | #define ANALOG_DEVICES_SYNC_SIZE (strlen(ANALOG_DEVICES_SYNC_RESPONSE))
36 | #define ANALOG_DEVICES_ACK 0x6
37 | #define ANALOG_DEVICES_NAK 0x7
38 |
39 | typedef struct
40 | {
41 | BINARY product_id[15];
42 | BINARY version[3];
43 | BINARY reserved[4];
44 | BINARY terminator[2];
45 | } AD_SYNC_RESPONSE;
46 |
47 | int AnalogDevicesDownload(ISP_ENVIRONMENT *IspEnvironment);
48 |
--------------------------------------------------------------------------------
/gpl.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/lgpl-3.0.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/lpc21isp.cbp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/lpc21isp.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: lsp21isp.h
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2014, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | // #define INTEGRATED_IN_WIN_APP
34 |
35 | #if defined(_WIN32) && !defined(__CYGWIN__)
36 | #define COMPILE_FOR_WINDOWS
37 | #define COMPILED_FOR "Windows"
38 | #elif defined(__CYGWIN__)
39 | #define COMPILE_FOR_CYGWIN
40 | #define COMPILED_FOR "Cygwin"
41 | #elif (defined(__arm__) || defined(__thumb__)) && !defined(__linux__)
42 | #define COMPILE_FOR_LPC21
43 | #define COMPILED_FOR "ARM"
44 | #define printf iprintf
45 | #elif defined(__APPLE__)
46 | #define COMPILE_FOR_LINUX
47 | #define COMPILED_FOR "Apple MacOS X"
48 | #elif defined(__FreeBSD__)
49 | #define COMPILE_FOR_LINUX
50 | #define COMPILED_FOR "FreeBSD"
51 | #elif defined(__OpenBSD__)
52 | #define COMPILE_FOR_LINUX
53 | #define COMPILED_FOR "OpenBSD"
54 | #else
55 | #define COMPILE_FOR_LINUX
56 | #define COMPILED_FOR "Linux"
57 | #endif
58 |
59 | // The Required features can be enabled / disabled here
60 | #define LPC_SUPPORT
61 |
62 | #ifndef COMPILE_FOR_LPC21
63 | #define AD_SUPPORT
64 | #define TERMINAL_SUPPORT
65 | #endif
66 |
67 | #if defined(__linux__) && !defined(GPIO_RST) && !defined(GPIO_ISP)
68 | #define SYSFS_GPIO_SUPPORT
69 | #endif
70 |
71 | #if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
72 | #include
73 | #include
74 | #endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
75 |
76 | #if defined COMPILE_FOR_WINDOWS
77 | #include
78 | //#define TRACE(x) OutputDebugString(x)
79 | #define TRACE(x) printf("%s",x)
80 | #endif // defined COMPILE_FOR_WINDOWS
81 |
82 | #if defined COMPILE_FOR_CYGWIN
83 | //#define TRACE(x) OutputDebugString(x)
84 | #define TRACE(x) printf("%s",x)
85 | #endif // defined COMPILE_FOR_WINDOWS
86 |
87 | #if defined COMPILE_FOR_LINUX
88 | #include
89 | #include
90 | #include
91 | #include
92 | #include
93 | #include
94 | extern void Sleep(unsigned long MilliSeconds);
95 | #define TRACE(x) printf("%s",x)
96 | #endif // defined COMPILE_FOR_LINUX
97 |
98 | #if defined COMPILE_FOR_LINUX || defined COMPILE_FOR_CYGWIN
99 | #include
100 | #include // for read and return value of lseek
101 | #include // for select_time
102 | extern int kbhit(void);
103 | extern int getch(void);
104 | extern struct termios keyboard_origtty;
105 | #endif // defined COMPILE_FOR_LINUX || defined COMPILE_FOR_CYGWIN
106 |
107 | #include // isdigit()
108 | #include // stdout
109 | #include
110 | #include
111 | #if defined (COMPILE_FOR_LINUX)
112 | #if defined(__OpenBSD__)
113 | #include
114 | #else
115 | #include
116 | #endif
117 | #endif
118 |
119 | #if defined COMPILE_FOR_LPC21
120 | #include
121 | #include
122 | //#include // if using libc serial port communication
123 | #else
124 | #include
125 | #endif
126 |
127 | typedef enum
128 | {
129 | NXP_ARM,
130 | ANALOG_DEVICES_ARM
131 | } TARGET;
132 |
133 | typedef enum
134 | {
135 | PROGRAM_MODE,
136 | RUN_MODE
137 | } TARGET_MODE;
138 |
139 | typedef enum
140 | {
141 | FORMAT_BINARY,
142 | FORMAT_HEX
143 | } FILE_FORMAT_TYPE;
144 |
145 | typedef unsigned char BINARY; // Data type used for microcontroller
146 |
147 | /** Used to create list of files to read in. */
148 | typedef struct file_list FILE_LIST;
149 |
150 | #define ERR_RECORD_TYPE_LOADFILE 55 /**< File record type not yet implemented. */
151 | #define ERR_ALLOC_FILE_LIST 60 /**< Error allocation file list. */
152 | #define ERR_FILE_OPEN_HEX 61 /**< Couldn't open hex file. */
153 | #define ERR_FILE_SIZE_HEX 62 /**< Unexpected hex file size. */
154 | #define ERR_FILE_ALLOC_HEX 63 /**< Couldn't allocate enough memory for hex file. */
155 | #define ERR_MEMORY_RANGE 69 /**< Out of memory range. */
156 |
157 | /** Structure used to build list of input files. */
158 | struct file_list
159 | {
160 | const char *name; /**< The name of the input file. */
161 | FILE_LIST *prev; /**< The previous file name in the list.*/
162 | char hex_flag; /**< True if the input file is hex. */
163 | };
164 |
165 | typedef struct
166 | {
167 | #if !defined COMPILE_FOR_LPC21
168 | TARGET micro; // The type of micro that will be programmed.
169 | FILE_FORMAT_TYPE FileFormat;
170 | unsigned char ProgramChip; // Normally set
171 |
172 | unsigned char ControlLines;
173 | unsigned char ControlLinesSwapped;
174 | unsigned char ControlLinesInverted;
175 | unsigned char LogFile;
176 | FILE_LIST *f_list; // List of files to read in.
177 | int nQuestionMarks; // how many times to try to synchronise
178 | int DoNotStart;
179 | int BootHold;
180 | char *serial_port; // Name of the serial port to use to
181 | // communicate with the microcontroller.
182 | // Read from the command line.
183 | #endif // !defined COMPILE_FOR_LPC21
184 |
185 | unsigned char TerminalOnly; // Declared here for lazyness saves ifdef's
186 | #ifdef TERMINAL_SUPPORT
187 | unsigned char TerminalAfterUpload;
188 | unsigned char LocalEcho;
189 | #endif
190 |
191 | #if defined SYSFS_GPIO_SUPPORT
192 | unsigned char GpioRst;
193 | unsigned char GpioIsp;
194 | #endif
195 |
196 | unsigned char HalfDuplex; // Only used for LPC Programming
197 | unsigned char WriteDelay;
198 | unsigned char DetectOnly;
199 | unsigned char WipeDevice;
200 | unsigned char Verify;
201 | int DetectedDevice; /* index in LPCtypes[] array */
202 | char *baud_rate; /**< Baud rate to use on the serial
203 | * port communicating with the
204 | * microcontroller. Read from the
205 | * command line. */
206 |
207 | char StringOscillator[6]; /**< Holds representation of oscillator
208 | * speed from the command line. */
209 |
210 | BINARY *FileContent;
211 | BINARY *BinaryContent; /**< Binary image of the */
212 | /* microcontroller's memory. */
213 | unsigned long BinaryLength;
214 | unsigned long BinaryOffset;
215 | unsigned long StartAddress;
216 | unsigned long BinaryMemSize;
217 |
218 | #if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
219 | HANDLE hCom;
220 | #endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
221 |
222 | #if defined COMPILE_FOR_LINUX || defined COMPILE_FOR_LPC21
223 | int fdCom;
224 | #endif // defined COMPILE_FOR_LINUX || defined COMPILE_FOR_LPC21
225 |
226 | #if defined COMPILE_FOR_LINUX
227 | struct termios oldtio, newtio;
228 | #endif // defined COMPILE_FOR_LINUX
229 |
230 | #ifdef INTEGRATED_IN_WIN_APP
231 | unsigned char NoSync;
232 | #endif
233 |
234 | #if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
235 | unsigned long serial_timeout_count; /**< Local used to track timeouts on serial port read. */
236 | #else
237 | unsigned serial_timeout_count; /**< Local used to track timeouts on serial port read. */
238 | #endif
239 |
240 | } ISP_ENVIRONMENT;
241 |
242 | #if defined COMPILE_FOR_LPC21
243 |
244 | #define DebugPrintf(in, ...)
245 |
246 | #else
247 | extern int debug_level;
248 |
249 | #if defined INTEGRATED_IN_WIN_APP
250 |
251 | #define DebugPrintf AppDebugPrintf
252 | void AppDebugPrintf(int level, const char *fmt, ...);
253 |
254 | #define exit(val) AppException(val)
255 | void AppException(int exception_level);
256 |
257 | int AppDoProgram(int argc, char *argv[]);
258 |
259 | #define Exclude_kbhit 1
260 | int AppSyncing(int trials);
261 | void AppWritten(int size);
262 |
263 | #else
264 | void DebugPrintf(int level, const char *fmt, ...);
265 | //#define DebugPrintf(level, ...) if (level <= debug_level) { TRACE( __VA_ARGS__ ); }
266 | #endif
267 |
268 | void ClearSerialPortBuffers(ISP_ENVIRONMENT *IspEnvironment);
269 | void ControlXonXoffSerialPort(ISP_ENVIRONMENT *IspEnvironment, unsigned char XonXoff);
270 |
271 | #endif
272 |
273 |
274 | #if defined COMPILE_FOR_LINUX
275 | #define stricmp strcasecmp
276 | #define strnicmp strncasecmp
277 | #endif // defined COMPILE_FOR_LINUX
278 |
279 | #ifndef O_BINARY
280 | #define O_BINARY 0
281 | #endif // O_BINARY
282 |
283 | #ifndef DWORD
284 | #define DWORD unsigned long
285 | #endif // DWORD
286 |
287 | /*
288 | debug levels
289 | 0 - very quiet - Nothing gets printed at this level
290 | 1 - quiet - Only error messages should be printed
291 | 2 - indicate progress - Add progress messages
292 | 3 - first level debug - Major level tracing
293 | 4 - second level debug - Add detailed debugging
294 | 5 - log comm's - log serial I/O
295 | */
296 |
297 |
298 | void ReceiveComPort(ISP_ENVIRONMENT *IspEnvironment,
299 | const char *Ans, unsigned long MaxSize,
300 | unsigned long *RealSize, unsigned long WantedNr0x0A,
301 | unsigned timeOutMilliseconds);
302 | void PrepareKeyboardTtySettings(void);
303 | void ResetKeyboardTtySettings(void);
304 | void ResetTarget(ISP_ENVIRONMENT *IspEnvironment, TARGET_MODE mode);
305 |
306 | void DumpString(int level, const void *s, size_t size, const char *prefix_string);
307 | void SendComPort(ISP_ENVIRONMENT *IspEnvironment, const char *s);
308 | void SendComPortBlock(ISP_ENVIRONMENT *IspEnvironment, const void *s, size_t n);
309 | int ReceiveComPortBlockComplete(ISP_ENVIRONMENT *IspEnvironment, void *block, size_t size, unsigned timeout);
310 | void ClearSerialPortBuffers(ISP_ENVIRONMENT *IspEnvironment);
311 | void ControlXonXoffSerialPort(ISP_ENVIRONMENT *IspEnvironment, unsigned char XonXoff);
312 |
313 |
--------------------------------------------------------------------------------
/lpcprog.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: lpcprog.c
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2014, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | // This file is for the Actual Programming of the LPC Chips
34 |
35 | #if defined(_WIN32)
36 | #include "malloc.h"
37 | #if !defined __BORLANDC__
38 | #include "StdAfx.h"
39 | #endif
40 | #endif // defined(_WIN32)
41 | #include "lpc21isp.h"
42 |
43 | #ifdef LPC_SUPPORT
44 | #include "lpcprog.h"
45 |
46 | static const unsigned int SectorTable_210x[] =
47 | {
48 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
49 | 8192, 8192, 8192, 8192, 8192, 8192, 8192
50 | };
51 |
52 | static const unsigned int SectorTable_2103[] =
53 | {
54 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096
55 | };
56 |
57 | static const unsigned int SectorTable_2109[] =
58 | {
59 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192
60 | };
61 |
62 | static const unsigned int SectorTable_211x[] =
63 | {
64 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
65 | 8192, 8192, 8192, 8192, 8192, 8192, 8192,
66 | };
67 |
68 | static const unsigned int SectorTable_212x[] =
69 | {
70 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
71 | 65536, 65536, 8192, 8192, 8192, 8192, 8192, 8192, 8192
72 | };
73 |
74 | // Used for devices with 500K (LPC2138 and LPC2148) and
75 | // for devices with 504K (1 extra 4k block at the end)
76 | static const unsigned int SectorTable_213x[] =
77 | {
78 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
79 | 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
80 | 32768, 32768, 32768, 32768, 32768, 32768, 4096, 4096,
81 | 4096, 4096, 4096, 4096
82 | };
83 |
84 | // Used for LPC11xx devices
85 | static const unsigned int SectorTable_11xx[] =
86 | {
87 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
88 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
89 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
90 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096
91 | };
92 |
93 | // Used for LPC17xx devices
94 | static const unsigned int SectorTable_17xx[] =
95 | {
96 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
97 | 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
98 | 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
99 | 32768, 32768, 32768, 32768, 32768, 32768
100 | };
101 |
102 | // Used for LPC18xx devices
103 | static const unsigned int SectorTable_18xx[] =
104 | {
105 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
106 | 65536, 65536, 65536, 65536, 65536, 65536, 65536
107 | };
108 |
109 | // Used for LPC43xx devices
110 | static const unsigned int SectorTable_43xx[] =
111 | {
112 | 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192,
113 | 65536, 65536, 65536, 65536, 65536, 65536, 65536
114 | };
115 |
116 | // Used for LPC8xx devices
117 | static const unsigned int SectorTable_8xx[] =
118 | {
119 | 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024,
120 | 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024
121 | };
122 |
123 | static int unsigned SectorTable_RAM[] = { 65000 };
124 |
125 | static LPC_DEVICE_TYPE LPCtypes[] =
126 | {
127 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, CHIP_VARIANT_NONE }, /* unknown */
128 |
129 | // id, id2, use id2, name of product, flash size, ram size, total number of sector, max copy size, sector table, chip variant
130 |
131 | { 0x00008100, 0x00000000, 0, "810M021FN8", 4, 1, 4, 256, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
132 | { 0x00008110, 0x00000000, 0, "811M001FDH16", 8, 2, 8, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
133 | { 0x00008120, 0x00000000, 0, "812M101FDH16", 16, 4, 16, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
134 | { 0x00008121, 0x00000000, 0, "812M101FD20", 16, 4, 16, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
135 | { 0x00008122, 0x00000000, 0, "812M101FDH20", 16, 4, 16, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
136 |
137 | { 0x00008241, 0x00000000, 0, "824M201JHI33", 32, 8, 32, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
138 | { 0x00008221, 0x00000000, 0, "822M101JHI33", 16, 4, 16, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
139 | { 0x00008242, 0x00000000, 0, "824M201JDH20", 32, 8, 32, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
140 | { 0x00008222, 0x00000000, 0, "822M101JDH20", 16, 4, 16, 1024, SectorTable_8xx, CHIP_VARIANT_LPC8XX },
141 |
142 | { 0x2500102B, 0x00000000, 0, "1102", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
143 |
144 | { 0x0A07102B, 0x00000000, 0, "1110.../002", 4, 1, 1, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
145 | { 0x1A07102B, 0x00000000, 0, "1110.../002", 4, 1, 1, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
146 | { 0x0A16D02B, 0x00000000, 0, "1111.../002", 8, 2, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
147 | { 0x1A16D02B, 0x00000000, 0, "1111.../002", 8, 2, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
148 | { 0x041E502B, 0x00000000, 0, "1111.../101", 8, 2, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
149 | { 0x2516D02B, 0x00000000, 0, "1111.../102", 8, 2, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
150 | { 0x00010013, 0x00000000, 0, "1111.../103", 8, 2, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
151 | { 0x0416502B, 0x00000000, 0, "1111.../201", 8, 4, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
152 | { 0x2516902B, 0x00000000, 0, "1111.../202", 8, 4, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
153 | { 0x00010012, 0x00000000, 0, "1111.../203", 8, 4, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
154 | { 0x042D502B, 0x00000000, 0, "1112.../101", 16, 2, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
155 | { 0x2524D02B, 0x00000000, 0, "1112.../102", 16, 2, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
156 | { 0x0A24902B, 0x00000000, 0, "1112.../102", 16, 4, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
157 | { 0x1A24902B, 0x00000000, 0, "1112.../102", 16, 4, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
158 | { 0x00020023, 0x00000000, 0, "1112.../103", 16, 2, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
159 | { 0x0425502B, 0x00000000, 0, "1112.../201", 16, 4, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
160 | { 0x2524902B, 0x00000000, 0, "1112.../202", 16, 4, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
161 | { 0x00020022, 0x00000000, 0, "1112.../203", 16, 4, 4, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
162 | { 0x0434502B, 0x00000000, 0, "1113.../201", 24, 4, 6, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
163 | { 0x2532902B, 0x00000000, 0, "1113.../202", 24, 4, 6, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
164 | { 0x00030032, 0x00000000, 0, "1113.../203", 24, 4, 6, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
165 | { 0x0434102B, 0x00000000, 0, "1113.../301", 24, 8, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
166 | { 0x2532102B, 0x00000000, 0, "1113.../302", 24, 8, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
167 | { 0x00030030, 0x00000000, 0, "1113.../303", 24, 8, 6, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
168 | { 0x0A40902B, 0x00000000, 0, "1114.../102", 32, 4, 8, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
169 | { 0x1A40902B, 0x00000000, 0, "1114.../102", 32, 4, 8, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
170 | { 0x0444502B, 0x00000000, 0, "1114.../201", 32, 4, 8, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
171 | { 0x2540902B, 0x00000000, 0, "1114.../202", 32, 4, 8, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
172 | { 0x00040042, 0x00000000, 0, "1114.../203", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
173 | { 0x0444102B, 0x00000000, 0, "1114.../301", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
174 | { 0x2540102B, 0x00000000, 0, "1114.../302", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
175 | { 0x00040040, 0x00000000, 0, "1114.../303", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
176 | { 0x00040060, 0x00000000, 0, "1114.../323", 32, 8, 12, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
177 | { 0x00040070, 0x00000000, 0, "1114.../333", 32, 8, 14, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
178 | { 0x00050080, 0x00000000, 0, "1115.../303", 64, 8, 16, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
179 |
180 | { 0x1421102B, 0x00000000, 0, "11C12.../301", 16, 8, 4, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
181 | { 0x1440102B, 0x00000000, 0, "11C14.../301", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
182 | { 0x1431102B, 0x00000000, 0, "11C22.../301", 16, 8, 4, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
183 | { 0x1430102B, 0x00000000, 0, "11C24.../301", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX },
184 |
185 | { 0x293E902B, 0x00000000, 0, "11E11FHN33/101", 8, 4, 2, 1024, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
186 | { 0x2954502B, 0x00000000, 0, "11E12FBD48/201", 16, 6, 4, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
187 | { 0x296A102B, 0x00000000, 0, "11E13FBD48/301", 24, 8, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
188 | { 0x2980102B, 0x00000000, 0, "11E14(FHN33,FBD48,FBD64)/401", 32, 10, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
189 | { 0x00009C41, 0x00000000, 0, "11E36(FBD64,FHN33)/501", 96, 12, 24, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
190 | { 0x00007C45, 0x00000000, 0, "11E37HFBD64/401", 128, 10, 32, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
191 | { 0x00007C41, 0x00000000, 0, "11E37(FBD48,FBD64)/501", 128, 12, 32, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10518 Rev. 3 -- 25 Nov 2013 */
192 |
193 | { 0x095C802B, 0x00000000, 0, "11U12(FHN33,FBD48)/201", 16, 6, 4, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
194 | { 0x295C802B, 0x00000000, 0, "11U12(FHN33,FBD48)/201", 16, 6, 4, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
195 | { 0x097A802B, 0x00000000, 0, "11U13FBD48/201", 24, 6, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
196 | { 0x297A802B, 0x00000000, 0, "11U13FBD48/201", 24, 6, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
197 | { 0x0998802B, 0x00000000, 0, "11U14FHN33/201", 32, 6, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
198 | { 0x2998802B, 0x00000000, 0, "11U14(FHN,FHI)33/201", 32, 6, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
199 | { 0x0998802B, 0x00000000, 0, "11U14(FBD,FET)48/201", 32, 6, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
200 | { 0x2998802B, 0x00000000, 0, "11U14(FBD,FET)48/201", 32, 6, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
201 | { 0x2972402B, 0x00000000, 0, "11U23FBD48/301", 24, 8, 6, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
202 | { 0x2988402B, 0x00000000, 0, "11U24(FHI33,FBD48,FET48)/301", 32, 8, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
203 | { 0x2980002B, 0x00000000, 0, "11U24(FHN33,FBD48,FBD64)/401", 32, 10, 8, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
204 | { 0x0003D440, 0x00000000, 0, "11U34(FHN33,FBD48)/311", 40, 8, 10, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
205 | { 0x0001CC40, 0x00000000, 0, "11U34(FHN33,FBD48)/421", 48, 10, 12, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
206 | { 0x0001BC40, 0x00000000, 0, "11U35(FHN33,FBD48,FBD64)/401", 64, 10, 16, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
207 | { 0x0000BC40, 0x00000000, 0, "11U35(FHI33,FET48)/501", 64, 12, 16, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
208 | { 0x00019C40, 0x00000000, 0, "11U36(FBD48,FBD64)/401", 96, 10, 24, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
209 | { 0x00017C40, 0x00000000, 0, "11U37FBD48/401", 128, 10, 32, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
210 | { 0x00007C44, 0x00000000, 0, "11U37HFBD64/401", 128, 10, 32, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
211 | { 0x00007C40, 0x00000000, 0, "11U37FBD64/501", 128, 12, 32, 4096, SectorTable_11xx, CHIP_VARIANT_LPC11XX }, /* From UM10462 Rev. 5 -- 20 Nov 2013 */
212 |
213 | { 0x3640C02B, 0x00000000, 0, "1224.../101", 32, 8, 4, 2048, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
214 | { 0x3642C02B, 0x00000000, 0, "1224.../121", 48, 12, 32, 4096, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
215 | { 0x3650002B, 0x00000000, 0, "1225.../301", 64, 16, 32, 4096, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
216 | { 0x3652002B, 0x00000000, 0, "1225.../321", 80, 20, 32, 4096, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
217 | { 0x3660002B, 0x00000000, 0, "1226", 96, 24, 32, 4096, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
218 | { 0x3670002B, 0x00000000, 0, "1227", 128, 32, 32, 4096, SectorTable_17xx, CHIP_VARIANT_LPC11XX },
219 |
220 | { 0x2C42502B, 0x00000000, 0, "1311", 8, 4, 2, 1024, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
221 | { 0x1816902B, 0x00000000, 0, "1311/01", 8, 4, 2, 1024, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
222 | { 0x2C40102B, 0x00000000, 0, "1313", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
223 | { 0x1830102B, 0x00000000, 0, "1313/01", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
224 | { 0x3A010523, 0x00000000, 0, "1315", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
225 | { 0x1A018524, 0x00000000, 0, "1316", 48, 8, 12, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
226 | { 0x1A020525, 0x00000000, 0, "1317", 64, 8, 16, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
227 | { 0x3D01402B, 0x00000000, 0, "1342", 16, 4, 4, 1024, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
228 | { 0x3D00002B, 0x00000000, 0, "1343", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
229 | { 0x28010541, 0x00000000, 0, "1345", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
230 | { 0x08018542, 0x00000000, 0, "1346", 48, 8, 12, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
231 | { 0x08020543, 0x00000000, 0, "1347", 64, 8, 16, 4096, SectorTable_17xx, CHIP_VARIANT_LPC13XX },
232 |
233 | { 0x25001118, 0x00000000, 0, "1751", 32, 8, 8, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
234 | { 0x25001121, 0x00000000, 0, "1752", 64, 16, 16, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
235 | { 0x25011722, 0x00000000, 0, "1754", 128, 32, 18, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
236 | { 0x25011723, 0x00000000, 0, "1756", 256, 32, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
237 | { 0x25013F37, 0x00000000, 0, "1758", 512, 64, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
238 | { 0x25113737, 0x00000000, 0, "1759", 512, 64, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
239 | { 0x26012033, 0x00000000, 0, "1763", 256, 64, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
240 | { 0x26011922, 0x00000000, 0, "1764", 128, 32, 18, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
241 | { 0x26013733, 0x00000000, 0, "1765", 256, 64, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
242 | { 0x26013F33, 0x00000000, 0, "1766", 256, 64, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
243 | { 0x26012837, 0x00000000, 0, "1767", 512, 64, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
244 | { 0x26013F37, 0x00000000, 0, "1768", 512, 64, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
245 | { 0x26113F37, 0x00000000, 0, "1769", 512, 64, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
246 |
247 | { 0x27011132, 0x00000000, 0, "1774", 128, 40, 18, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
248 | { 0x27191F43, 0x00000000, 0, "1776", 256, 80, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
249 | { 0x27193747, 0x00000000, 0, "1777", 512, 96, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
250 | { 0x27193F47, 0x00000000, 0, "1778", 512, 96, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
251 | { 0x281D1743, 0x00000000, 0, "1785", 256, 80, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
252 | { 0x281D1F43, 0x00000000, 0, "1786", 256, 80, 22, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
253 | { 0x281D3747, 0x00000000, 0, "1787", 512, 96, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
254 | { 0x281D3F47, 0x00000000, 0, "1788", 512, 96, 30, 4096, SectorTable_17xx, CHIP_VARIANT_LPC17XX },
255 |
256 | // LPC18xx
257 | { 0xF00B1B3F, 0x00000000, 1, "1810", 0, 32, 0, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX }, // Flashless
258 | { 0xF001D830, 0x00000000, 1, "1812", 512, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
259 | { 0xF001D830, 0x00000000, 1, "1813", 512, 32, 11, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
260 | { 0xF001D830, 0x00000000, 1, "1815", 768, 32, 13, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
261 | { 0xF001D830, 0x00000000, 1, "1817", 1024, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
262 | { 0xF00A9B3C, 0x00000000, 1, "1820", 0, 32, 0, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX }, // Flashless
263 | { 0xF001D830, 0x00000000, 1, "1822", 512, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
264 | { 0xF001D830, 0x00000000, 1, "1823", 512, 32, 11, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
265 | { 0xF001D830, 0x00000000, 1, "1825", 768, 32, 13, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
266 | { 0xF001D830, 0x00000000, 1, "1827", 1024, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
267 | { 0xF0009A30, 0x00000000, 1, "1830", 0, 32, 0, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX }, // Flashless
268 | { 0xF001DA30, 0x00000044, 1, "1833", 512, 32, 11, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
269 | { 0xF001DA30, 0x00000000, 1, "1837", 1024, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
270 | { 0xF0009830, 0x00000000, 1, "1850", 0, 32, 0, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX }, // Flashless
271 | { 0xF001D830, 0x00000044, 1, "1853", 512, 32, 11, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
272 | { 0xF001D830, 0x00000000, 1, "1857", 1024, 32, 15, 8192, SectorTable_18xx, CHIP_VARIANT_LPC18XX },
273 |
274 | { 0x0004FF11, 0x00000000, 0, "2103", 32, 8, 8, 4096, SectorTable_2103, CHIP_VARIANT_LPC2XXX },
275 | { 0xFFF0FF12, 0x00000000, 0, "2104", 128, 16, 15, 8192, SectorTable_210x, CHIP_VARIANT_LPC2XXX },
276 | { 0xFFF0FF22, 0x00000000, 0, "2105", 128, 32, 15, 8192, SectorTable_210x, CHIP_VARIANT_LPC2XXX },
277 | { 0xFFF0FF32, 0x00000000, 0, "2106", 128, 64, 15, 8192, SectorTable_210x, CHIP_VARIANT_LPC2XXX },
278 | { 0x0201FF01, 0x00000000, 0, "2109", 64, 8, 8, 4096, SectorTable_2109, CHIP_VARIANT_LPC2XXX },
279 | { 0x0101FF12, 0x00000000, 0, "2114", 128, 16, 15, 8192, SectorTable_211x, CHIP_VARIANT_LPC2XXX },
280 | { 0x0201FF12, 0x00000000, 0, "2119", 128, 16, 15, 8192, SectorTable_211x, CHIP_VARIANT_LPC2XXX },
281 | { 0x0101FF13, 0x00000000, 0, "2124", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
282 | { 0x0201FF13, 0x00000000, 0, "2129", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
283 | { 0x0002FF01, 0x00000000, 0, "2131", 32, 8, 8, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
284 | { 0x0002FF11, 0x00000000, 0, "2132", 64, 16, 9, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
285 | { 0x0002FF12, 0x00000000, 0, "2134", 128, 16, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
286 | { 0x0002FF23, 0x00000000, 0, "2136", 256, 32, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
287 | { 0x0002FF25, 0x00000000, 0, "2138", 512, 32, 27, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
288 | { 0x0402FF01, 0x00000000, 0, "2141", 32, 8, 8, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
289 | { 0x0402FF11, 0x00000000, 0, "2142", 64, 16, 9, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
290 | { 0x0402FF12, 0x00000000, 0, "2144", 128, 16, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
291 | { 0x0402FF23, 0x00000000, 0, "2146", 256, 40, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
292 | { 0x0402FF25, 0x00000000, 0, "2148", 512, 40, 27, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
293 | { 0x0301FF13, 0x00000000, 0, "2194", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
294 | { 0x0301FF12, 0x00000000, 0, "2210", 0, 16, 0, 8192, SectorTable_211x, CHIP_VARIANT_LPC2XXX }, /* table is a "don't care" */
295 | { 0x0401FF12, 0x00000000, 0, "2212", 128, 16, 15, 8192, SectorTable_211x, CHIP_VARIANT_LPC2XXX },
296 | { 0x0601FF13, 0x00000000, 0, "2214", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
297 | /* "2290"; same id as the LPC2210 */
298 | { 0x0401FF13, 0x00000000, 0, "2292", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
299 | { 0x0501FF13, 0x00000000, 0, "2294", 256, 16, 17, 8192, SectorTable_212x, CHIP_VARIANT_LPC2XXX },
300 | { 0x1600F701, 0x00000000, 0, "2361", 128, 34, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 4.1 -- 5 Sep 2012 */
301 | { 0x1600FF22, 0x00000000, 0, "2362", 128, 34, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 4.1 -- 5 Sep 2012 */
302 | { 0x0603FB02, 0x00000000, 0, "2364", 128, 34, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 01 -- 6 July 2007 */
303 | { 0x1600F902, 0x00000000, 0, "2364", 128, 34, 11, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
304 | { 0x1600E823, 0x00000000, 0, "2365", 256, 58, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
305 | { 0x0603FB23, 0x00000000, 0, "2366", 256, 58, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 01 -- 6 July 2007 */
306 | { 0x1600F923, 0x00000000, 0, "2366", 256, 58, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
307 | { 0x1600E825, 0x00000000, 0, "2367", 512, 58, 15, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
308 | { 0x0603FB25, 0x00000000, 0, "2368", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 01 -- 6 July 2007 */
309 | { 0x1600F925, 0x00000000, 0, "2368", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
310 | { 0x1700E825, 0x00000000, 0, "2377", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
311 | { 0x0703FF25, 0x00000000, 0, "2378", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 01 -- 6 July 2007 */
312 | { 0x1600FD25, 0x00000000, 0, "2378", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 01 -- 29 October 2007 */
313 | { 0x1700FD25, 0x00000000, 0, "2378", 512, 58, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
314 | { 0x1700FF35, 0x00000000, 0, "2387", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX }, /* From UM10211 Rev. 03 -- 25 August 2008 */
315 | { 0x1800F935, 0x00000000, 0, "2387", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
316 | { 0x1800FF35, 0x00000000, 0, "2388", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
317 | { 0x1500FF35, 0x00000000, 0, "2458", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
318 | { 0x1600FF30, 0x00000000, 0, "2460", 0, 98, 0, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
319 | { 0x1600FF35, 0x00000000, 0, "2468", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
320 | { 0x1701FF30, 0x00000000, 0, "2470", 0, 98, 0, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
321 | { 0x1701FF35, 0x00000000, 0, "2478", 512, 98, 28, 4096, SectorTable_213x, CHIP_VARIANT_LPC2XXX },
322 |
323 | { 0xA00A8B3F, 0x00000000, 1, "4310", 0, 168, 0, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
324 | { 0xA00BCB3F, 0x00000080, 1, "4312", 512, 104, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
325 | { 0xA00BCB3F, 0x00000044, 1, "4313", 512, 104, 11, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
326 | { 0xA001CB3F, 0x00000022, 1, "4315", 768, 136, 13, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
327 | { 0xA001CB3F, 0x00000000, 1, "4317", 1024, 136, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
328 | { 0xA0008B3C, 0x00000000, 1, "4320", 0, 200, 0, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
329 | { 0xA00BCB3C, 0x00000080, 1, "4322", 512, 104, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
330 | { 0xA00BCB3C, 0x00000044, 1, "4323", 512, 104, 11, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
331 | { 0xA001CB3C, 0x00000022, 1, "4325", 768, 136, 13, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
332 | { 0xA001CB3C, 0x00000000, 1, "4327", 1024, 136, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
333 | { 0xA0000A30, 0x00000000, 1, "4330", 0, 264, 0, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
334 | { 0xA001CA30, 0x00000044, 1, "4333", 512, 512, 11, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
335 | { 0xA001CA30, 0x00000000, 1, "4337", 1024, 512, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* info not yet available */
336 | { 0xA0000830, 0x00000000, 1, "4350", 0, 264, 0, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
337 | { 0xA001C830, 0x00000044, 1, "4353", 512, 512, 11, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX }, /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
338 | { 0xA001C830, 0x00000000, 1, "4357", 1024, 512, 15, 4096, SectorTable_43xx, CHIP_VARIANT_LPC43XX } /* From UM10503 Rev. 1.4 -- 3 Sep 2012 */
339 | };
340 |
341 | /***************************** NXP Download *********************************/
342 | /** Download the file from the internal memory image to the NXP microcontroller.
343 | * This function is visible from outside if COMPILE_FOR_LPC21
344 | */
345 |
346 | /***************************** FormatCommand ********************************/
347 | /** 2013-06-28 Torsten Lang, Uwe Schneider GmbH
348 | According to the various NXP user manuals the ISP bootloader commands should
349 | be terminated with , the echo and/or answer should have the same line
350 | termination. So far for the theory...
351 | In fact, the bootloader also accepts as line termination, but it may or
352 | may not echo the linebreak character. Some bootloaders convert the character
353 | into , some leave the and append another one ( in the
354 | answer). Furthermore, during uuencoded data transfer the bootloader may or
355 | may not append an additional character at the end of the answer
356 | (leading to a sequence).
357 | A reliable way to handle these deviations from the UM is to strictly send the
358 | commands according to the description in the UM and to re-format commands
359 | and answers after a transfer.
360 | FormatCommand works in a way that it drops any leading linefeeds which only
361 | can be surplus characters from a previous answer. It then converts any
362 | sequence of and into a single character.
363 | FormatCommand can work in place, meaning that In==Out is allowed!
364 | \param [in] In Pointer to input buffer.
365 | \param [out] Out Pointer to output buffer.
366 | */
367 |
368 | static void FormatCommand(const char *In, char *Out)
369 | {
370 | size_t i, j;
371 | for (i = 0, j = 0; In[j] != '\0'; i++, j++)
372 | {
373 | if ((In[j] == '\r') || (In[j] == '\n'))
374 | {
375 | if (i > 0) // Ignore leading line breaks (they must be leftovers from a previous answer)
376 | {
377 | Out[i] = '\n';
378 | }
379 | else
380 | {
381 | i--;
382 | }
383 | while ((In[j+1] == '\r') || (In[j+1] == '\n'))
384 | {
385 | j++;
386 | }
387 | }
388 | else
389 | {
390 | Out[i] = In[j];
391 | }
392 | }
393 | Out[i] = '\0';
394 | }
395 |
396 | static int SendAndVerify(ISP_ENVIRONMENT *IspEnvironment, const char *Command,
397 | char *AnswerBuffer, int AnswerLength)
398 | {
399 | unsigned long realsize;
400 | int cmdlen;
401 | char *FormattedCommand;
402 |
403 | SendComPort(IspEnvironment, Command);
404 | ReceiveComPort(IspEnvironment, AnswerBuffer, AnswerLength - 1, &realsize, 2, 5000);
405 |
406 | cmdlen = strlen(Command);
407 | FormattedCommand = (char *)alloca(cmdlen+1);
408 | FormatCommand(Command, FormattedCommand);
409 | FormatCommand(AnswerBuffer, AnswerBuffer);
410 | cmdlen = strlen(FormattedCommand);
411 | return (strncmp(AnswerBuffer, FormattedCommand, cmdlen) == 0
412 | && strcmp(AnswerBuffer + cmdlen, "0\n") == 0);
413 | }
414 |
415 |
416 |
417 | /***************************** NxpOutputErrorMessage ***********************/
418 | /** Given an error number find and print the appropriate error message.
419 | \param [in] ErrorNumber The number of the error.
420 | */
421 | #if defined COMPILE_FOR_LPC21
422 |
423 | #define NxpOutputErrorMessage(in) // Cleanly remove this feature from the embedded version !!
424 |
425 | #else
426 |
427 | static void NxpOutputErrorMessage(unsigned char ErrorNumber)
428 | {
429 | switch (ErrorNumber)
430 | {
431 | case 0:
432 | DebugPrintf(1, "CMD_SUCCESS\n");
433 | break;
434 |
435 | case 1:
436 | DebugPrintf(1, "INVALID_COMMAND\n");
437 | break;
438 |
439 | case 2:
440 | DebugPrintf(1, "SRC_ADDR_ERROR: Source address is not on word boundary.\n");
441 | break;
442 |
443 | case 3:
444 | DebugPrintf(1, "DST_ADDR_ERROR: Destination address is not on a correct boundary.\n");
445 | break;
446 |
447 | case 4:
448 | DebugPrintf(1, "SRC_ADDR_NOT_MAPPED: Source address is not mapped in the memory map.\n"
449 | " Count value is taken into consideration where applicable.\n");
450 | break;
451 |
452 | case 5:
453 | DebugPrintf(1, "DST_ADDR_NOT_MAPPED: Destination address is not mapped in the memory map.\n"
454 | " Count value is taken into consideration where applicable.\n");
455 | break;
456 |
457 | case 6:
458 | DebugPrintf(1, "COUNT_ERROR: Byte count is not multiple of 4 or is not a permitted value.\n");
459 | break;
460 |
461 | case 7:
462 | DebugPrintf(1, "INVALID_SECTOR: Sector number is invalid or end sector number is\n"
463 | " greater than start sector number.\n");
464 | break;
465 |
466 | case 8:
467 | DebugPrintf(1, "SECTOR_NOT_BLANK\n");
468 | break;
469 |
470 | case 9:
471 | DebugPrintf(1, "SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION:\n"
472 | "Command to prepare sector for write operation was not executed.\n");
473 | break;
474 |
475 | case 10:
476 | DebugPrintf(1, "COMPARE_ERROR: Source and destination data not equal.\n");
477 | break;
478 |
479 | case 11:
480 | DebugPrintf(1, "BUSY: Flash programming hardware interface is busy.\n");
481 | break;
482 |
483 | case 12:
484 | DebugPrintf(1, "PARAM_ERROR: Insufficient number of parameters or invalid parameter.\n");
485 | break;
486 |
487 | case 13:
488 | DebugPrintf(1, "ADDR_ERROR: Address is not on word boundary.\n");
489 | break;
490 |
491 | case 14:
492 | DebugPrintf(1, "ADDR_NOT_MAPPED: Address is not mapped in the memory map.\n"
493 | " Count value is taken in to consideration where applicable.\n");
494 | break;
495 |
496 | case 15:
497 | DebugPrintf(1, "CMD_LOCKED\n");
498 | break;
499 |
500 | case 16:
501 | DebugPrintf(1, "INVALID_CODE: Unlock code is invalid.\n");
502 | break;
503 |
504 | case 17:
505 | DebugPrintf(1, "INVALID_BAUD_RATE: Invalid baud rate setting.\n");
506 | break;
507 |
508 | case 18:
509 | DebugPrintf(1, "INVALID_STOP_BIT: Invalid stop bit setting.\n");
510 | break;
511 |
512 | case 19:
513 | DebugPrintf( 1, "CODE READ PROTECTION ENABLED\n");
514 | break;
515 |
516 | case 255:
517 | break;
518 |
519 | default:
520 | DebugPrintf(1, "unknown error %u\n", ErrorNumber);
521 | break;
522 | }
523 |
524 | //DebugPrintf(1, "error (%u), see NxpOutputErrorMessage() in lpc21isp.c for help \n\r", ErrorNumber);
525 | }
526 | #endif // !defined COMPILE_FOR_LPC21
527 |
528 | /***************************** GetAndReportErrorNumber ***************************/
529 | /** Find error number in string. This will normally be the string
530 | returned from the microcontroller.
531 | \param [in] Answer the buffer to search for the error number.
532 | \return the error number found, if no linefeed found before the end of the
533 | string an error value of 255 is returned. If a non-numeric value is found
534 | then it is printed to stdout and an error value of 255 is returned.
535 | */
536 | static unsigned char GetAndReportErrorNumber(const char *Answer)
537 | {
538 | unsigned char Result = 0xFF; // Error !!!
539 | unsigned int i = 0;
540 |
541 | while (1)
542 | {
543 | if (Answer[i] == 0x00)
544 | {
545 | break;
546 | }
547 |
548 | if (Answer[i] == 0x0a)
549 | {
550 | i++;
551 |
552 | if (Answer[i] < '0' || Answer[i] > '9')
553 | {
554 | DebugPrintf(1, "ErrorString: %s", &Answer[i]);
555 | break;
556 | }
557 |
558 | Result = (unsigned char) (atoi(&Answer[i]));
559 | break;
560 | }
561 |
562 | i++;
563 | }
564 |
565 | NxpOutputErrorMessage(Result);
566 |
567 | return Result;
568 | }
569 |
570 |
571 | int NxpDownload(ISP_ENVIRONMENT *IspEnvironment)
572 | {
573 | unsigned long realsize;
574 | char Answer[128];
575 | char ExpectedAnswer[128];
576 | char temp[128];
577 | /*const*/ char *strippedAnswer, *endPtr;
578 | int strippedsize;
579 | int nQuestionMarks;
580 | int found;
581 | unsigned long Sector;
582 | unsigned long SectorLength;
583 | unsigned long SectorStart, SectorOffset, SectorChunk;
584 | char tmpString[128];
585 | char uuencode_table[64];
586 | int Line;
587 | unsigned long tmpStringPos;
588 | unsigned long BlockOffset;
589 | unsigned long Block;
590 | unsigned long Pos;
591 | unsigned long Id[2];
592 | unsigned long Id1Masked;
593 | unsigned long CopyLength;
594 | int c,k=0,i;
595 | unsigned long ivt_CRC; // CRC over interrupt vector table
596 | unsigned long block_CRC;
597 | time_t tStartUpload=0, tDoneUpload=0;
598 | char tmp_string[64];
599 | char * cmdstr;
600 |
601 | #if !defined COMPILE_FOR_LPC21
602 |
603 | #if defined __BORLANDC__
604 | #define local_static static
605 | #else
606 | #define local_static
607 | #endif
608 |
609 | // char * cmdstr;
610 | int repeat = 0;
611 | // Puffer for data to resend after "RESEND\r\n" Target responce
612 | local_static char sendbuf0[128];
613 | local_static char sendbuf1[128];
614 | local_static char sendbuf2[128];
615 | local_static char sendbuf3[128];
616 | local_static char sendbuf4[128];
617 | local_static char sendbuf5[128];
618 | local_static char sendbuf6[128];
619 | local_static char sendbuf7[128];
620 | local_static char sendbuf8[128];
621 | local_static char sendbuf9[128];
622 | local_static char sendbuf10[128];
623 | local_static char sendbuf11[128];
624 | local_static char sendbuf12[128];
625 | local_static char sendbuf13[128];
626 | local_static char sendbuf14[128];
627 | local_static char sendbuf15[128];
628 | local_static char sendbuf16[128];
629 | local_static char sendbuf17[128];
630 | local_static char sendbuf18[128];
631 | local_static char sendbuf19[128];
632 |
633 | char * sendbuf[20] = { sendbuf0, sendbuf1, sendbuf2, sendbuf3, sendbuf4,
634 | sendbuf5, sendbuf6, sendbuf7, sendbuf8, sendbuf9,
635 | sendbuf10, sendbuf11, sendbuf12, sendbuf13, sendbuf14,
636 | sendbuf15, sendbuf16, sendbuf17, sendbuf18, sendbuf19};
637 | #endif
638 |
639 | DebugPrintf(2, "Synchronizing (ESC to abort)");
640 |
641 | PrepareKeyboardTtySettings();
642 |
643 | #if defined INTEGRATED_IN_WIN_APP
644 | if (IspEnvironment->NoSync)
645 | {
646 | found = 1;
647 | }
648 | else
649 | #endif
650 | {
651 | for (nQuestionMarks = found = 0; !found && nQuestionMarks < IspEnvironment->nQuestionMarks; nQuestionMarks++)
652 | {
653 | #if defined INTEGRATED_IN_WIN_APP
654 | // allow calling application to abort when syncing takes too long
655 |
656 | if (!AppSyncing(nQuestionMarks))
657 | {
658 | return (USER_ABORT_SYNC);
659 | }
660 | #else
661 | #ifndef Exclude_kbhit
662 | if (kbhit())
663 | {
664 | if (getch() == 0x1b)
665 | {
666 | ResetKeyboardTtySettings();
667 | DebugPrintf(2, "\nUser aborted during synchronisation\n");
668 | return (USER_ABORT_SYNC);
669 | }
670 | }
671 | #endif
672 | #endif
673 |
674 | DebugPrintf(2, ".");
675 | SendComPort(IspEnvironment, "?");
676 |
677 | memset(Answer,0,sizeof(Answer));
678 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 1,100);
679 |
680 | strippedAnswer = Answer;
681 | strippedsize = realsize;
682 | while ((strippedsize > 0) && ((*strippedAnswer == '?') || (*strippedAnswer == 0)))
683 | {
684 | strippedAnswer++;
685 | strippedsize--;
686 | }
687 |
688 | sprintf(tmp_string, "StrippedAnswer(Length=%d): ", strippedsize);
689 | DumpString(3, strippedAnswer, strippedsize, tmp_string);
690 |
691 | tStartUpload = time(NULL);
692 |
693 | FormatCommand(strippedAnswer, strippedAnswer);
694 | if (strcmp(strippedAnswer, "Synchronized\n") == 0)
695 | {
696 | found = 1;
697 | }
698 | #if !defined COMPILE_FOR_LPC21
699 | else
700 | {
701 | ResetTarget(IspEnvironment, PROGRAM_MODE);
702 | }
703 | #endif
704 | }
705 | }
706 |
707 | ResetKeyboardTtySettings();
708 |
709 | if (!found)
710 | {
711 | DebugPrintf(1, " no answer on '?'\n");
712 | return (NO_ANSWER_QM);
713 | }
714 |
715 | #if defined INTEGRATED_IN_WIN_APP
716 | AppSyncing(-1); // flag syncing done
717 | #endif
718 |
719 | DebugPrintf(2, " OK\n");
720 |
721 | SendComPort(IspEnvironment, "Synchronized\r\n");
722 |
723 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer) - 1, &realsize, 2, 1000);
724 |
725 | FormatCommand(Answer, Answer);
726 | if (strcmp(Answer, "Synchronized\nOK\n") != 0)
727 | {
728 | DebugPrintf(1, "No answer on 'Synchronized'\n");
729 | return (NO_ANSWER_SYNC);
730 | }
731 |
732 | DebugPrintf(3, "Synchronized 1\n");
733 |
734 | DebugPrintf(3, "Setting oscillator\n");
735 |
736 | sprintf(temp, "%s\r\n", IspEnvironment->StringOscillator);
737 |
738 | SendComPort(IspEnvironment, temp);
739 |
740 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2, 1000);
741 |
742 | sprintf(temp, "%s\nOK\n", IspEnvironment->StringOscillator);
743 |
744 | FormatCommand(Answer, Answer);
745 | if (strcmp(Answer, temp) != 0)
746 | {
747 | DebugPrintf(1, "No answer on Oscillator-Command\n");
748 | return (NO_ANSWER_OSC);
749 | }
750 |
751 | DebugPrintf(3, "Unlock\n");
752 |
753 | cmdstr = "U 23130\r\n";
754 |
755 | if (!SendAndVerify(IspEnvironment, cmdstr, Answer, sizeof Answer))
756 | {
757 | DebugPrintf(1, "Unlock-Command:\n");
758 | return (UNLOCK_ERROR + GetAndReportErrorNumber(Answer));
759 | }
760 |
761 | DebugPrintf(2, "Read bootcode version: ");
762 |
763 | cmdstr = "K\r\n";
764 |
765 | SendComPort(IspEnvironment, cmdstr);
766 |
767 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 4,5000);
768 |
769 | FormatCommand(cmdstr, temp);
770 | FormatCommand(Answer, Answer);
771 | if (strncmp(Answer, temp, strlen(temp)) != 0)
772 | {
773 | DebugPrintf(1, "no answer on Read Boot Code Version\n");
774 | return (NO_ANSWER_RBV);
775 | }
776 |
777 | if (strncmp(Answer + strlen(temp), "0\n", 2) == 0)
778 | {
779 | strippedAnswer = Answer + strlen(temp) + 2;
780 | /*
781 | int maj, min, build;
782 | if (sscanf(strippedAnswer, "%d %d %d", &build, &min, &maj) == 2) {
783 | maj = min;
784 | min = build;
785 | build = 0;
786 | } // if
787 | DebugPrintf(2, "%d.%d.%d\n", maj, min, build);
788 | */
789 | DebugPrintf(2, strippedAnswer);
790 | }
791 | else
792 | {
793 | DebugPrintf(2, "unknown\n");
794 | }
795 |
796 | DebugPrintf(2, "Read part ID: ");
797 |
798 | cmdstr = "J\r\n";
799 |
800 | SendComPort(IspEnvironment, cmdstr);
801 |
802 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 3, 5000);
803 |
804 | FormatCommand(cmdstr, temp);
805 | FormatCommand(Answer, Answer);
806 | if (strncmp(Answer, temp, strlen(temp)) != 0)
807 | {
808 | DebugPrintf(1, "no answer on Read Part Id\n");
809 | return (NO_ANSWER_RPID);
810 | }
811 |
812 | strippedAnswer = (strncmp(Answer, "J\n0\n", 4) == 0) ? Answer + 4 : Answer;
813 |
814 | Id[0] = strtoul(strippedAnswer, &endPtr, 10);
815 | Id[1] = 0UL;
816 | *endPtr = '\0'; /* delete \r\n */
817 | for (i = sizeof LPCtypes / sizeof LPCtypes[0] - 1; i > 0 && LPCtypes[i].id != Id[0]; i--)
818 | /* nothing */;
819 | IspEnvironment->DetectedDevice = i;
820 | if (LPCtypes[IspEnvironment->DetectedDevice].EvalId2 != 0)
821 | {
822 | /* Read out the second configuration word and run the search again */
823 | *endPtr = '\n';
824 | endPtr++;
825 | if ((endPtr[0] == '\0') || (endPtr[strlen(endPtr)-1] != '\n'))
826 | {
827 | /* No or incomplete word 2 */
828 | ReceiveComPort(IspEnvironment, endPtr, sizeof(Answer)-(endPtr-Answer)-1, &realsize, 1, 100);
829 | }
830 |
831 | FormatCommand(endPtr, endPtr);
832 | if ((*endPtr == '\0') || (*endPtr == '\n'))
833 | {
834 | DebugPrintf(1, "incomplete answer on Read Part Id (second configuration word missing)\n");
835 | return (NO_ANSWER_RPID);
836 | }
837 |
838 | Id[1] = strtoul(endPtr, &endPtr, 10);
839 | *endPtr = '\0'; /* delete \r\n */
840 |
841 | Id1Masked = Id[1] & 0xFF;
842 |
843 | /* now search the table again */
844 | for (i = sizeof LPCtypes / sizeof LPCtypes[0] - 1; i > 0 && (LPCtypes[i].id != Id[0] || LPCtypes[i].id2 != Id1Masked); i--)
845 | /* nothing */;
846 | IspEnvironment->DetectedDevice = i;
847 | }
848 | if (IspEnvironment->DetectedDevice == 0) {
849 | DebugPrintf(2, "unknown");
850 | }
851 | else {
852 | DebugPrintf(2, "LPC%s, %d kiB FLASH / %d kiB SRAM",
853 | LPCtypes[IspEnvironment->DetectedDevice].Product,
854 | LPCtypes[IspEnvironment->DetectedDevice].FlashSize,
855 | LPCtypes[IspEnvironment->DetectedDevice].RAMSize);
856 | }
857 | if (LPCtypes[IspEnvironment->DetectedDevice].EvalId2 != 0)
858 | {
859 | DebugPrintf(2, " (0x%08lX / 0x%08lX -> %08lX)\n", Id[0], Id[1], Id1Masked);
860 | }
861 | else
862 | {
863 | DebugPrintf(2, " (0x%08lX)\n", Id[0]);
864 | }
865 |
866 | if (!IspEnvironment->DetectOnly)
867 | {
868 | // Build up uuencode table
869 | uuencode_table[0] = 0x60; // 0x20 is translated to 0x60 !
870 |
871 | for (i = 1; i < 64; i++)
872 | {
873 | uuencode_table[i] = (char)(0x20 + i);
874 | }
875 |
876 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
877 | {
878 | // Patch 0x14, otherwise it is not running and jumps to boot mode
879 |
880 | ivt_CRC = 0;
881 |
882 | // Clear the vector at 0x14 so it doesn't affect the checksum:
883 | for (i = 0; i < 4; i++)
884 | {
885 | IspEnvironment->BinaryContent[i + 0x14] = 0;
886 | }
887 |
888 | // Calculate a native checksum of the little endian vector table:
889 | for (i = 0; i < (4 * 8);) {
890 | ivt_CRC += IspEnvironment->BinaryContent[i++];
891 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 8;
892 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 16;
893 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 24;
894 | }
895 |
896 | /* Negate the result and place in the vector at 0x14 as little endian
897 | * again. The resulting vector table should checksum to 0. */
898 | ivt_CRC = (unsigned long) (0 - ivt_CRC);
899 | for (i = 0; i < 4; i++)
900 | {
901 | IspEnvironment->BinaryContent[i + 0x14] = (unsigned char)(ivt_CRC >> (8 * i));
902 | }
903 |
904 | DebugPrintf(3, "Position 0x14 patched: ivt_CRC = 0x%08lX\n", ivt_CRC);
905 | }
906 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
907 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX ||
908 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
909 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
910 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX ||
911 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
912 | {
913 | // Patch 0x1C, otherwise it is not running and jumps to boot mode
914 |
915 | ivt_CRC = 0;
916 |
917 | // Clear the vector at 0x1C so it doesn't affect the checksum:
918 | for (i = 0; i < 4; i++)
919 | {
920 | IspEnvironment->BinaryContent[i + 0x1C] = 0;
921 | }
922 |
923 | // Calculate a native checksum of the little endian vector table:
924 | for (i = 0; i < (4 * 8);) {
925 | ivt_CRC += IspEnvironment->BinaryContent[i++];
926 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 8;
927 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 16;
928 | ivt_CRC += IspEnvironment->BinaryContent[i++] << 24;
929 | }
930 |
931 | /* Negate the result and place in the vector at 0x1C as little endian
932 | * again. The resulting vector table should checksum to 0. */
933 | ivt_CRC = (unsigned long) (0 - ivt_CRC);
934 | for (i = 0; i < 4; i++)
935 | {
936 | IspEnvironment->BinaryContent[i + 0x1C] = (unsigned char)(ivt_CRC >> (8 * i));
937 | }
938 |
939 | DebugPrintf(3, "Position 0x1C patched: ivt_CRC = 0x%08lX\n", ivt_CRC);
940 | }
941 | else
942 | {
943 | DebugPrintf(1, "Internal error: wrong chip variant %d (detected device %d)\n", LPCtypes[IspEnvironment->DetectedDevice].ChipVariant, IspEnvironment->DetectedDevice);
944 | exit(1);
945 | }
946 | }
947 |
948 | #if 0
949 | DebugPrintf(2, "Read Unique ID:\n");
950 |
951 | cmdstr = "N\r\n";
952 |
953 | SendComPort(IspEnvironment, cmdstr);
954 |
955 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 5,5000);
956 |
957 | FormatCommand(cmdstr, temp);
958 | FormatCommand(Answer, Answer);
959 | if (strncmp(Answer, temp, strlen(temp)) != 0)
960 | {
961 | DebugPrintf(1, "no answer on Read Unique ID\n");
962 | return (NO_ANSWER_RBV);
963 | }
964 |
965 | if (strncmp(Answer + strlen(cmdstr), "0\n", 2) == 0)
966 | {
967 | strippedAnswer = Answer + strlen(temp) + 2;
968 | DebugPrintf(2, strippedAnswer);
969 | }
970 | else
971 | {
972 | DebugPrintf(2, "unknown\n");
973 | }
974 | #endif // 0
975 |
976 | /* In case of a download to RAM, use full RAM for downloading
977 | * set the flash parameters to full RAM also.
978 | * This makes sure that all code is downloaded as one big sector
979 | */
980 |
981 | if ( (IspEnvironment->BinaryOffset >= ReturnValueLpcRamStart(IspEnvironment))
982 | &&(IspEnvironment->BinaryOffset + IspEnvironment->BinaryLength <= ReturnValueLpcRamStart(IspEnvironment)+(LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024)))
983 | {
984 | LPCtypes[IspEnvironment->DetectedDevice].FlashSectors = 1;
985 | LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize = LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024 - (ReturnValueLpcRamBase(IspEnvironment) - ReturnValueLpcRamStart(IspEnvironment));
986 | LPCtypes[IspEnvironment->DetectedDevice].SectorTable = SectorTable_RAM;
987 | SectorTable_RAM[0] = LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize;
988 | }
989 | if (IspEnvironment->DetectOnly)
990 | return (0);
991 |
992 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
993 | {
994 | // XON/XOFF must be switched off for LPC8XX
995 | // otherwise problem during binary transmission of data to LPC8XX
996 | DebugPrintf(3, "Switch off XON/XOFF !!!\n");
997 | ControlXonXoffSerialPort(IspEnvironment, 0);
998 | }
999 |
1000 | // Start with sector 1 and go upward... Sector 0 containing the interrupt vectors
1001 | // will be loaded last, since it contains a checksum and device will re-enter
1002 | // bootloader mode as long as this checksum is invalid.
1003 | DebugPrintf(2, "Will start programming at Sector 1 if possible, and conclude with Sector 0 to ensure that checksum is written last.\n");
1004 | if (LPCtypes[IspEnvironment->DetectedDevice].SectorTable[0] >= IspEnvironment->BinaryLength)
1005 | {
1006 | Sector = 0;
1007 | SectorStart = 0;
1008 | }
1009 | else
1010 | {
1011 | SectorStart = LPCtypes[IspEnvironment->DetectedDevice].SectorTable[0];
1012 | Sector = 1;
1013 | }
1014 |
1015 | if (IspEnvironment->WipeDevice == 1)
1016 | {
1017 | DebugPrintf(2, "Wiping Device. ");
1018 |
1019 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1020 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1021 | {
1022 | // TODO: Quick and dirty hack to address bank 0
1023 | sprintf(tmpString, "P %d %d 0\r\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
1024 | }
1025 | else
1026 | {
1027 | sprintf(tmpString, "P %d %d\r\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
1028 | }
1029 |
1030 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1031 | {
1032 | DebugPrintf(1, "Wrong answer on Prepare-Command\n");
1033 | return (WRONG_ANSWER_PREP + GetAndReportErrorNumber(Answer));
1034 | }
1035 |
1036 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1037 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1038 | {
1039 | // TODO: Quick and dirty hack to address bank 0
1040 | sprintf(tmpString, "E %d %d 0\r\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
1041 | }
1042 | else
1043 | {
1044 | sprintf(tmpString, "E %d %d\r\n", 0, LPCtypes[IspEnvironment->DetectedDevice].FlashSectors-1);
1045 | }
1046 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1047 | {
1048 | DebugPrintf(1, "Wrong answer on Erase-Command\n");
1049 | return (WRONG_ANSWER_ERAS + GetAndReportErrorNumber(Answer));
1050 | }
1051 | DebugPrintf(2, "OK \n");
1052 |
1053 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1054 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1055 | {
1056 | DebugPrintf(2, "ATTENTION: Only bank A was wiped!!!\n");
1057 | }
1058 | }
1059 | else{
1060 | //no wiping requested: erasing sector 0 first
1061 | DebugPrintf(2, "Erasing sector 0 first, to invalidate checksum. ");
1062 |
1063 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1064 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1065 | {
1066 | // TODO: Quick and dirty hack to address bank 0
1067 | sprintf(tmpString, "P %d %d 0\r\n", 0, 0);
1068 | }
1069 | else
1070 | {
1071 | sprintf(tmpString, "P %d %d\r\n", 0, 0);
1072 | }
1073 |
1074 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1075 | {
1076 | DebugPrintf(1, "Wrong answer on Prepare-Command\n");
1077 | return (WRONG_ANSWER_PREP + GetAndReportErrorNumber(Answer));
1078 | }
1079 |
1080 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1081 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1082 | {
1083 | // TODO: Quick and dirty hack to address bank 0
1084 | sprintf(tmpString, "E %d %d 0\r\n", 0, 0);
1085 | }
1086 | else
1087 | {
1088 | sprintf(tmpString, "E %d %d\r\n", 0, 0);
1089 | }
1090 |
1091 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1092 | {
1093 | DebugPrintf(1, "Wrong answer on Erase-Command\n");
1094 | return (WRONG_ANSWER_ERAS + GetAndReportErrorNumber(Answer));
1095 | }
1096 | DebugPrintf(2, "OK \n");
1097 | }
1098 | while (1)
1099 | {
1100 | if (Sector >= LPCtypes[IspEnvironment->DetectedDevice].FlashSectors)
1101 | {
1102 | DebugPrintf(1, "Program too large; running out of Flash sectors.\n");
1103 | return (PROGRAM_TOO_LARGE);
1104 | }
1105 |
1106 | DebugPrintf(2, "Sector %ld: ", Sector);
1107 | fflush(stdout);
1108 |
1109 | if ( (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment)) // Skip Erase when running from RAM
1110 | ||(IspEnvironment->BinaryOffset >= ReturnValueLpcRamStart(IspEnvironment)+(LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024)))
1111 | {
1112 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1113 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1114 | {
1115 | // TODO: Quick and dirty hack to address bank 0
1116 | sprintf(tmpString, "P %ld %ld 0\r\n", Sector, Sector);
1117 | }
1118 | else
1119 | {
1120 | sprintf(tmpString, "P %ld %ld\r\n", Sector, Sector);
1121 | }
1122 |
1123 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1124 | {
1125 | DebugPrintf(1, "Wrong answer on Prepare-Command (1) (Sector %ld)\n", Sector);
1126 | return (WRONG_ANSWER_PREP + GetAndReportErrorNumber(Answer));
1127 | }
1128 |
1129 | DebugPrintf(2, ".");
1130 | fflush(stdout);
1131 | if (IspEnvironment->WipeDevice == 0 && (Sector!=0)) //Sector 0 already erased
1132 | {
1133 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1134 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1135 | {
1136 | // TODO: Quick and dirty hack to address bank 0
1137 | sprintf(tmpString, "E %ld %ld 0\r\n", Sector, Sector);
1138 | }
1139 | else
1140 | {
1141 | sprintf(tmpString, "E %ld %ld\r\n", Sector, Sector);
1142 | }
1143 |
1144 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1145 | {
1146 | DebugPrintf(1, "Wrong answer on Erase-Command (Sector %ld)\n", Sector);
1147 | return (WRONG_ANSWER_ERAS + GetAndReportErrorNumber(Answer));
1148 | }
1149 |
1150 | DebugPrintf(2, ".");
1151 | fflush(stdout);
1152 | }
1153 | }
1154 |
1155 | SectorLength = LPCtypes[IspEnvironment->DetectedDevice].SectorTable[Sector];
1156 | if (SectorLength > IspEnvironment->BinaryLength - SectorStart)
1157 | {
1158 | SectorLength = IspEnvironment->BinaryLength - SectorStart;
1159 | }
1160 |
1161 | for (SectorOffset = 0; SectorOffset < SectorLength; SectorOffset += SectorChunk)
1162 | {
1163 | // Check if we are to write only 0xFFs - it would be just a waste of time..
1164 | if (SectorOffset == 0) {
1165 | for (SectorOffset = 0; SectorOffset < SectorLength; ++SectorOffset)
1166 | {
1167 | if (IspEnvironment->BinaryContent[SectorStart + SectorOffset] != 0xFF)
1168 | break;
1169 | }
1170 | if (SectorOffset == SectorLength) // all data contents were 0xFFs
1171 | {
1172 | DebugPrintf(2, "Whole sector contents is 0xFFs, skipping programming.");
1173 | fflush(stdout);
1174 | break;
1175 | }
1176 | SectorOffset = 0; // re-set otherwise
1177 | }
1178 |
1179 | if (SectorOffset > 0)
1180 | {
1181 | // Add a visible marker between segments in a sector
1182 | DebugPrintf(2, "|"); /* means: partial segment copied */
1183 | fflush(stdout);
1184 | }
1185 |
1186 | // If the Flash ROM sector size is bigger than the number of bytes
1187 | // we can copy from RAM to Flash, we must "chop up" the sector and
1188 | // copy these individually.
1189 | // This is especially needed in the case where a Flash sector is
1190 | // bigger than the amount of SRAM.
1191 | SectorChunk = SectorLength - SectorOffset;
1192 | if (SectorChunk > (unsigned)LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize)
1193 | {
1194 | SectorChunk = LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize;
1195 | }
1196 |
1197 | // Write multiple of 45 * 4 Byte blocks to RAM, but copy maximum of on sector to Flash
1198 | // In worst case we transfer up to 180 byte too much to RAM
1199 | // but then we can always use full 45 byte blocks and length is multiple of 4
1200 | CopyLength = SectorChunk;
1201 |
1202 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX ||
1203 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
1204 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
1205 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX ||
1206 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX ||
1207 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX)
1208 | {
1209 | if ((CopyLength % (45 * 4)) != 0)
1210 | {
1211 | CopyLength += ((45 * 4) - (CopyLength % (45 * 4)));
1212 | }
1213 | }
1214 |
1215 | sprintf(tmpString, "W %ld %ld\r\n", ReturnValueLpcRamBase(IspEnvironment), CopyLength);
1216 |
1217 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1218 | {
1219 | DebugPrintf(1, "Wrong answer on Write-Command\n");
1220 | return (WRONG_ANSWER_WRIT + GetAndReportErrorNumber(Answer));
1221 | }
1222 |
1223 | DebugPrintf(2, ".");
1224 | fflush(stdout);
1225 |
1226 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX ||
1227 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
1228 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
1229 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX ||
1230 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX ||
1231 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX)
1232 | {
1233 | block_CRC = 0;
1234 | Line = 0;
1235 |
1236 | // Transfer blocks of 45 * 4 bytes to RAM
1237 | for (Pos = SectorStart + SectorOffset; (Pos < SectorStart + SectorOffset + CopyLength) && (Pos < IspEnvironment->BinaryLength); Pos += (45 * 4))
1238 | {
1239 | for (Block = 0; Block < 4; Block++) // Each block 45 bytes
1240 | {
1241 | DebugPrintf(2, ".");
1242 | fflush(stdout);
1243 |
1244 | #if defined INTEGRATED_IN_WIN_APP
1245 | // inform the calling application about having written another chuck of data
1246 | AppWritten(45);
1247 | #endif
1248 |
1249 | // Uuencode one 45 byte block
1250 | tmpStringPos = 0;
1251 |
1252 | #if !defined COMPILE_FOR_LPC21
1253 | sendbuf[Line][tmpStringPos++] = (char)(' ' + 45); // Encode Length of block
1254 | #else
1255 | tmpString[tmpStringPos++] = (char)(' ' + 45); // Encode Length of block
1256 | #endif
1257 |
1258 | for (BlockOffset = 0; BlockOffset < 45; BlockOffset++)
1259 | {
1260 | if ( (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment))
1261 | ||(IspEnvironment->BinaryOffset >= ReturnValueLpcRamStart(IspEnvironment)+(LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024)))
1262 | { // Flash: use full memory
1263 | c = IspEnvironment->BinaryContent[Pos + Block * 45 + BlockOffset];
1264 | }
1265 | else
1266 | { // RAM: Skip first 0x200 bytes, these are used by the download program in LPC21xx
1267 | c = IspEnvironment->BinaryContent[Pos + Block * 45 + BlockOffset + 0x200];
1268 | }
1269 |
1270 | block_CRC += c;
1271 |
1272 | k = (k << 8) + (c & 255);
1273 |
1274 | if ((BlockOffset % 3) == 2) // Collecting always 3 Bytes, then do processing in 4 Bytes
1275 | {
1276 | #if !defined COMPILE_FOR_LPC21
1277 | sendbuf[Line][tmpStringPos++] = uuencode_table[(k >> 18) & 63];
1278 | sendbuf[Line][tmpStringPos++] = uuencode_table[(k >> 12) & 63];
1279 | sendbuf[Line][tmpStringPos++] = uuencode_table[(k >> 6) & 63];
1280 | sendbuf[Line][tmpStringPos++] = uuencode_table[ k & 63];
1281 | #else
1282 | tmpString[tmpStringPos++] = uuencode_table[(k >> 18) & 63];
1283 | tmpString[tmpStringPos++] = uuencode_table[(k >> 12) & 63];
1284 | tmpString[tmpStringPos++] = uuencode_table[(k >> 6) & 63];
1285 | tmpString[tmpStringPos++] = uuencode_table[ k & 63];
1286 | #endif
1287 | }
1288 | }
1289 |
1290 |
1291 | #if !defined COMPILE_FOR_LPC21
1292 | sendbuf[Line][tmpStringPos++] = '\r';
1293 | sendbuf[Line][tmpStringPos++] = '\n';
1294 | sendbuf[Line][tmpStringPos++] = 0;
1295 |
1296 | SendComPort(IspEnvironment, sendbuf[Line]);
1297 | // receive only for debug proposes
1298 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 1, 5000);
1299 | FormatCommand(sendbuf[Line], tmpString);
1300 | FormatCommand(Answer, Answer);
1301 | if (strncmp(Answer, tmpString, strlen(tmpString)) != 0)
1302 | {
1303 | DebugPrintf(1, "Error on writing data (1)\n");
1304 | return (ERROR_WRITE_DATA);
1305 | }
1306 | #else
1307 | tmpString[tmpStringPos++] = '\r';
1308 | tmpString[tmpStringPos++] = '\n';
1309 | tmpString[tmpStringPos++] = 0;
1310 |
1311 | SendComPort(IspEnvironment, tmpString);
1312 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 1, 5000);
1313 | FormatCommand(tmpString, tmpString);
1314 | FormatCommand(Answer, Answer);
1315 | if (strncmp(Answer, tmpString, tmpStringPos) != 0)
1316 | {
1317 | DebugPrintf(1, "Error on writing data (1)\n");
1318 | return (ERROR_WRITE_DATA);
1319 | }
1320 | #endif
1321 |
1322 | Line++;
1323 |
1324 | DebugPrintf(3, "Line = %d\n", Line);
1325 |
1326 | if (Line == 20)
1327 | {
1328 | #if !defined COMPILE_FOR_LPC21
1329 | for (repeat = 0; repeat < 3; repeat++)
1330 | {
1331 |
1332 | // DebugPrintf(1, "block_CRC = %ld\n", block_CRC);
1333 |
1334 | sprintf(tmpString, "%ld\r\n", block_CRC);
1335 |
1336 | SendComPort(IspEnvironment, tmpString);
1337 |
1338 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2, 5000);
1339 |
1340 | sprintf(tmpString, "%ld\nOK\n", block_CRC);
1341 |
1342 | FormatCommand(tmpString, tmpString);
1343 | FormatCommand(Answer, Answer);
1344 | if (strcmp(Answer, tmpString) != 0)
1345 | {
1346 | for (i = 0; i < Line; i++)
1347 | {
1348 | SendComPort(IspEnvironment, sendbuf[i]);
1349 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 1, 5000);
1350 | }
1351 | }
1352 | else
1353 | break;
1354 | }
1355 |
1356 | if (repeat >= 3)
1357 | {
1358 | DebugPrintf(1, "Error on writing block_CRC (1)\n");
1359 | return (ERROR_WRITE_CRC);
1360 | }
1361 | #else
1362 | // DebugPrintf(1, "block_CRC = %ld\n", block_CRC);
1363 | sprintf(tmpString, "%ld\r\n", block_CRC);
1364 | SendComPort(IspEnvironment, tmpString);
1365 |
1366 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
1367 |
1368 | sprintf(tmpString, "%ld\nOK\n", block_CRC);
1369 | FormatCommand(tmpString, tmpString);
1370 | FormatCommand(Answer, Answer);
1371 | if (strcmp(Answer, tmpString) != 0)
1372 | {
1373 | DebugPrintf(1, "Error on writing block_CRC (2)\n");
1374 | return (ERROR_WRITE_CRC);
1375 | }
1376 | #endif
1377 | Line = 0;
1378 | block_CRC = 0;
1379 | }
1380 | }
1381 | }
1382 |
1383 | if (Line != 0)
1384 | {
1385 | #if !defined COMPILE_FOR_LPC21
1386 | for (repeat = 0; repeat < 3; repeat++)
1387 | {
1388 | sprintf(tmpString, "%ld\r\n", block_CRC);
1389 |
1390 | SendComPort(IspEnvironment, tmpString);
1391 |
1392 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
1393 |
1394 | sprintf(tmpString, "%ld\nOK\n", block_CRC);
1395 |
1396 | FormatCommand(tmpString, tmpString);
1397 | FormatCommand(Answer, Answer);
1398 | if (strcmp(Answer, tmpString) != 0)
1399 | {
1400 | for (i = 0; i < Line; i++)
1401 | {
1402 | SendComPort(IspEnvironment, sendbuf[i]);
1403 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 1,5000);
1404 | }
1405 | }
1406 | else
1407 | break;
1408 | }
1409 |
1410 | if (repeat >= 3)
1411 | {
1412 | DebugPrintf(1, "Error on writing block_CRC (3)\n");
1413 | return (ERROR_WRITE_CRC2);
1414 | }
1415 | #else
1416 | sprintf(tmpString, "%ld\r\n", block_CRC);
1417 | SendComPort(IspEnvironment, tmpString);
1418 |
1419 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2,5000);
1420 |
1421 | sprintf(tmpString, "%ld\nOK\n", block_CRC);
1422 | FormatCommand(tmpString, tmpString);
1423 | FormatCommand(Answer, Answer);
1424 | if (strcmp(Answer, tmpString) != 0)
1425 | {
1426 | DebugPrintf(1, "Error on writing block_CRC (4)\n");
1427 | return (ERROR_WRITE_CRC2);
1428 | }
1429 | #endif
1430 | }
1431 | }
1432 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
1433 | {
1434 | unsigned char BigAnswer[4096];
1435 | unsigned long CopyLengthPartialOffset = 0;
1436 | unsigned long CopyLengthPartialRemainingBytes;
1437 |
1438 | while(CopyLengthPartialOffset < CopyLength)
1439 | {
1440 | CopyLengthPartialRemainingBytes = CopyLength - CopyLengthPartialOffset;
1441 | if(CopyLengthPartialRemainingBytes > 256)
1442 | {
1443 | // There seems to be an error in LPC812:
1444 | // When too much bytes are written at high speed,
1445 | // bytes get lost
1446 | // Workaround: Use smaller blocks
1447 | CopyLengthPartialRemainingBytes = 256;
1448 | }
1449 |
1450 | SendComPortBlock(IspEnvironment, &IspEnvironment->BinaryContent[SectorStart + SectorOffset + CopyLengthPartialOffset], CopyLengthPartialRemainingBytes);
1451 |
1452 | if (ReceiveComPortBlockComplete(IspEnvironment, &BigAnswer, CopyLengthPartialRemainingBytes, 10000) != 0)
1453 | {
1454 | return (ERROR_WRITE_DATA);
1455 | }
1456 |
1457 | if(memcmp(&IspEnvironment->BinaryContent[SectorStart + SectorOffset + CopyLengthPartialOffset], BigAnswer, CopyLengthPartialRemainingBytes))
1458 | {
1459 | return (ERROR_WRITE_DATA);
1460 | }
1461 |
1462 | CopyLengthPartialOffset += CopyLengthPartialRemainingBytes;
1463 | }
1464 | }
1465 |
1466 | if ( (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment))
1467 | ||(IspEnvironment->BinaryOffset >= ReturnValueLpcRamStart(IspEnvironment)+(LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024)))
1468 | {
1469 | // Prepare command must be repeated before every write
1470 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1471 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1472 | {
1473 | // TODO: Quick and dirty hack to address bank 0
1474 | sprintf(tmpString, "P %ld %ld 0\r\n", Sector, Sector);
1475 | }
1476 | else
1477 | {
1478 | sprintf(tmpString, "P %ld %ld\r\n", Sector, Sector);
1479 | }
1480 |
1481 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1482 | {
1483 | DebugPrintf(1, "Wrong answer on Prepare-Command (2) (Sector %ld)\n", Sector);
1484 | return (WRONG_ANSWER_PREP2 + GetAndReportErrorNumber(Answer));
1485 | }
1486 |
1487 | // Round CopyLength up to one of the following values: 512, 1024,
1488 | // 4096, 8192; but do not exceed the maximum copy size (usually
1489 | // 8192, but chip-dependent)
1490 | if (CopyLength < 512)
1491 | {
1492 | CopyLength = 512;
1493 | }
1494 | else if (SectorLength < 1024)
1495 | {
1496 | CopyLength = 1024;
1497 | }
1498 | else if (SectorLength < 4096)
1499 | {
1500 | CopyLength = 4096;
1501 | }
1502 | else
1503 | {
1504 | CopyLength = 8192;
1505 | }
1506 | if (CopyLength > (unsigned)LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize)
1507 | {
1508 | CopyLength = LPCtypes[IspEnvironment->DetectedDevice].MaxCopySize;
1509 | }
1510 |
1511 | sprintf(tmpString, "C %ld %ld %ld\r\n", IspEnvironment->BinaryOffset + SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength);
1512 |
1513 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1514 | {
1515 | DebugPrintf(1, "Wrong answer on Copy-Command\n");
1516 | return (WRONG_ANSWER_COPY + GetAndReportErrorNumber(Answer));
1517 | }
1518 |
1519 | if (IspEnvironment->Verify)
1520 | {
1521 |
1522 | //Avoid compare first 64 bytes.
1523 | //Because first 64 bytes are re-mapped to flash boot sector,
1524 | //and the compare result may not be correct.
1525 | if (SectorStart + SectorOffset<64)
1526 | {
1527 | sprintf(tmpString, "M %d %ld %ld\r\n", 64, ReturnValueLpcRamBase(IspEnvironment) + (64 - SectorStart - SectorOffset), CopyLength-(64 - SectorStart - SectorOffset));
1528 | }
1529 | else
1530 | {
1531 | sprintf(tmpString, "M %ld %ld %ld\r\n", SectorStart + SectorOffset, ReturnValueLpcRamBase(IspEnvironment), CopyLength);
1532 | }
1533 |
1534 | if (!SendAndVerify(IspEnvironment, tmpString, Answer, sizeof Answer))
1535 | {
1536 | DebugPrintf(1, "Wrong answer on Compare-Command\n");
1537 | return (WRONG_ANSWER_COPY + GetAndReportErrorNumber(Answer));
1538 | }
1539 | }
1540 | }
1541 | }
1542 |
1543 | DebugPrintf(2, "\n");
1544 | fflush(stdout);
1545 |
1546 | if ((SectorStart + SectorLength) >= IspEnvironment->BinaryLength && Sector!=0)
1547 | {
1548 | Sector = 0;
1549 | SectorStart = 0;
1550 | }
1551 | else if (Sector == 0) {
1552 | break;
1553 | }
1554 | else {
1555 | SectorStart += LPCtypes[IspEnvironment->DetectedDevice].SectorTable[Sector];
1556 | Sector++;
1557 | }
1558 | }
1559 |
1560 | tDoneUpload = time(NULL);
1561 | if (IspEnvironment->Verify)
1562 | DebugPrintf(2, "Download Finished and Verified correct... taking %d seconds\n", tDoneUpload - tStartUpload);
1563 | else
1564 | DebugPrintf(2, "Download Finished... taking %d seconds\n", tDoneUpload - tStartUpload);
1565 |
1566 | // For LPC18xx set boot bank to 0
1567 | if (LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1568 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1569 | {
1570 | if (!SendAndVerify(IspEnvironment, "S 0\r\n", Answer, sizeof Answer))
1571 | {
1572 | DebugPrintf(1, "Wrong answer on SetActiveBootFlashBank-Command\n");
1573 | return (WRONG_ANSWER_BTBNK + GetAndReportErrorNumber(Answer));
1574 | }
1575 | }
1576 |
1577 | if(IspEnvironment->DoNotStart == 0)
1578 | {
1579 | DebugPrintf(2, "Now launching the brand new code\n");
1580 | fflush(stdout);
1581 |
1582 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
1583 | {
1584 | sprintf(tmpString, "G %ld A\r\n", IspEnvironment->StartAddress);
1585 | }
1586 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1587 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX ||
1588 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
1589 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
1590 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
1591 | {
1592 | sprintf(tmpString, "G %ld T\r\n", IspEnvironment->StartAddress & ~1);
1593 | }
1594 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
1595 | {
1596 | sprintf(tmpString, "G 0 T\r\n");
1597 | }
1598 | else
1599 | {
1600 | DebugPrintf(1, "Internal Error %s %d\n", __FILE__, __LINE__);
1601 | exit(1);
1602 | }
1603 |
1604 | SendComPort(IspEnvironment, tmpString); //goto 0 : run this fresh new downloaded code code
1605 | if ( (IspEnvironment->BinaryOffset < ReturnValueLpcRamStart(IspEnvironment))
1606 | ||(IspEnvironment->BinaryOffset >= ReturnValueLpcRamStart(IspEnvironment)+(LPCtypes[IspEnvironment->DetectedDevice].RAMSize*1024)))
1607 | { // Skip response on G command - show response on Terminal instead
1608 | ReceiveComPort(IspEnvironment, Answer, sizeof(Answer)-1, &realsize, 2, 5000);
1609 | /* the reply string is frequently terminated with a -1 (EOF) because the
1610 | * connection gets broken; zero-terminate the string ourselves
1611 | */
1612 | while (realsize > 0 && ((signed char) Answer[(int)realsize - 1]) < 0)
1613 | realsize--;
1614 | Answer[(int)realsize] = '\0';
1615 | /* Better to check only the first 9 chars instead of complete receive buffer,
1616 | * because the answer can contain the output by the started programm
1617 | */
1618 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
1619 | {
1620 | sprintf(ExpectedAnswer, "G %ld A\n0", IspEnvironment->StartAddress);
1621 | }
1622 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX ||
1623 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX ||
1624 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX ||
1625 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX ||
1626 | LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
1627 | {
1628 | sprintf(ExpectedAnswer, "G %ld T\n0", IspEnvironment->StartAddress & ~1);
1629 | }
1630 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
1631 | {
1632 | sprintf(ExpectedAnswer, "G 0 T\n0");
1633 | }
1634 | else
1635 | {
1636 | DebugPrintf(1, "Internal Error %s %d\n", __FILE__, __LINE__);
1637 | exit(1);
1638 | }
1639 |
1640 | FormatCommand(Answer, Answer);
1641 | if (realsize == 0 || strncmp((const char *)Answer, /*cmdstr*/ExpectedAnswer, strlen(/*cmdstr*/ExpectedAnswer)) != 0)
1642 | {
1643 | DebugPrintf(2, "Failed to run the new downloaded code: ");
1644 | return (FAILED_RUN + GetAndReportErrorNumber(Answer));
1645 | }
1646 | }
1647 |
1648 | fflush(stdout);
1649 | }
1650 | return (0);
1651 | }
1652 | #endif // LPC_SUPPORT
1653 |
1654 |
1655 | unsigned long ReturnValueLpcRamStart(ISP_ENVIRONMENT *IspEnvironment)
1656 | {
1657 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX)
1658 | {
1659 | return LPC_RAMSTART_LPC43XX;
1660 | }
1661 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
1662 | {
1663 | return LPC_RAMSTART_LPC2XXX;
1664 | }
1665 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1666 | {
1667 | return LPC_RAMSTART_LPC18XX;
1668 | }
1669 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX)
1670 | {
1671 | return LPC_RAMSTART_LPC17XX;
1672 | }
1673 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX)
1674 | {
1675 | return LPC_RAMSTART_LPC13XX;
1676 | }
1677 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
1678 | {
1679 | return LPC_RAMSTART_LPC11XX;
1680 | }
1681 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
1682 | {
1683 | return LPC_RAMSTART_LPC8XX;
1684 | }
1685 | DebugPrintf(1, "Error in ReturnValueLpcRamStart (%d)\n", LPCtypes[IspEnvironment->DetectedDevice].ChipVariant);
1686 | exit(1);
1687 | }
1688 |
1689 |
1690 | unsigned long ReturnValueLpcRamBase(ISP_ENVIRONMENT *IspEnvironment)
1691 | {
1692 | if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC43XX)
1693 | {
1694 | return LPC_RAMBASE_LPC43XX;
1695 | }
1696 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC2XXX)
1697 | {
1698 | return LPC_RAMBASE_LPC2XXX;
1699 | }
1700 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC18XX)
1701 | {
1702 | return LPC_RAMBASE_LPC18XX;
1703 | }
1704 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC17XX)
1705 | {
1706 | return LPC_RAMBASE_LPC17XX;
1707 | }
1708 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC13XX)
1709 | {
1710 | return LPC_RAMBASE_LPC13XX;
1711 | }
1712 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC11XX)
1713 | {
1714 | return LPC_RAMBASE_LPC11XX;
1715 | }
1716 | else if(LPCtypes[IspEnvironment->DetectedDevice].ChipVariant == CHIP_VARIANT_LPC8XX)
1717 | {
1718 | return LPC_RAMBASE_LPC8XX;
1719 | }
1720 | DebugPrintf(1, "Error in ReturnValueLpcRamBase (%d)\n", LPCtypes[IspEnvironment->DetectedDevice].ChipVariant);
1721 | exit(1);
1722 | }
1723 |
--------------------------------------------------------------------------------
/lpcprog.dsp:
--------------------------------------------------------------------------------
1 | # Microsoft Developer Studio Project File - Name="lpcprog" - Package Owner=<4>
2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00
3 | # ** DO NOT EDIT **
4 |
5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103
6 |
7 | CFG=lpcprog - Win32 Debug
8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE,
9 | !MESSAGE use the Export Makefile command and run
10 | !MESSAGE
11 | !MESSAGE NMAKE /f "lpcprog.mak".
12 | !MESSAGE
13 | !MESSAGE You can specify a configuration when running NMAKE
14 | !MESSAGE by defining the macro CFG on the command line. For example:
15 | !MESSAGE
16 | !MESSAGE NMAKE /f "lpcprog.mak" CFG="lpcprog - Win32 Debug"
17 | !MESSAGE
18 | !MESSAGE Possible choices for configuration are:
19 | !MESSAGE
20 | !MESSAGE "lpcprog - Win32 Release" (based on "Win32 (x86) Console Application")
21 | !MESSAGE "lpcprog - Win32 Debug" (based on "Win32 (x86) Console Application")
22 | !MESSAGE
23 |
24 | # Begin Project
25 | # PROP AllowPerConfigDependencies 0
26 | # PROP Scc_ProjName ""
27 | # PROP Scc_LocalPath ""
28 | CPP=cl.exe
29 | RSC=rc.exe
30 |
31 | !IF "$(CFG)" == "lpcprog - Win32 Release"
32 |
33 | # PROP BASE Use_MFC 0
34 | # PROP BASE Use_Debug_Libraries 0
35 | # PROP BASE Output_Dir "Release"
36 | # PROP BASE Intermediate_Dir "Release"
37 | # PROP BASE Target_Dir ""
38 | # PROP Use_MFC 0
39 | # PROP Use_Debug_Libraries 0
40 | # PROP Output_Dir "Release"
41 | # PROP Intermediate_Dir "Release"
42 | # PROP Target_Dir ""
43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
45 | # ADD BASE RSC /l 0x809 /d "NDEBUG"
46 | # ADD RSC /l 0x809 /d "NDEBUG"
47 | BSC32=bscmake.exe
48 | # ADD BASE BSC32 /nologo
49 | # ADD BSC32 /nologo
50 | LINK32=link.exe
51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
53 |
54 | !ELSEIF "$(CFG)" == "lpcprog - Win32 Debug"
55 |
56 | # PROP BASE Use_MFC 0
57 | # PROP BASE Use_Debug_Libraries 1
58 | # PROP BASE Output_Dir "Debug"
59 | # PROP BASE Intermediate_Dir "Debug"
60 | # PROP BASE Target_Dir ""
61 | # PROP Use_MFC 0
62 | # PROP Use_Debug_Libraries 1
63 | # PROP Output_Dir "Debug"
64 | # PROP Intermediate_Dir "Debug"
65 | # PROP Target_Dir ""
66 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
67 | # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
68 | # ADD BASE RSC /l 0x809 /d "_DEBUG"
69 | # ADD RSC /l 0x809 /d "_DEBUG"
70 | BSC32=bscmake.exe
71 | # ADD BASE BSC32 /nologo
72 | # ADD BSC32 /nologo
73 | LINK32=link.exe
74 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
75 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
76 |
77 | !ENDIF
78 |
79 | # Begin Target
80 |
81 | # Name "lpcprog - Win32 Release"
82 | # Name "lpcprog - Win32 Debug"
83 | # Begin Source File
84 |
85 | SOURCE=.\adprog.c
86 | # End Source File
87 | # Begin Source File
88 |
89 | SOURCE=.\lpc21isp.c
90 | # End Source File
91 | # Begin Source File
92 |
93 | SOURCE=.\lpcprog.c
94 | # End Source File
95 | # Begin Source File
96 |
97 | SOURCE=.\lpcterm.c
98 | # End Source File
99 | # End Target
100 | # End Project
101 |
--------------------------------------------------------------------------------
/lpcprog.dsw:
--------------------------------------------------------------------------------
1 | Microsoft Developer Studio Workspace File, Format Version 6.00
2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
3 |
4 | ###############################################################################
5 |
6 | Project: "lpcprog"=.\lpcprog.dsp - Package Owner=<4>
7 |
8 | Package=<5>
9 | {{{
10 | }}}
11 |
12 | Package=<4>
13 | {{{
14 | }}}
15 |
16 | ###############################################################################
17 |
18 | Global:
19 |
20 | Package=<5>
21 | {{{
22 | }}}
23 |
24 | Package=<3>
25 | {{{
26 | }}}
27 |
28 | ###############################################################################
29 |
30 |
--------------------------------------------------------------------------------
/lpcprog.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: lpcprog.h
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2014, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | /* LPC_RAMSTART, LPC_RAMBASE
34 | *
35 | * Used in NxpDownload() to decide whether to Flash code or just place in in RAM
36 | * (works for .hex files only)
37 | *
38 | * LPC_RAMSTART - the Physical start address of the SRAM
39 | * LPC_RAMBASE - the base address where downloading starts.
40 | * Note that any code in the .hex file that resides in 0x4000,0000 ~ 0x4000,0200
41 | * will _not_ be written to the LPCs SRAM.
42 | * This is due to the fact that 0x4000,0040 - 0x4000,0200 is used by the bootrom.
43 | * Any interrupt vectors must be copied to 0x4000,0000 and remapped to 0x0000,0000
44 | * by the startup code.
45 | */
46 | #define LPC_RAMSTART_LPC43XX 0x10000000L
47 | #define LPC_RAMBASE_LPC43XX 0x10000200L
48 |
49 | #define LPC_RAMSTART_LPC2XXX 0x40000000L
50 | #define LPC_RAMBASE_LPC2XXX 0x40000200L
51 |
52 | #define LPC_RAMSTART_LPC18XX 0x10000000L
53 | #define LPC_RAMBASE_LPC18XX 0x10000200L
54 |
55 | #define LPC_RAMSTART_LPC17XX 0x10000000L
56 | #define LPC_RAMBASE_LPC17XX 0x10000200L
57 |
58 | #define LPC_RAMSTART_LPC13XX 0x10000000L
59 | #define LPC_RAMBASE_LPC13XX 0x10000300L
60 |
61 | #define LPC_RAMSTART_LPC11XX 0x10000000L
62 | #define LPC_RAMBASE_LPC11XX 0x10000300L
63 |
64 | #define LPC_RAMSTART_LPC8XX 0x10000000L
65 | #define LPC_RAMBASE_LPC8XX 0x10000270L
66 |
67 | /* Return values used by NxpDownload(): reserving all values from 0x1000 to 0x1FFF */
68 |
69 | #define NO_ANSWER_WDT 0x1000
70 | #define NO_ANSWER_QM 0x1001
71 | #define NO_ANSWER_SYNC 0x1002
72 | #define NO_ANSWER_OSC 0x1003
73 | #define NO_ANSWER_RBV 0x1004
74 | #define NO_ANSWER_RPID 0x1005
75 | #define ERROR_WRITE_DATA 0x1006
76 | #define ERROR_WRITE_CRC 0x1007
77 | #define ERROR_WRITE_CRC2 0x1008
78 | #define PROGRAM_TOO_LARGE 0x1009
79 |
80 | #define USER_ABORT_SYNC 0x100A /* User aborted synchronisation process */
81 |
82 | #define UNKNOWN_LPC 0x100B /* Unknown LPC detected */
83 |
84 | #define UNLOCK_ERROR 0x1100 /* return value is 0x1100 + NXP ISP returned value (0 to 255) */
85 | #define WRONG_ANSWER_PREP 0x1200 /* return value is 0x1200 + NXP ISP returned value (0 to 255) */
86 | #define WRONG_ANSWER_ERAS 0x1300 /* return value is 0x1300 + NXP ISP returned value (0 to 255) */
87 | #define WRONG_ANSWER_WRIT 0x1400 /* return value is 0x1400 + NXP ISP returned value (0 to 255) */
88 | #define WRONG_ANSWER_PREP2 0x1500 /* return value is 0x1500 + NXP ISP returned value (0 to 255) */
89 | #define WRONG_ANSWER_COPY 0x1600 /* return value is 0x1600 + NXP ISP returned value (0 to 255) */
90 | #define FAILED_RUN 0x1700 /* return value is 0x1700 + NXP ISP returned value (0 to 255) */
91 | #define WRONG_ANSWER_BTBNK 0x1800 /* return value is 0x1800 + NXP ISP returned value (0 to 255) */
92 |
93 | #if defined COMPILE_FOR_LPC21
94 | #ifndef WIN32
95 | #define LPC_BSL_PIN 13
96 | #define LPC_RESET_PIN 47
97 | #define LPC_RESET(in) NAsetGPIOpin(LPC_RESET_PIN, (in))
98 | #define LPC_BSL(in) NAsetGPIOpin(LPC_BSL_PIN, (in))
99 | #endif // WIN32
100 | #endif // COMPILE_FOR_LPC21
101 |
102 |
103 | /* LPC_FLASHMASK
104 | *
105 | * LPC_FLASHMASK - bitmask to define the maximum size of the Filesize to download.
106 | * LoadFile() will check any new segment address record (03) or extended linear
107 | * address record (04) to see if the addressed 64 kByte data block still falls
108 | * in the max. flash size.
109 | * LoadFile() will not load any files that are larger than this size.
110 | */
111 | #define LPC_FLASHMASK 0xFFC00000 /* 22 bits = 4 MB */
112 |
113 | typedef enum
114 | {
115 | CHIP_VARIANT_NONE,
116 | CHIP_VARIANT_LPC43XX,
117 | CHIP_VARIANT_LPC2XXX,
118 | CHIP_VARIANT_LPC18XX,
119 | CHIP_VARIANT_LPC17XX,
120 | CHIP_VARIANT_LPC13XX,
121 | CHIP_VARIANT_LPC11XX,
122 | CHIP_VARIANT_LPC8XX
123 | } CHIP_VARIANT;
124 |
125 | typedef struct
126 | {
127 | const unsigned long id;
128 | const unsigned long id2;
129 | const unsigned int EvalId2;
130 | const char *Product;
131 | const unsigned int FlashSize; /* in kiB, for informational purposes only */
132 | const unsigned int RAMSize; /* in kiB, for informational purposes only */
133 | unsigned int FlashSectors; /* total number of sectors */
134 | unsigned int MaxCopySize; /* maximum size that can be copied to Flash in a single command */
135 | const unsigned int *SectorTable; /* pointer to a sector table with constant the sector sizes */
136 | const CHIP_VARIANT ChipVariant;
137 | } LPC_DEVICE_TYPE;
138 |
139 | int NxpDownload(ISP_ENVIRONMENT *IspEnvironment);
140 |
141 | unsigned long ReturnValueLpcRamStart(ISP_ENVIRONMENT *IspEnvironment);
142 |
143 | unsigned long ReturnValueLpcRamBase(ISP_ENVIRONMENT *IspEnvironment);
144 |
145 |
--------------------------------------------------------------------------------
/lpcterm.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: lpcterm.c
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2014, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | #if defined(_WIN32)
34 | #if !defined __BORLANDC__
35 | #include "StdAfx.h"
36 | #endif
37 | #endif // defined(_WIN32)
38 | #include "lpc21isp.h"
39 | #include "lpcterm.h"
40 |
41 | #ifdef TERMINAL_SUPPORT
42 | /***************************** Terminal *********************************/
43 | /** Acts as a simple dumb terminal. Press 'ESC' to exit.
44 | */
45 | BOOL CheckTerminalParameters(ISP_ENVIRONMENT *IspEnvironment, char* pstr)
46 | {
47 | if (stricmp(pstr, "-localecho") == 0)
48 | {
49 | IspEnvironment->LocalEcho = 1;
50 | DebugPrintf(3, "Local echo in terminal mode.\n");
51 | return TRUE;
52 | }
53 |
54 | if (stricmp(pstr, "-term") == 0)
55 | {
56 | IspEnvironment->TerminalAfterUpload = 1;
57 | DebugPrintf(3, "Invoke terminal after upload.\n");
58 | return TRUE;
59 | }
60 |
61 | if (stricmp(pstr, "-termonly") == 0)
62 | {
63 | IspEnvironment->TerminalOnly = 1;
64 | IspEnvironment->ProgramChip = 0;
65 | DebugPrintf(3, "Only provide terminal.\n");
66 | return TRUE;
67 | }
68 |
69 | return FALSE;
70 | }
71 |
72 | void Terminal(ISP_ENVIRONMENT *IspEnvironment)
73 | {
74 | if (IspEnvironment->TerminalAfterUpload || IspEnvironment->TerminalOnly)
75 | {
76 | int ch = 0;
77 | char buffer[128];
78 | int fdlogfile = -1;
79 | unsigned long realsize;
80 |
81 | // When logging is switched on, output terminal output to lpc21isp.log
82 | if (IspEnvironment->LogFile)
83 | {
84 | fdlogfile = open("lpc21isp.log", O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0777);
85 | }
86 |
87 | PrepareKeyboardTtySettings();
88 |
89 | DebugPrintf(1, "Terminal started (press Escape to abort)\n\n");
90 | fflush(stdout);
91 |
92 | do
93 | {
94 | ReceiveComPort(IspEnvironment, buffer, sizeof(buffer) - 1, &realsize, 0,200); // Check for received characters
95 |
96 | if (realsize)
97 | {
98 | write(1, buffer, realsize);
99 | fflush(stdout);
100 | if (IspEnvironment->LogFile) // When logging is turned on, then copy output to logfile
101 | {
102 | write(fdlogfile, buffer, realsize);
103 | }
104 | }
105 |
106 | // check for keypress, and write any out the port.
107 | if (kbhit())
108 | {
109 | ch = getch();
110 | if (ch == 0x1b)
111 | {
112 | break;
113 | }
114 | buffer[0] = (unsigned char)ch;
115 | buffer[1] = 0;
116 |
117 | if (IspEnvironment->LocalEcho)
118 | {
119 | write(1, buffer, 1);
120 | }
121 |
122 | SendComPort(IspEnvironment, buffer);
123 | }
124 | }
125 | while (ch != 0x1b);
126 |
127 | DebugPrintf(1, "\n\nTerminal stopped\n\n");
128 | fflush(stdout);
129 |
130 | ResetKeyboardTtySettings();
131 |
132 | if (IspEnvironment->LogFile)
133 | {
134 | close(fdlogfile);
135 | }
136 | }
137 | }
138 | #endif
139 |
--------------------------------------------------------------------------------
/lpcterm.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 |
3 | Project: Portable command line ISP for NXP LPC1000 / LPC2000 family
4 | and Analog Devices ADUC70xx
5 |
6 | Filename: lpcterm.h
7 |
8 | Compiler: Microsoft VC 6/7, Microsoft VS2008, Microsoft VS2010,
9 | GCC Cygwin, GCC Linux, GCC ARM ELF
10 |
11 | Author: Martin Maurer (Martin.Maurer@clibb.de)
12 |
13 | Copyright: (c) Martin Maurer 2003-2011, All rights reserved
14 | Portions Copyright (c) by Aeolus Development 2004 http://www.aeolusdevelopment.com
15 |
16 | This file is part of lpc21isp.
17 |
18 | lpc21isp is free software: you can redistribute it and/or modify
19 | it under the terms of the GNU Lesser General Public License as published by
20 | the Free Software Foundation, either version 3 of the License, or
21 | any later version.
22 |
23 | lpc21isp is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 | GNU Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public License
29 | and GNU General Public License along with lpc21isp.
30 | If not, see .
31 | */
32 |
33 | #ifndef TRUE
34 | #define TRUE (1)
35 | #endif
36 | #ifndef FALSE
37 | #define FALSE (0)
38 | #endif
39 |
40 | typedef int BOOL;
41 |
42 | void Terminal(ISP_ENVIRONMENT *IspEnvironment);
43 | BOOL CheckTerminalParameters(ISP_ENVIRONMENT *IspEnvironment, char* pstr);
44 |
--------------------------------------------------------------------------------