1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * LPC1700 support Copyright (C) 2009 by Audrius Urmanavicius *
6 * didele.deze@gmail.com *
8 * LPC1100 variant and auto-probing support Copyright (C) 2014 *
9 * by Cosmin Gorgovan cosmin [at] linux-geek [dot] org *
11 * LPC800/LPC1500/LPC54100 support Copyright (C) 2013/2014 *
12 * by Nemui Trinomius *
13 * nemuisan_kawausogasuki@live.jp *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
20 * This program is distributed in the hope that it will be useful, *
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23 * GNU General Public License for more details. *
25 * You should have received a copy of the GNU General Public License *
26 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
27 ***************************************************************************/
34 #include <helper/binarybuffer.h>
35 #include <target/algorithm.h>
36 #include <target/arm_opcodes.h>
37 #include <target/armv7m.h>
41 * flash programming support for NXP LPC8xx,LPC1xxx,LPC4xxx,LP5410x and LPC2xxx devices.
43 * @todo Provide a way to update CCLK after declaring the flash bank. The value which is correct after chip reset will
44 * rarely still work right after the clocks switch to use the PLL (e.g. 4MHz --> 100 MHz).
47 * currently supported devices:
48 * variant 1 (lpc2000_v1):
56 * variant 2 (lpc2000_v2):
65 * - 176x (tested with LPC1768)
67 * - 178x (tested with LPC1788)
69 * lpc4000: (lpc1700's alias)
71 * - 408x (tested with LPC4088)
73 * lpc4300: (also available as lpc1800 - alias)
74 * - 43x2 | 3 | 5 | 7 (tested with LPC4337/LPC4357)
78 * - 810 | 1 | 2 (tested with LPC810/LPC811/LPC812)
79 * - 822 | 4 (tested with LPC824)
87 * - 11Uxx (tested with LPC11U34)
92 * - 15x7 | 8 | 9 (tested with LPC1549)
95 * - 54101 | 2 (tested with LPC54102)
97 * The auto variant auto-detects parts from the following series:
116 /* Part IDs for autodetection */
117 /* A script which can automatically extract part ids from user manuals is available here:
118 * https://github.com/lgeek/lpc_part_ids
120 #define LPC1110_1 0x0A07102B
121 #define LPC1110_2 0x1A07102B
122 #define LPC1111_002_1 0x0A16D02B
123 #define LPC1111_002_2 0x1A16D02B
124 #define LPC1111_101_1 0x041E502B
125 #define LPC1111_101_2 0x2516D02B
126 #define LPC1111_103_1 0x00010013
127 #define LPC1111_201_1 0x0416502B
128 #define LPC1111_201_2 0x2516902B
129 #define LPC1111_203_1 0x00010012
130 #define LPC1112_101_1 0x042D502B
131 #define LPC1112_101_2 0x2524D02B
132 #define LPC1112_102_1 0x0A24902B
133 #define LPC1112_102_2 0x1A24902B
134 #define LPC1112_103_1 0x00020023
135 #define LPC1112_201_1 0x0425502B
136 #define LPC1112_201_2 0x2524902B
137 #define LPC1112_203_1 0x00020022
138 #define LPC1113_201_1 0x0434502B
139 #define LPC1113_201_2 0x2532902B
140 #define LPC1113_203_1 0x00030032
141 #define LPC1113_301_1 0x0434102B
142 #define LPC1113_301_2 0x2532102B
143 #define LPC1113_303_1 0x00030030
144 #define LPC1114_102_1 0x0A40902B
145 #define LPC1114_102_2 0x1A40902B
146 #define LPC1114_201_1 0x0444502B
147 #define LPC1114_201_2 0x2540902B
148 #define LPC1114_203_1 0x00040042
149 #define LPC1114_301_1 0x0444102B
150 #define LPC1114_301_2 0x2540102B
151 #define LPC1114_303_1 0x00040040
152 #define LPC1114_323_1 0x00040060
153 #define LPC1114_333_1 0x00040070
154 #define LPC1115_303_1 0x00050080
156 #define LPC11A02_1 0x4D4C802B
157 #define LPC11A04_1 0x4D80002B
158 #define LPC11A11_001_1 0x455EC02B
159 #define LPC11A12_101_1 0x4574802B
160 #define LPC11A13_201_1 0x458A402B
161 #define LPC11A14_301_1 0x35A0002B
162 #define LPC11A14_301_2 0x45A0002B
164 #define LPC11C12_301_1 0x1421102B
165 #define LPC11C14_301_1 0x1440102B
166 #define LPC11C22_301_1 0x1431102B
167 #define LPC11C24_301_1 0x1430102B
169 #define LPC11E11_101 0x293E902B
170 #define LPC11E12_201 0x2954502B
171 #define LPC11E13_301 0x296A102B
172 #define LPC11E14_401 0x2980102B
173 #define LPC11E36_501 0x00009C41
174 #define LPC11E37_401 0x00007C45
175 #define LPC11E37_501 0x00007C41
177 #define LPC11U12_201_1 0x095C802B
178 #define LPC11U12_201_2 0x295C802B
179 #define LPC11U13_201_1 0x097A802B
180 #define LPC11U13_201_2 0x297A802B
181 #define LPC11U14_201_1 0x0998802B
182 #define LPC11U14_201_2 0x2998802B
183 #define LPC11U23_301 0x2972402B
184 #define LPC11U24_301 0x2988402B
185 #define LPC11U24_401 0x2980002B
186 #define LPC11U34_311 0x0003D440
187 #define LPC11U34_421 0x0001CC40
188 #define LPC11U35_401 0x0001BC40
189 #define LPC11U35_501 0x0000BC40
190 #define LPC11U36_401 0x00019C40
191 #define LPC11U37_401 0x00017C40
192 #define LPC11U37H_401 0x00007C44
193 #define LPC11U37_501 0x00007C40
195 #define LPC11E66 0x0000DCC1
196 #define LPC11E67 0x0000BC81
197 #define LPC11E68 0x00007C01
199 #define LPC11U66 0x0000DCC8
200 #define LPC11U67_1 0x0000BC88
201 #define LPC11U67_2 0x0000BC80
202 #define LPC11U68_1 0x00007C08
203 #define LPC11U68_2 0x00007C00
205 #define LPC1311 0x2C42502B
206 #define LPC1311_1 0x1816902B
207 #define LPC1313 0x2C40102B
208 #define LPC1313_1 0x1830102B
209 #define LPC1315 0x3A010523
210 #define LPC1316 0x1A018524
211 #define LPC1317 0x1A020525
212 #define LPC1342 0x3D01402B
213 #define LPC1343 0x3D00002B
214 #define LPC1343_1 0x3000002B
215 #define LPC1345 0x28010541
216 #define LPC1346 0x08018542
217 #define LPC1347 0x08020543
219 #define LPC1751_1 0x25001110
220 #define LPC1751_2 0x25001118
221 #define LPC1752 0x25001121
222 #define LPC1754 0x25011722
223 #define LPC1756 0x25011723
224 #define LPC1758 0x25013F37
225 #define LPC1759 0x25113737
226 #define LPC1763 0x26012033
227 #define LPC1764 0x26011922
228 #define LPC1765 0x26013733
229 #define LPC1766 0x26013F33
230 #define LPC1767 0x26012837
231 #define LPC1768 0x26013F37
232 #define LPC1769 0x26113F37
233 #define LPC1774 0x27011132
234 #define LPC1776 0x27191F43
235 #define LPC1777 0x27193747
236 #define LPC1778 0x27193F47
237 #define LPC1785 0x281D1743
238 #define LPC1786 0x281D1F43
239 #define LPC1787 0x281D3747
240 #define LPC1788 0x281D3F47
242 #define LPC4072 0x47011121
243 #define LPC4074 0x47011132
244 #define LPC4076 0x47191F43
245 #define LPC4078 0x47193F47
246 #define LPC4088 0x481D3F47
248 #define LPC810_021 0x00008100
249 #define LPC811_001 0x00008110
250 #define LPC812_101 0x00008120
251 #define LPC812_101_1 0x00008121
252 #define LPC812_101_2 0x00008122
253 #define LPC812_101_3 0x00008123
255 #define LPC822_101 0x00008221
256 #define LPC822_101_1 0x00008222
257 #define LPC824_201 0x00008241
258 #define LPC824_201_1 0x00008242
260 #define IAP_CODE_LEN 0x34
274 struct lpc2000_flash_bank
{
275 lpc2000_variant variant
;
277 int cmd51_dst_boundary
;
279 uint32_t cmd51_max_buffer
;
281 uint32_t iap_max_stack
;
282 uint32_t lpc4300_bank
;
286 enum lpc2000_status_codes
{
287 LPC2000_CMD_SUCCESS
= 0,
288 LPC2000_INVALID_COMMAND
= 1,
289 LPC2000_SRC_ADDR_ERROR
= 2,
290 LPC2000_DST_ADDR_ERROR
= 3,
291 LPC2000_SRC_ADDR_NOT_MAPPED
= 4,
292 LPC2000_DST_ADDR_NOT_MAPPED
= 5,
293 LPC2000_COUNT_ERROR
= 6,
294 LPC2000_INVALID_SECTOR
= 7,
295 LPC2000_SECTOR_NOT_BLANK
= 8,
296 LPC2000_SECTOR_NOT_PREPARED
= 9,
297 LPC2000_COMPARE_ERROR
= 10,
299 LPC2000_PARAM_ERROR
= 12,
300 LPC2000_ADDR_ERROR
= 13,
301 LPC2000_ADDR_NOT_MAPPED
= 14,
302 LPC2000_CMD_NOT_LOCKED
= 15,
303 LPC2000_INVALID_CODE
= 16,
304 LPC2000_INVALID_BAUD_RATE
= 17,
305 LPC2000_INVALID_STOP_BIT
= 18,
306 LPC2000_CRP_ENABLED
= 19,
307 LPC2000_INVALID_FLASH_UNIT
= 20,
308 LPC2000_USER_CODE_CHECKSUM
= 21,
309 LCP2000_ERROR_SETTING_ACTIVE_PARTITION
= 22,
312 static int lpc2000_build_sector_list(struct flash_bank
*bank
)
314 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
317 /* default to a 4096 write buffer */
318 lpc2000_info
->cmd51_max_buffer
= 4096;
320 if (lpc2000_info
->variant
== lpc2000_v1
) {
321 lpc2000_info
->cmd51_dst_boundary
= 512;
322 lpc2000_info
->checksum_vector
= 5;
323 lpc2000_info
->iap_max_stack
= 128;
325 /* variant 1 has different layout for 128kb and 256kb flashes */
326 if (bank
->size
== 128 * 1024) {
327 bank
->num_sectors
= 16;
328 bank
->sectors
= malloc(sizeof(struct flash_sector
) * 16);
329 for (int i
= 0; i
< 16; i
++) {
330 bank
->sectors
[i
].offset
= offset
;
331 bank
->sectors
[i
].size
= 8 * 1024;
332 offset
+= bank
->sectors
[i
].size
;
333 bank
->sectors
[i
].is_erased
= -1;
334 bank
->sectors
[i
].is_protected
= 1;
336 } else if (bank
->size
== 256 * 1024) {
337 bank
->num_sectors
= 18;
338 bank
->sectors
= malloc(sizeof(struct flash_sector
) * 18);
340 for (int i
= 0; i
< 8; i
++) {
341 bank
->sectors
[i
].offset
= offset
;
342 bank
->sectors
[i
].size
= 8 * 1024;
343 offset
+= bank
->sectors
[i
].size
;
344 bank
->sectors
[i
].is_erased
= -1;
345 bank
->sectors
[i
].is_protected
= 1;
347 for (int i
= 8; i
< 10; i
++) {
348 bank
->sectors
[i
].offset
= offset
;
349 bank
->sectors
[i
].size
= 64 * 1024;
350 offset
+= bank
->sectors
[i
].size
;
351 bank
->sectors
[i
].is_erased
= -1;
352 bank
->sectors
[i
].is_protected
= 1;
354 for (int i
= 10; i
< 18; i
++) {
355 bank
->sectors
[i
].offset
= offset
;
356 bank
->sectors
[i
].size
= 8 * 1024;
357 offset
+= bank
->sectors
[i
].size
;
358 bank
->sectors
[i
].is_erased
= -1;
359 bank
->sectors
[i
].is_protected
= 1;
362 LOG_ERROR("BUG: unknown bank->size encountered");
365 } else if (lpc2000_info
->variant
== lpc2000_v2
) {
366 lpc2000_info
->cmd51_dst_boundary
= 256;
367 lpc2000_info
->checksum_vector
= 5;
368 lpc2000_info
->iap_max_stack
= 128;
370 /* variant 2 has a uniform layout, only number of sectors differs */
371 switch (bank
->size
) {
373 lpc2000_info
->cmd51_max_buffer
= 1024;
374 bank
->num_sectors
= 1;
377 lpc2000_info
->cmd51_max_buffer
= 1024;
378 bank
->num_sectors
= 2;
381 bank
->num_sectors
= 4;
384 bank
->num_sectors
= 8;
387 bank
->num_sectors
= 9;
390 bank
->num_sectors
= 11;
393 bank
->num_sectors
= 15;
396 bank
->num_sectors
= 27;
400 bank
->num_sectors
= 28;
403 LOG_ERROR("BUG: unknown bank->size encountered");
408 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
410 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
412 bank
->sectors
[i
].offset
= offset
;
413 bank
->sectors
[i
].size
= 4 * 1024;
414 offset
+= bank
->sectors
[i
].size
;
415 bank
->sectors
[i
].is_erased
= -1;
416 bank
->sectors
[i
].is_protected
= 1;
418 bank
->sectors
[i
].offset
= offset
;
419 bank
->sectors
[i
].size
= 32 * 1024;
420 offset
+= bank
->sectors
[i
].size
;
421 bank
->sectors
[i
].is_erased
= -1;
422 bank
->sectors
[i
].is_protected
= 1;
424 bank
->sectors
[i
].offset
= offset
;
425 bank
->sectors
[i
].size
= 4 * 1024;
426 offset
+= bank
->sectors
[i
].size
;
427 bank
->sectors
[i
].is_erased
= -1;
428 bank
->sectors
[i
].is_protected
= 1;
431 } else if (lpc2000_info
->variant
== lpc1700
) {
432 lpc2000_info
->cmd51_dst_boundary
= 256;
433 lpc2000_info
->checksum_vector
= 7;
434 lpc2000_info
->iap_max_stack
= 128;
436 switch (bank
->size
) {
438 lpc2000_info
->cmd51_max_buffer
= 256;
439 bank
->num_sectors
= 1;
442 lpc2000_info
->cmd51_max_buffer
= 512;
443 bank
->num_sectors
= 2;
446 lpc2000_info
->cmd51_max_buffer
= 512;
447 bank
->num_sectors
= 4;
450 lpc2000_info
->cmd51_max_buffer
= 1024;
451 bank
->num_sectors
= 8;
454 bank
->num_sectors
= 16;
457 bank
->num_sectors
= 18;
460 bank
->num_sectors
= 22;
463 bank
->num_sectors
= 30;
466 LOG_ERROR("BUG: unknown bank->size encountered");
470 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
472 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
473 bank
->sectors
[i
].offset
= offset
;
474 /* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx/LPC40xx devices */
475 bank
->sectors
[i
].size
= (i
< 16) ? 4 * 1024 : 32 * 1024;
476 offset
+= bank
->sectors
[i
].size
;
477 bank
->sectors
[i
].is_erased
= -1;
478 bank
->sectors
[i
].is_protected
= 1;
480 } else if (lpc2000_info
->variant
== lpc4300
) {
481 lpc2000_info
->cmd51_dst_boundary
= 512;
482 lpc2000_info
->checksum_vector
= 7;
483 lpc2000_info
->iap_max_stack
= 208;
485 switch (bank
->size
) {
487 bank
->num_sectors
= 11;
490 bank
->num_sectors
= 13;
493 bank
->num_sectors
= 15;
496 LOG_ERROR("BUG: unknown bank->size encountered");
500 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
502 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
503 bank
->sectors
[i
].offset
= offset
;
504 /* sectors 0-7 are 8kB-sized, 8 and above are 64kB-sized for LPC43xx devices */
505 bank
->sectors
[i
].size
= (i
< 8) ? 8 * 1024 : 64 * 1024;
506 offset
+= bank
->sectors
[i
].size
;
507 bank
->sectors
[i
].is_erased
= -1;
508 bank
->sectors
[i
].is_protected
= 1;
511 } else if (lpc2000_info
->variant
== lpc800
) {
512 lpc2000_info
->cmd51_dst_boundary
= 64;
513 lpc2000_info
->checksum_vector
= 7;
514 lpc2000_info
->iap_max_stack
= 208; /* 148byte for LPC81x,208byte for LPC82x. */
515 lpc2000_info
->cmd51_max_buffer
= 256; /* smallest MCU in the series, LPC810, has 1 kB of SRAM */
517 switch (bank
->size
) {
519 bank
->num_sectors
= 4;
522 bank
->num_sectors
= 8;
525 bank
->num_sectors
= 16;
528 lpc2000_info
->cmd51_max_buffer
= 1024; /* For LPC824, has 8kB of SRAM */
529 bank
->num_sectors
= 32;
532 LOG_ERROR("BUG: unknown bank->size encountered");
536 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
538 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
539 bank
->sectors
[i
].offset
= offset
;
540 /* all sectors are 1kB-sized for LPC8xx devices */
541 bank
->sectors
[i
].size
= 1 * 1024;
542 offset
+= bank
->sectors
[i
].size
;
543 bank
->sectors
[i
].is_erased
= -1;
544 bank
->sectors
[i
].is_protected
= 1;
547 } else if (lpc2000_info
->variant
== lpc1100
) {
548 lpc2000_info
->cmd51_dst_boundary
= 256;
549 lpc2000_info
->checksum_vector
= 7;
550 lpc2000_info
->iap_max_stack
= 128;
552 if ((bank
->size
% (4 * 1024)) != 0) {
553 LOG_ERROR("BUG: unknown bank->size encountered,\nLPC1100 flash size must be a multiple of 4096");
556 lpc2000_info
->cmd51_max_buffer
= 512; /* smallest MCU in the series, LPC1110, has 1 kB of SRAM */
557 bank
->num_sectors
= bank
->size
/ 4096;
559 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
561 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
562 bank
->sectors
[i
].offset
= offset
;
563 /* all sectors are 4kB-sized */
564 bank
->sectors
[i
].size
= 4 * 1024;
565 offset
+= bank
->sectors
[i
].size
;
566 bank
->sectors
[i
].is_erased
= -1;
567 bank
->sectors
[i
].is_protected
= 1;
570 } else if (lpc2000_info
->variant
== lpc1500
) {
571 lpc2000_info
->cmd51_dst_boundary
= 256;
572 lpc2000_info
->checksum_vector
= 7;
573 lpc2000_info
->iap_max_stack
= 128;
575 switch (bank
->size
) {
577 bank
->num_sectors
= 16;
580 bank
->num_sectors
= 32;
583 bank
->num_sectors
= 64;
586 LOG_ERROR("BUG: unknown bank->size encountered");
590 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
592 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
593 bank
->sectors
[i
].offset
= offset
;
594 /* all sectors are 4kB-sized */
595 bank
->sectors
[i
].size
= 4 * 1024;
596 offset
+= bank
->sectors
[i
].size
;
597 bank
->sectors
[i
].is_erased
= -1;
598 bank
->sectors
[i
].is_protected
= 1;
601 } else if (lpc2000_info
->variant
== lpc54100
) {
602 lpc2000_info
->cmd51_dst_boundary
= 256;
603 lpc2000_info
->checksum_vector
= 7;
604 lpc2000_info
->iap_max_stack
= 128;
606 switch (bank
->size
) {
608 bank
->num_sectors
= 8;
611 bank
->num_sectors
= 16;
614 LOG_ERROR("BUG: unknown bank->size encountered");
618 bank
->sectors
= malloc(sizeof(struct flash_sector
) * bank
->num_sectors
);
620 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
621 bank
->sectors
[i
].offset
= offset
;
622 /* all sectors are 32kB-sized */
623 bank
->sectors
[i
].size
= 32 * 1024;
624 offset
+= bank
->sectors
[i
].size
;
625 bank
->sectors
[i
].is_erased
= -1;
626 bank
->sectors
[i
].is_protected
= 1;
630 LOG_ERROR("BUG: unknown lpc2000_info->variant encountered");
637 /* this function allocates and initializes working area used for IAP algorithm
638 * uses 52 + max IAP stack bytes working area
639 * 0x0 to 0x7: jump gate (BX to thumb state, b -2 to wait)
640 * 0x8 to 0x1f: command parameter table (1+5 words)
641 * 0x20 to 0x33: command result table (1+4 words)
642 * 0x34 to 0xb3|0x104: stack
643 * (128b needed for lpc1xxx/2000/5410x, 208b for lpc43xx/lpc82x and 148b for lpc81x)
646 static int lpc2000_iap_working_area_init(struct flash_bank
*bank
, struct working_area
**iap_working_area
)
648 struct target
*target
= bank
->target
;
649 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
651 if (target_alloc_working_area(target
, IAP_CODE_LEN
+ lpc2000_info
->iap_max_stack
, iap_working_area
) != ERROR_OK
) {
652 LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
653 return ERROR_FLASH_OPERATION_FAILED
;
656 uint8_t jump_gate
[8];
658 /* write IAP code to working area */
659 switch (lpc2000_info
->variant
) {
667 target_buffer_set_u32(target
, jump_gate
, ARMV4_5_T_BX(12));
668 target_buffer_set_u32(target
, jump_gate
+ 4, ARMV5_T_BKPT(0));
672 target_buffer_set_u32(target
, jump_gate
, ARMV4_5_BX(12));
673 target_buffer_set_u32(target
, jump_gate
+ 4, ARMV4_5_B(0xfffffe, 0));
676 LOG_ERROR("BUG: unknown lpc2000_info->variant encountered");
680 int retval
= target_write_memory(target
, (*iap_working_area
)->address
, 4, 2, jump_gate
);
681 if (retval
!= ERROR_OK
) {
682 LOG_ERROR("Write memory at address 0x%8.8" PRIx32
" failed (check work_area definition)",
683 (*iap_working_area
)->address
);
684 target_free_working_area(target
, *iap_working_area
);
690 /* call LPC8xx/LPC1xxx/LPC4xxx/LPC5410x/LPC2000 IAP function */
692 static int lpc2000_iap_call(struct flash_bank
*bank
, struct working_area
*iap_working_area
, int code
,
693 uint32_t param_table
[5], uint32_t result_table
[4])
695 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
696 struct target
*target
= bank
->target
;
698 struct arm_algorithm arm_algo
; /* for LPC2000 */
699 struct armv7m_algorithm armv7m_info
; /* for LPC8xx/LPC1xxx/LPC4xxx/LPC5410x */
700 uint32_t iap_entry_point
= 0; /* to make compiler happier */
702 switch (lpc2000_info
->variant
) {
707 armv7m_info
.common_magic
= ARMV7M_COMMON_MAGIC
;
708 armv7m_info
.core_mode
= ARM_MODE_THREAD
;
709 iap_entry_point
= 0x1fff1ff1;
713 armv7m_info
.common_magic
= ARMV7M_COMMON_MAGIC
;
714 armv7m_info
.core_mode
= ARM_MODE_THREAD
;
715 iap_entry_point
= 0x03000205;
719 arm_algo
.common_magic
= ARM_COMMON_MAGIC
;
720 arm_algo
.core_mode
= ARM_MODE_SVC
;
721 arm_algo
.core_state
= ARM_STATE_ARM
;
722 iap_entry_point
= 0x7ffffff1;
725 armv7m_info
.common_magic
= ARMV7M_COMMON_MAGIC
;
726 armv7m_info
.core_mode
= ARM_MODE_THREAD
;
727 /* read out IAP entry point from ROM driver table at 0x10400100 */
728 target_read_u32(target
, 0x10400100, &iap_entry_point
);
731 LOG_ERROR("BUG: unknown lpc2000->variant encountered");
735 struct mem_param mem_params
[2];
737 /* command parameter table */
738 init_mem_param(&mem_params
[0], iap_working_area
->address
+ 8, 6 * 4, PARAM_OUT
);
739 target_buffer_set_u32(target
, mem_params
[0].value
, code
);
740 target_buffer_set_u32(target
, mem_params
[0].value
+ 0x04, param_table
[0]);
741 target_buffer_set_u32(target
, mem_params
[0].value
+ 0x08, param_table
[1]);
742 target_buffer_set_u32(target
, mem_params
[0].value
+ 0x0c, param_table
[2]);
743 target_buffer_set_u32(target
, mem_params
[0].value
+ 0x10, param_table
[3]);
744 target_buffer_set_u32(target
, mem_params
[0].value
+ 0x14, param_table
[4]);
746 struct reg_param reg_params
[5];
748 init_reg_param(®_params
[0], "r0", 32, PARAM_OUT
);
749 buf_set_u32(reg_params
[0].value
, 0, 32, iap_working_area
->address
+ 0x08);
751 /* command result table */
752 init_mem_param(&mem_params
[1], iap_working_area
->address
+ 0x20, 5 * 4, PARAM_IN
);
754 init_reg_param(®_params
[1], "r1", 32, PARAM_OUT
);
755 buf_set_u32(reg_params
[1].value
, 0, 32, iap_working_area
->address
+ 0x20);
757 /* IAP entry point */
758 init_reg_param(®_params
[2], "r12", 32, PARAM_OUT
);
759 buf_set_u32(reg_params
[2].value
, 0, 32, iap_entry_point
);
761 switch (lpc2000_info
->variant
) {
770 init_reg_param(®_params
[3], "sp", 32, PARAM_OUT
);
771 buf_set_u32(reg_params
[3].value
, 0, 32,
772 iap_working_area
->address
+ IAP_CODE_LEN
+ lpc2000_info
->iap_max_stack
);
775 init_reg_param(®_params
[4], "lr", 32, PARAM_OUT
);
776 buf_set_u32(reg_params
[4].value
, 0, 32, (iap_working_area
->address
+ 0x04) | 1);
777 /* bit0 of LR = 1 to return in Thumb mode */
779 target_run_algorithm(target
, 2, mem_params
, 5, reg_params
, iap_working_area
->address
, 0, 10000,
785 init_reg_param(®_params
[3], "sp_svc", 32, PARAM_OUT
);
786 buf_set_u32(reg_params
[3].value
, 0, 32,
787 iap_working_area
->address
+ IAP_CODE_LEN
+ lpc2000_info
->iap_max_stack
);
790 init_reg_param(®_params
[4], "lr_svc", 32, PARAM_OUT
);
791 buf_set_u32(reg_params
[4].value
, 0, 32, iap_working_area
->address
+ 0x04);
793 target_run_algorithm(target
, 2, mem_params
, 5, reg_params
, iap_working_area
->address
,
794 iap_working_area
->address
+ 0x4, 10000, &arm_algo
);
797 LOG_ERROR("BUG: unknown lpc2000->variant encountered");
801 int status_code
= target_buffer_get_u32(target
, mem_params
[1].value
);
802 result_table
[0] = target_buffer_get_u32(target
, mem_params
[1].value
+ 0x04);
803 result_table
[1] = target_buffer_get_u32(target
, mem_params
[1].value
+ 0x08);
804 result_table
[2] = target_buffer_get_u32(target
, mem_params
[1].value
+ 0x0c);
805 result_table
[3] = target_buffer_get_u32(target
, mem_params
[1].value
+ 0x10);
807 LOG_DEBUG("IAP command = %i (0x%8.8" PRIx32
", 0x%8.8" PRIx32
", 0x%8.8" PRIx32
", 0x%8.8" PRIx32
", 0x%8.8" PRIx32
808 ") completed with result = %8.8x",
809 code
, param_table
[0], param_table
[1], param_table
[2], param_table
[3], param_table
[4], status_code
);
811 destroy_mem_param(&mem_params
[0]);
812 destroy_mem_param(&mem_params
[1]);
814 destroy_reg_param(®_params
[0]);
815 destroy_reg_param(®_params
[1]);
816 destroy_reg_param(®_params
[2]);
817 destroy_reg_param(®_params
[3]);
818 destroy_reg_param(®_params
[4]);
823 static int lpc2000_iap_blank_check(struct flash_bank
*bank
, int first
, int last
)
825 if ((first
< 0) || (last
>= bank
->num_sectors
))
826 return ERROR_FLASH_SECTOR_INVALID
;
828 uint32_t param_table
[5] = {0};
829 uint32_t result_table
[4];
830 struct working_area
*iap_working_area
;
832 int retval
= lpc2000_iap_working_area_init(bank
, &iap_working_area
);
834 if (retval
!= ERROR_OK
)
837 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
838 if (lpc2000_info
->variant
== lpc4300
)
839 param_table
[2] = lpc2000_info
->lpc4300_bank
;
841 for (int i
= first
; i
<= last
&& retval
== ERROR_OK
; i
++) {
842 /* check single sector */
843 param_table
[0] = param_table
[1] = i
;
844 int status_code
= lpc2000_iap_call(bank
, iap_working_area
, 53, param_table
, result_table
);
846 switch (status_code
) {
847 case ERROR_FLASH_OPERATION_FAILED
:
848 retval
= ERROR_FLASH_OPERATION_FAILED
;
850 case LPC2000_CMD_SUCCESS
:
851 bank
->sectors
[i
].is_erased
= 1;
853 case LPC2000_SECTOR_NOT_BLANK
:
854 bank
->sectors
[i
].is_erased
= 0;
856 case LPC2000_INVALID_SECTOR
:
857 bank
->sectors
[i
].is_erased
= 0;
860 retval
= ERROR_FLASH_BUSY
;
863 LOG_ERROR("BUG: unknown LPC2000 status code %i", status_code
);
868 struct target
*target
= bank
->target
;
869 target_free_working_area(target
, iap_working_area
);
875 * flash bank lpc2000 <base> <size> 0 0 <target#> <lpc_variant> <cclk> [calc_checksum]
877 FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command
)
880 return ERROR_COMMAND_SYNTAX_ERROR
;
882 struct lpc2000_flash_bank
*lpc2000_info
= calloc(1, sizeof(*lpc2000_info
));
883 lpc2000_info
->probed
= false;
885 bank
->driver_priv
= lpc2000_info
;
887 if (strcmp(CMD_ARGV
[6], "lpc2000_v1") == 0) {
888 lpc2000_info
->variant
= lpc2000_v1
;
889 } else if (strcmp(CMD_ARGV
[6], "lpc2000_v2") == 0) {
890 lpc2000_info
->variant
= lpc2000_v2
;
891 } else if (strcmp(CMD_ARGV
[6], "lpc1700") == 0 || strcmp(CMD_ARGV
[6], "lpc4000") == 0) {
892 lpc2000_info
->variant
= lpc1700
;
893 } else if (strcmp(CMD_ARGV
[6], "lpc1800") == 0 || strcmp(CMD_ARGV
[6], "lpc4300") == 0) {
894 lpc2000_info
->variant
= lpc4300
;
895 } else if (strcmp(CMD_ARGV
[6], "lpc800") == 0) {
896 lpc2000_info
->variant
= lpc800
;
897 } else if (strcmp(CMD_ARGV
[6], "lpc1100") == 0) {
898 lpc2000_info
->variant
= lpc1100
;
899 } else if (strcmp(CMD_ARGV
[6], "lpc1500") == 0) {
900 lpc2000_info
->variant
= lpc1500
;
901 } else if (strcmp(CMD_ARGV
[6], "lpc54100") == 0) {
902 lpc2000_info
->variant
= lpc54100
;
903 } else if (strcmp(CMD_ARGV
[6], "auto") == 0) {
904 lpc2000_info
->variant
= lpc_auto
;
906 LOG_ERROR("unknown LPC2000 variant: %s", CMD_ARGV
[6]);
908 return ERROR_FLASH_BANK_INVALID
;
911 /* Maximum size required for the IAP stack.
912 This value only gets used when probing, only for auto, lpc1100 and lpc1700.
913 We use the maximum size for any part supported by the driver(!) to be safe
914 in case the auto variant is mistakenly used on a MCU from one of the series
915 for which we don't support auto-probing. */
916 lpc2000_info
->iap_max_stack
= 208;
918 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[7], lpc2000_info
->cclk
);
919 lpc2000_info
->calc_checksum
= 0;
921 uint32_t temp_base
= 0;
922 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], temp_base
);
923 if (temp_base
>= 0x1B000000)
924 lpc2000_info
->lpc4300_bank
= 1; /* bank B */
926 lpc2000_info
->lpc4300_bank
= 0; /* bank A */
929 if (strcmp(CMD_ARGV
[8], "calc_checksum") == 0)
930 lpc2000_info
->calc_checksum
= 1;
936 static int lpc2000_erase(struct flash_bank
*bank
, int first
, int last
)
938 if (bank
->target
->state
!= TARGET_HALTED
) {
939 LOG_ERROR("Target not halted");
940 return ERROR_TARGET_NOT_HALTED
;
943 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
944 uint32_t param_table
[5] = {0};
946 param_table
[0] = first
;
947 param_table
[1] = last
;
949 if (lpc2000_info
->variant
== lpc4300
)
950 param_table
[2] = lpc2000_info
->lpc4300_bank
;
952 param_table
[2] = lpc2000_info
->cclk
;
954 uint32_t result_table
[4];
955 struct working_area
*iap_working_area
;
957 int retval
= lpc2000_iap_working_area_init(bank
, &iap_working_area
);
959 if (retval
!= ERROR_OK
)
962 if (lpc2000_info
->variant
== lpc4300
)
963 /* Init IAP Anyway */
964 lpc2000_iap_call(bank
, iap_working_area
, 49, param_table
, result_table
);
966 /* Prepare sectors */
967 int status_code
= lpc2000_iap_call(bank
, iap_working_area
, 50, param_table
, result_table
);
968 switch (status_code
) {
969 case ERROR_FLASH_OPERATION_FAILED
:
970 retval
= ERROR_FLASH_OPERATION_FAILED
;
972 case LPC2000_CMD_SUCCESS
:
974 case LPC2000_INVALID_SECTOR
:
975 retval
= ERROR_FLASH_SECTOR_INVALID
;
978 LOG_WARNING("lpc2000 prepare sectors returned %i", status_code
);
979 retval
= ERROR_FLASH_OPERATION_FAILED
;
983 if (retval
== ERROR_OK
) {
985 param_table
[2] = lpc2000_info
->cclk
;
986 if (lpc2000_info
->variant
== lpc4300
)
987 param_table
[3] = lpc2000_info
->lpc4300_bank
;
989 status_code
= lpc2000_iap_call(bank
, iap_working_area
, 52, param_table
, result_table
);
990 switch (status_code
) {
991 case ERROR_FLASH_OPERATION_FAILED
:
992 retval
= ERROR_FLASH_OPERATION_FAILED
;
994 case LPC2000_CMD_SUCCESS
:
996 case LPC2000_INVALID_SECTOR
:
997 retval
= ERROR_FLASH_SECTOR_INVALID
;
1000 LOG_WARNING("lpc2000 erase sectors returned %i", status_code
);
1001 retval
= ERROR_FLASH_OPERATION_FAILED
;
1006 struct target
*target
= bank
->target
;
1007 target_free_working_area(target
, iap_working_area
);
1012 static int lpc2000_protect(struct flash_bank
*bank
, int set
, int first
, int last
)
1014 /* can't protect/unprotect on the lpc2000 */
1018 static int lpc2000_write(struct flash_bank
*bank
, const uint8_t *buffer
, uint32_t offset
, uint32_t count
)
1020 struct target
*target
= bank
->target
;
1022 if (bank
->target
->state
!= TARGET_HALTED
) {
1023 LOG_ERROR("Target not halted");
1024 return ERROR_TARGET_NOT_HALTED
;
1027 if (offset
+ count
> bank
->size
)
1028 return ERROR_FLASH_DST_OUT_OF_BANK
;
1030 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
1032 uint32_t dst_min_alignment
= lpc2000_info
->cmd51_dst_boundary
;
1034 if (offset
% dst_min_alignment
) {
1035 LOG_WARNING("offset 0x%" PRIx32
" breaks required alignment 0x%" PRIx32
, offset
, dst_min_alignment
);
1036 return ERROR_FLASH_DST_BREAKS_ALIGNMENT
;
1039 int first_sector
= 0;
1040 int last_sector
= 0;
1042 for (int i
= 0; i
< bank
->num_sectors
; i
++) {
1043 if (offset
>= bank
->sectors
[i
].offset
)
1045 if (offset
+ DIV_ROUND_UP(count
, dst_min_alignment
) * dst_min_alignment
> bank
->sectors
[i
].offset
)
1049 LOG_DEBUG("first_sector: %i, last_sector: %i", first_sector
, last_sector
);
1051 /* check if exception vectors should be flashed */
1052 if ((offset
== 0) && (count
>= 0x20) && lpc2000_info
->calc_checksum
) {
1053 assert(lpc2000_info
->checksum_vector
< 8);
1054 uint32_t checksum
= 0;
1055 for (int i
= 0; i
< 8; i
++) {
1056 LOG_DEBUG("Vector 0x%2.2x: 0x%8.8" PRIx32
, i
* 4, buf_get_u32(buffer
+ (i
* 4), 0, 32));
1057 if (i
!= lpc2000_info
->checksum_vector
)
1058 checksum
+= buf_get_u32(buffer
+ (i
* 4), 0, 32);
1060 checksum
= 0 - checksum
;
1061 LOG_DEBUG("checksum: 0x%8.8" PRIx32
, checksum
);
1063 uint32_t original_value
= buf_get_u32(buffer
+ (lpc2000_info
->checksum_vector
* 4), 0, 32);
1064 if (original_value
!= checksum
) {
1065 LOG_WARNING("Verification will fail since checksum in image (0x%8.8" PRIx32
") to be written to flash is "
1066 "different from calculated vector checksum (0x%8.8" PRIx32
").", original_value
, checksum
);
1067 LOG_WARNING("To remove this warning modify build tools on developer PC to inject correct LPC vector "
1071 /* FIXME: WARNING! This code is broken because it modifies the callers buffer in place. */
1072 buf_set_u32((uint8_t *)buffer
+ (lpc2000_info
->checksum_vector
* 4), 0, 32, checksum
);
1075 struct working_area
*iap_working_area
;
1077 int retval
= lpc2000_iap_working_area_init(bank
, &iap_working_area
);
1079 if (retval
!= ERROR_OK
)
1082 struct working_area
*download_area
;
1084 /* allocate a working area */
1085 if (target_alloc_working_area(target
, lpc2000_info
->cmd51_max_buffer
, &download_area
) != ERROR_OK
) {
1086 LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
1087 target_free_working_area(target
, iap_working_area
);
1088 return ERROR_FLASH_OPERATION_FAILED
;
1091 uint32_t bytes_remaining
= count
;
1092 uint32_t bytes_written
= 0;
1093 uint32_t param_table
[5] = {0};
1094 uint32_t result_table
[4];
1096 if (lpc2000_info
->variant
== lpc4300
)
1097 /* Init IAP Anyway */
1098 lpc2000_iap_call(bank
, iap_working_area
, 49, param_table
, result_table
);
1100 while (bytes_remaining
> 0) {
1101 uint32_t thisrun_bytes
;
1102 if (bytes_remaining
>= lpc2000_info
->cmd51_max_buffer
)
1103 thisrun_bytes
= lpc2000_info
->cmd51_max_buffer
;
1105 thisrun_bytes
= lpc2000_info
->cmd51_dst_boundary
;
1107 /* Prepare sectors */
1108 param_table
[0] = first_sector
;
1109 param_table
[1] = last_sector
;
1111 if (lpc2000_info
->variant
== lpc4300
)
1112 param_table
[2] = lpc2000_info
->lpc4300_bank
;
1114 param_table
[2] = lpc2000_info
->cclk
;
1116 int status_code
= lpc2000_iap_call(bank
, iap_working_area
, 50, param_table
, result_table
);
1117 switch (status_code
) {
1118 case ERROR_FLASH_OPERATION_FAILED
:
1119 retval
= ERROR_FLASH_OPERATION_FAILED
;
1121 case LPC2000_CMD_SUCCESS
:
1123 case LPC2000_INVALID_SECTOR
:
1124 retval
= ERROR_FLASH_SECTOR_INVALID
;
1127 LOG_WARNING("lpc2000 prepare sectors returned %i", status_code
);
1128 retval
= ERROR_FLASH_OPERATION_FAILED
;
1132 /* Exit if error occured */
1133 if (retval
!= ERROR_OK
)
1136 if (bytes_remaining
>= thisrun_bytes
) {
1137 retval
= target_write_buffer(bank
->target
, download_area
->address
, thisrun_bytes
, buffer
+ bytes_written
);
1138 if (retval
!= ERROR_OK
) {
1139 retval
= ERROR_FLASH_OPERATION_FAILED
;
1143 uint8_t *last_buffer
= malloc(thisrun_bytes
);
1144 memcpy(last_buffer
, buffer
+ bytes_written
, bytes_remaining
);
1145 memset(last_buffer
+ bytes_remaining
, 0xff, thisrun_bytes
- bytes_remaining
);
1146 target_write_buffer(bank
->target
, download_area
->address
, thisrun_bytes
, last_buffer
);
1150 LOG_DEBUG("writing 0x%" PRIx32
" bytes to address 0x%" PRIx32
, thisrun_bytes
,
1151 bank
->base
+ offset
+ bytes_written
);
1154 param_table
[0] = bank
->base
+ offset
+ bytes_written
;
1155 param_table
[1] = download_area
->address
;
1156 param_table
[2] = thisrun_bytes
;
1157 param_table
[3] = lpc2000_info
->cclk
;
1158 status_code
= lpc2000_iap_call(bank
, iap_working_area
, 51, param_table
, result_table
);
1159 switch (status_code
) {
1160 case ERROR_FLASH_OPERATION_FAILED
:
1161 retval
= ERROR_FLASH_OPERATION_FAILED
;
1163 case LPC2000_CMD_SUCCESS
:
1165 case LPC2000_INVALID_SECTOR
:
1166 retval
= ERROR_FLASH_SECTOR_INVALID
;
1169 LOG_WARNING("lpc2000 returned %i", status_code
);
1170 retval
= ERROR_FLASH_OPERATION_FAILED
;
1174 /* Exit if error occured */
1175 if (retval
!= ERROR_OK
)
1178 if (bytes_remaining
> thisrun_bytes
)
1179 bytes_remaining
-= thisrun_bytes
;
1181 bytes_remaining
= 0;
1182 bytes_written
+= thisrun_bytes
;
1185 target_free_working_area(target
, iap_working_area
);
1186 target_free_working_area(target
, download_area
);
1191 static int get_lpc2000_part_id(struct flash_bank
*bank
, uint32_t *part_id
)
1193 if (bank
->target
->state
!= TARGET_HALTED
) {
1194 LOG_ERROR("Target not halted");
1195 return ERROR_TARGET_NOT_HALTED
;
1198 uint32_t param_table
[5] = {0};
1199 uint32_t result_table
[4];
1200 struct working_area
*iap_working_area
;
1202 int retval
= lpc2000_iap_working_area_init(bank
, &iap_working_area
);
1204 if (retval
!= ERROR_OK
)
1207 /* The status seems to be bogus with the part ID command on some IAP
1208 firmwares, so ignore it. */
1209 lpc2000_iap_call(bank
, iap_working_area
, 54, param_table
, result_table
);
1211 struct target
*target
= bank
->target
;
1212 target_free_working_area(target
, iap_working_area
);
1214 /* If the result is zero, the command probably didn't work out. */
1215 if (result_table
[0] == 0)
1216 return LPC2000_INVALID_COMMAND
;
1218 *part_id
= result_table
[0];
1219 return LPC2000_CMD_SUCCESS
;
1222 static int lpc2000_auto_probe_flash(struct flash_bank
*bank
)
1226 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
1228 if (bank
->target
->state
!= TARGET_HALTED
) {
1229 LOG_ERROR("Target not halted");
1230 return ERROR_TARGET_NOT_HALTED
;
1233 retval
= get_lpc2000_part_id(bank
, &part_id
);
1234 if (retval
!= LPC2000_CMD_SUCCESS
) {
1235 LOG_ERROR("Could not get part ID");
1242 lpc2000_info
->variant
= lpc1100
;
1243 bank
->size
= 4 * 1024;
1254 case LPC11A11_001_1
:
1258 lpc2000_info
->variant
= lpc1100
;
1259 bank
->size
= 8 * 1024;
1271 case LPC11C12_301_1
:
1272 case LPC11C22_301_1
:
1273 case LPC11A12_101_1
:
1275 case LPC11U12_201_1
:
1276 case LPC11U12_201_2
:
1278 lpc2000_info
->variant
= lpc1100
;
1279 bank
->size
= 16 * 1024;
1288 case LPC11A13_201_1
:
1290 case LPC11U13_201_1
:
1291 case LPC11U13_201_2
:
1293 lpc2000_info
->variant
= lpc1100
;
1294 bank
->size
= 24 * 1024;
1306 case LPC11A14_301_1
:
1307 case LPC11A14_301_2
:
1308 case LPC11C14_301_1
:
1309 case LPC11C24_301_1
:
1311 case LPC11U14_201_1
:
1312 case LPC11U14_201_2
:
1321 lpc2000_info
->variant
= lpc1100
;
1322 bank
->size
= 32 * 1024;
1327 lpc2000_info
->variant
= lpc1700
;
1328 bank
->size
= 32 * 1024;
1332 lpc2000_info
->variant
= lpc1100
;
1333 bank
->size
= 40 * 1024;
1340 lpc2000_info
->variant
= lpc1100
;
1341 bank
->size
= 48 * 1024;
1345 lpc2000_info
->variant
= lpc1100
;
1346 bank
->size
= 56 * 1024;
1356 lpc2000_info
->variant
= lpc1100
;
1357 bank
->size
= 64 * 1024;
1362 lpc2000_info
->variant
= lpc1700
;
1363 bank
->size
= 64 * 1024;
1368 lpc2000_info
->variant
= lpc1100
;
1369 bank
->size
= 96 * 1024;
1381 lpc2000_info
->variant
= lpc1100
;
1382 bank
->size
= 128 * 1024;
1389 lpc2000_info
->variant
= lpc1700
;
1390 bank
->size
= 128 * 1024;
1395 lpc2000_info
->variant
= lpc1100
;
1396 bank
->size
= 256 * 1024;
1407 lpc2000_info
->variant
= lpc1700
;
1408 bank
->size
= 256 * 1024;
1422 lpc2000_info
->variant
= lpc1700
;
1423 bank
->size
= 512 * 1024;
1427 lpc2000_info
->variant
= lpc800
;
1428 bank
->size
= 4 * 1024;
1432 lpc2000_info
->variant
= lpc800
;
1433 bank
->size
= 8 * 1024;
1442 lpc2000_info
->variant
= lpc800
;
1443 bank
->size
= 16 * 1024;
1448 lpc2000_info
->variant
= lpc800
;
1449 bank
->size
= 32 * 1024;
1453 LOG_ERROR("BUG: unknown Part ID encountered: 0x%" PRIx32
, part_id
);
1460 static int lpc2000_probe(struct flash_bank
*bank
)
1464 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
1466 if (!lpc2000_info
->probed
) {
1467 if (lpc2000_info
->variant
== lpc_auto
) {
1468 status
= lpc2000_auto_probe_flash(bank
);
1469 if (status
!= ERROR_OK
)
1471 } else if (lpc2000_info
->variant
== lpc1100
|| lpc2000_info
->variant
== lpc1700
) {
1472 status
= get_lpc2000_part_id(bank
, &part_id
);
1473 if (status
== LPC2000_CMD_SUCCESS
)
1474 LOG_INFO("If auto-detection fails for this part, please email "
1475 "openocd-devel@lists.sourceforge.net, citing part id 0x%" PRIx32
".\n", part_id
);
1478 lpc2000_build_sector_list(bank
);
1479 lpc2000_info
->probed
= true;
1485 static int lpc2000_erase_check(struct flash_bank
*bank
)
1487 if (bank
->target
->state
!= TARGET_HALTED
) {
1488 LOG_ERROR("Target not halted");
1489 return ERROR_TARGET_NOT_HALTED
;
1492 return lpc2000_iap_blank_check(bank
, 0, bank
->num_sectors
- 1);
1495 static int lpc2000_protect_check(struct flash_bank
*bank
)
1497 /* sectors are always protected */
1501 static int get_lpc2000_info(struct flash_bank
*bank
, char *buf
, int buf_size
)
1503 struct lpc2000_flash_bank
*lpc2000_info
= bank
->driver_priv
;
1505 snprintf(buf
, buf_size
, "lpc2000 flash driver variant: %i, clk: %" PRIi32
"kHz", lpc2000_info
->variant
,
1506 lpc2000_info
->cclk
);
1511 COMMAND_HANDLER(lpc2000_handle_part_id_command
)
1514 return ERROR_COMMAND_SYNTAX_ERROR
;
1516 struct flash_bank
*bank
;
1517 int retval
= CALL_COMMAND_HANDLER(flash_command_get_bank
, 0, &bank
);
1518 if (ERROR_OK
!= retval
)
1521 if (bank
->target
->state
!= TARGET_HALTED
) {
1522 LOG_ERROR("Target not halted");
1523 return ERROR_TARGET_NOT_HALTED
;
1527 int status_code
= get_lpc2000_part_id(bank
, &part_id
);
1528 if (status_code
!= 0x0) {
1529 if (status_code
== ERROR_FLASH_OPERATION_FAILED
) {
1530 command_print(CMD_CTX
, "no sufficient working area specified, can't access LPC2000 IAP interface");
1532 command_print(CMD_CTX
, "lpc2000 IAP returned status code %i", status_code
);
1534 command_print(CMD_CTX
, "lpc2000 part id: 0x%8.8" PRIx32
, part_id
);
1539 static const struct command_registration lpc2000_exec_command_handlers
[] = {
1542 .handler
= lpc2000_handle_part_id_command
,
1543 .mode
= COMMAND_EXEC
,
1544 .help
= "print part id of lpc2000 flash bank <num>",
1547 COMMAND_REGISTRATION_DONE
1549 static const struct command_registration lpc2000_command_handlers
[] = {
1552 .mode
= COMMAND_ANY
,
1553 .help
= "lpc2000 flash command group",
1555 .chain
= lpc2000_exec_command_handlers
,
1557 COMMAND_REGISTRATION_DONE
1560 struct flash_driver lpc2000_flash
= {
1562 .commands
= lpc2000_command_handlers
,
1563 .flash_bank_command
= lpc2000_flash_bank_command
,
1564 .erase
= lpc2000_erase
,
1565 .protect
= lpc2000_protect
,
1566 .write
= lpc2000_write
,
1567 .read
= default_flash_read
,
1568 .probe
= lpc2000_probe
,
1569 .auto_probe
= lpc2000_probe
,
1570 .erase_check
= lpc2000_erase_check
,
1571 .protect_check
= lpc2000_protect_check
,
1572 .info
= get_lpc2000_info
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)