OpenOCD
lpc2000.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * LPC1700 support Copyright (C) 2009 by Audrius Urmanavicius *
8  * didele.deze@gmail.com *
9  * *
10  * LPC1100 variant and auto-probing support Copyright (C) 2014 *
11  * by Cosmin Gorgovan cosmin [at] linux-geek [dot] org *
12  * *
13  * LPC800/LPC1500/LPC54100 support Copyright (C) 2013/2014 *
14  * by Nemui Trinomius *
15  * nemuisan_kawausogasuki@live.jp *
16  * *
17  * LPC8N04/HNS31xx support Copyright (C) 2018 *
18  * by Jean-Christian de Rivaz jcdr [at] innodelec [dot] ch *
19  ***************************************************************************/
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "imp.h"
26 #include <helper/binarybuffer.h>
27 #include <target/algorithm.h>
28 #include <target/arm_opcodes.h>
29 #include <target/armv7m.h>
30 
38 /*
39  * currently supported devices:
40  * variant 1 (lpc2000_v1):
41  * - 2104 | 5 | 6
42  * - 2114 | 9
43  * - 2124 | 9
44  * - 2194
45  * - 2212 | 4
46  * - 2292 | 4
47  *
48  * variant 2 (lpc2000_v2):
49  * - 213x
50  * - 214x
51  * - 2101 | 2 | 3
52  * - 2364 | 6 | 8
53  * - 2378
54  *
55  * lpc1700:
56  * - 175x
57  * - 176x (tested with LPC1768)
58  * - 177x
59  * - 178x (tested with LPC1788)
60  *
61  * lpc4000: (lpc1700's alias)
62  * - 407x
63  * - 408x (tested with LPC4088)
64  *
65  * lpc4300: (also available as lpc1800 - alias)
66  * - 43x2 | 3 | 5 | 7 (tested with LPC4337/LPC4357)
67  * - 18x2 | 3 | 5 | 7
68  *
69  * lpc800:
70  * - 810 | 1 | 2 (tested with LPC810/LPC811/LPC812)
71  * - 822 | 4 (tested with LPC824)
72  * - 8N04
73  * - NHS31xx (tested with NHS3100)
74  * - 844 | 5 (tested with LPC845)
75  *
76  * lpc1100:
77  * - 11xx
78  * - 11Axx
79  * - 11Cxx
80  * - 11Dxx
81  * - 11Exx
82  * - 11Uxx (tested with LPC11U34)
83  * - 131x
84  * - 134x
85  *
86  * lpc1500:
87  * - 15x7 | 8 | 9 (tested with LPC1549)
88  *
89  * lpc54100:
90  * - 54101 | 2 (tested with LPC54102)
91  *
92  * The auto variant auto-detects parts from the following series:
93  * - 11xx
94  * - 11Axx
95  * - 11Cxx
96  * - 11Dxx
97  * - 11Exx
98  * - 11Uxx
99  * - 131x
100  * - 134x
101  * - 175x
102  * - 176x
103  * - 177x
104  * - 178x
105  * - 407x
106  * - 408x
107  * - 81x
108  * - 82x
109  * - 8N04
110  * - NHS31xx
111  */
112 
113 /* Part IDs for autodetection */
114 /* A script which can automatically extract part ids from user manuals is available here:
115  * https://github.com/lgeek/lpc_part_ids
116  */
117 #define LPC1110_1 0x0A07102B
118 #define LPC1110_2 0x1A07102B
119 #define LPC1111_002_1 0x0A16D02B
120 #define LPC1111_002_2 0x1A16D02B
121 #define LPC1111_101_1 0x041E502B
122 #define LPC1111_101_2 0x2516D02B
123 #define LPC1111_103_1 0x00010013
124 #define LPC1111_201_1 0x0416502B
125 #define LPC1111_201_2 0x2516902B
126 #define LPC1111_203_1 0x00010012
127 #define LPC1112_101_1 0x042D502B
128 #define LPC1112_101_2 0x2524D02B
129 #define LPC1112_102_1 0x0A24902B
130 #define LPC1112_102_2 0x1A24902B
131 #define LPC1112_103_1 0x00020023
132 #define LPC1112_201_1 0x0425502B
133 #define LPC1112_201_2 0x2524902B
134 #define LPC1112_203_1 0x00020022
135 #define LPC1113_201_1 0x0434502B
136 #define LPC1113_201_2 0x2532902B
137 #define LPC1113_203_1 0x00030032
138 #define LPC1113_301_1 0x0434102B
139 #define LPC1113_301_2 0x2532102B
140 #define LPC1113_303_1 0x00030030
141 #define LPC1114_102_1 0x0A40902B
142 #define LPC1114_102_2 0x1A40902B
143 #define LPC1114_201_1 0x0444502B
144 #define LPC1114_201_2 0x2540902B
145 #define LPC1114_203_1 0x00040042
146 #define LPC1114_301_1 0x0444102B
147 #define LPC1114_301_2 0x2540102B
148 #define LPC1114_303_1 0x00040040
149 #define LPC1114_323_1 0x00040060
150 #define LPC1114_333_1 0x00040070
151 #define LPC1115_303_1 0x00050080
152 
153 #define LPC11A02_1 0x4D4C802B
154 #define LPC11A04_1 0x4D80002B
155 #define LPC11A11_001_1 0x455EC02B
156 #define LPC11A12_101_1 0x4574802B
157 #define LPC11A13_201_1 0x458A402B
158 #define LPC11A14_301_1 0x35A0002B
159 #define LPC11A14_301_2 0x45A0002B
160 
161 #define LPC11C12_301_1 0x1421102B
162 #define LPC11C14_301_1 0x1440102B
163 #define LPC11C22_301_1 0x1431102B
164 #define LPC11C24_301_1 0x1430102B
165 
166 #define LPC11E11_101 0x293E902B
167 #define LPC11E12_201 0x2954502B
168 #define LPC11E13_301 0x296A102B
169 #define LPC11E14_401 0x2980102B
170 #define LPC11E36_501 0x00009C41
171 #define LPC11E37_401 0x00007C45
172 #define LPC11E37_501 0x00007C41
173 
174 #define LPC11U12_201_1 0x095C802B
175 #define LPC11U12_201_2 0x295C802B
176 #define LPC11U13_201_1 0x097A802B
177 #define LPC11U13_201_2 0x297A802B
178 #define LPC11U14_201_1 0x0998802B
179 #define LPC11U14_201_2 0x2998802B
180 #define LPC11U23_301 0x2972402B
181 #define LPC11U24_301 0x2988402B
182 #define LPC11U24_401 0x2980002B
183 #define LPC11U34_311 0x0003D440
184 #define LPC11U34_421 0x0001CC40
185 #define LPC11U35_401 0x0001BC40
186 #define LPC11U35_501 0x0000BC40
187 #define LPC11U36_401 0x00019C40
188 #define LPC11U37_401 0x00017C40
189 #define LPC11U37H_401 0x00007C44
190 #define LPC11U37_501 0x00007C40
191 
192 #define LPC11E66 0x0000DCC1
193 #define LPC11E67 0x0000BC81
194 #define LPC11E68 0x00007C01
195 
196 #define LPC11U66 0x0000DCC8
197 #define LPC11U67_1 0x0000BC88
198 #define LPC11U67_2 0x0000BC80
199 #define LPC11U68_1 0x00007C08
200 #define LPC11U68_2 0x00007C00
201 
202 #define LPC1311 0x2C42502B
203 #define LPC1311_1 0x1816902B
204 #define LPC1313 0x2C40102B
205 #define LPC1313_1 0x1830102B
206 #define LPC1315 0x3A010523
207 #define LPC1316 0x1A018524
208 #define LPC1317 0x1A020525
209 #define LPC1342 0x3D01402B
210 #define LPC1343 0x3D00002B
211 #define LPC1343_1 0x3000002B
212 #define LPC1345 0x28010541
213 #define LPC1346 0x08018542
214 #define LPC1347 0x08020543
215 
216 #define LPC1751_1 0x25001110
217 #define LPC1751_2 0x25001118
218 #define LPC1752 0x25001121
219 #define LPC1754 0x25011722
220 #define LPC1756 0x25011723
221 #define LPC1758 0x25013F37
222 #define LPC1759 0x25113737
223 #define LPC1763 0x26012033
224 #define LPC1764 0x26011922
225 #define LPC1765 0x26013733
226 #define LPC1766 0x26013F33
227 #define LPC1767 0x26012837
228 #define LPC1768 0x26013F37
229 #define LPC1769 0x26113F37
230 #define LPC1774 0x27011132
231 #define LPC1776 0x27191F43
232 #define LPC1777 0x27193747
233 #define LPC1778 0x27193F47
234 #define LPC1785 0x281D1743
235 #define LPC1786 0x281D1F43
236 #define LPC1787 0x281D3747
237 #define LPC1788 0x281D3F47
238 
239 #define LPC4072 0x47011121
240 #define LPC4074 0x47011132
241 #define LPC4076 0x47191F43
242 #define LPC4078 0x47193F47
243 #define LPC4088 0x481D3F47
244 
245 #define LPC810_021 0x00008100
246 #define LPC811_001 0x00008110
247 #define LPC812_101 0x00008120
248 #define LPC812_101_1 0x00008121
249 #define LPC812_101_2 0x00008122
250 #define LPC812_101_3 0x00008123
251 
252 #define LPC822_101 0x00008221
253 #define LPC822_101_1 0x00008222
254 #define LPC824_201 0x00008241
255 #define LPC824_201_1 0x00008242
256 
257 #define LPC8N04 0x00008A04
258 #define NHS3100 0x4e310020
259 #define NHS3152 0x4e315220
260 #define NHS3153 0x4e315320 /* Only specified in Rev.1 of the datasheet */
261 
262 #define LPC844_201 0x00008441
263 #define LPC844_201_1 0x00008442
264 #define LPC844_201_2 0x00008444
265 
266 #define LPC845_301 0x00008451
267 #define LPC845_301_1 0x00008452
268 #define LPC845_301_2 0x00008453
269 #define LPC845_301_3 0x00008454
270 
271 #define IAP_CODE_LEN 0x34
272 
273 #define LPC11XX_REG_SECTORS 24
274 
275 typedef enum {
286 
289  uint32_t cclk;
294  uint32_t iap_max_stack;
295  uint32_t lpc4300_bank;
297  bool probed;
298 };
299 
324 };
325 
327 {
328  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
329  uint32_t offset = 0;
330 
331  /* default to a 4096 write buffer */
332  lpc2000_info->cmd51_max_buffer = 4096;
333 
334  if (lpc2000_info->variant == LPC2000_V1) {
335  lpc2000_info->cmd51_dst_boundary = 512;
336  lpc2000_info->checksum_vector = 5;
337  lpc2000_info->iap_max_stack = 128;
338 
339  /* variant 1 has different layout for 128kb and 256kb flashes */
340  if (bank->size == 128 * 1024) {
341  bank->num_sectors = 16;
342  bank->sectors = malloc(sizeof(struct flash_sector) * 16);
343  for (int i = 0; i < 16; i++) {
344  bank->sectors[i].offset = offset;
345  bank->sectors[i].size = 8 * 1024;
346  offset += bank->sectors[i].size;
347  bank->sectors[i].is_erased = -1;
348  bank->sectors[i].is_protected = 1;
349  }
350  } else if (bank->size == 256 * 1024) {
351  bank->num_sectors = 18;
352  bank->sectors = malloc(sizeof(struct flash_sector) * 18);
353 
354  for (int i = 0; i < 8; 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;
360  }
361  for (int i = 8; i < 10; i++) {
362  bank->sectors[i].offset = offset;
363  bank->sectors[i].size = 64 * 1024;
364  offset += bank->sectors[i].size;
365  bank->sectors[i].is_erased = -1;
366  bank->sectors[i].is_protected = 1;
367  }
368  for (int i = 10; i < 18; i++) {
369  bank->sectors[i].offset = offset;
370  bank->sectors[i].size = 8 * 1024;
371  offset += bank->sectors[i].size;
372  bank->sectors[i].is_erased = -1;
373  bank->sectors[i].is_protected = 1;
374  }
375  } else {
376  LOG_ERROR("BUG: unknown bank->size encountered");
377  exit(-1);
378  }
379  } else if (lpc2000_info->variant == LPC2000_V2) {
380  lpc2000_info->cmd51_dst_boundary = 256;
381  lpc2000_info->checksum_vector = 5;
382  lpc2000_info->iap_max_stack = 128;
383 
384  /* variant 2 has a uniform layout, only number of sectors differs */
385  switch (bank->size) {
386  case 4 * 1024:
387  lpc2000_info->cmd51_max_buffer = 1024;
388  bank->num_sectors = 1;
389  break;
390  case 8 * 1024:
391  lpc2000_info->cmd51_max_buffer = 1024;
392  bank->num_sectors = 2;
393  break;
394  case 16 * 1024:
395  bank->num_sectors = 4;
396  break;
397  case 32 * 1024:
398  bank->num_sectors = 8;
399  break;
400  case 64 * 1024:
401  bank->num_sectors = 9;
402  break;
403  case 128 * 1024:
404  bank->num_sectors = 11;
405  break;
406  case 256 * 1024:
407  bank->num_sectors = 15;
408  break;
409  case 500 * 1024:
410  bank->num_sectors = 27;
411  break;
412  case 512 * 1024:
413  case 504 * 1024:
414  bank->num_sectors = 28;
415  break;
416  default:
417  LOG_ERROR("BUG: unknown bank->size encountered");
418  exit(-1);
419  break;
420  }
421 
422  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
423 
424  for (unsigned int i = 0; i < bank->num_sectors; i++) {
425  if (i < 8) {
426  bank->sectors[i].offset = offset;
427  bank->sectors[i].size = 4 * 1024;
428  offset += bank->sectors[i].size;
429  bank->sectors[i].is_erased = -1;
430  bank->sectors[i].is_protected = 1;
431  } else if (i < 22) {
432  bank->sectors[i].offset = offset;
433  bank->sectors[i].size = 32 * 1024;
434  offset += bank->sectors[i].size;
435  bank->sectors[i].is_erased = -1;
436  bank->sectors[i].is_protected = 1;
437  } else if (i < 28) {
438  bank->sectors[i].offset = offset;
439  bank->sectors[i].size = 4 * 1024;
440  offset += bank->sectors[i].size;
441  bank->sectors[i].is_erased = -1;
442  bank->sectors[i].is_protected = 1;
443  }
444  }
445  } else if (lpc2000_info->variant == LPC1700) {
446  lpc2000_info->cmd51_dst_boundary = 256;
447  lpc2000_info->checksum_vector = 7;
448  lpc2000_info->iap_max_stack = 128;
449 
450  switch (bank->size) {
451  case 4 * 1024:
452  lpc2000_info->cmd51_max_buffer = 256;
453  bank->num_sectors = 1;
454  break;
455  case 8 * 1024:
456  lpc2000_info->cmd51_max_buffer = 512;
457  bank->num_sectors = 2;
458  break;
459  case 16 * 1024:
460  lpc2000_info->cmd51_max_buffer = 512;
461  bank->num_sectors = 4;
462  break;
463  case 32 * 1024:
464  lpc2000_info->cmd51_max_buffer = 1024;
465  bank->num_sectors = 8;
466  break;
467  case 64 * 1024:
468  bank->num_sectors = 16;
469  break;
470  case 128 * 1024:
471  bank->num_sectors = 18;
472  break;
473  case 256 * 1024:
474  bank->num_sectors = 22;
475  break;
476  case 512 * 1024:
477  bank->num_sectors = 30;
478  break;
479  default:
480  LOG_ERROR("BUG: unknown bank->size encountered");
481  exit(-1);
482  }
483 
484  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
485 
486  for (unsigned int i = 0; i < bank->num_sectors; i++) {
487  bank->sectors[i].offset = offset;
488  /* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx/LPC40xx devices */
489  bank->sectors[i].size = (i < 16) ? 4 * 1024 : 32 * 1024;
490  offset += bank->sectors[i].size;
491  bank->sectors[i].is_erased = -1;
492  bank->sectors[i].is_protected = 1;
493  }
494  } else if (lpc2000_info->variant == LPC4300) {
495  lpc2000_info->cmd51_dst_boundary = 512;
496  lpc2000_info->checksum_vector = 7;
497  lpc2000_info->iap_max_stack = 208;
498 
499  switch (bank->size) {
500  case 256 * 1024:
501  bank->num_sectors = 11;
502  break;
503  case 384 * 1024:
504  bank->num_sectors = 13;
505  break;
506  case 512 * 1024:
507  bank->num_sectors = 15;
508  break;
509  default:
510  LOG_ERROR("BUG: unknown bank->size encountered");
511  exit(-1);
512  }
513 
514  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
515 
516  for (unsigned int i = 0; i < bank->num_sectors; i++) {
517  bank->sectors[i].offset = offset;
518  /* sectors 0-7 are 8kB-sized, 8 and above are 64kB-sized for LPC43xx devices */
519  bank->sectors[i].size = (i < 8) ? 8 * 1024 : 64 * 1024;
520  offset += bank->sectors[i].size;
521  bank->sectors[i].is_erased = -1;
522  bank->sectors[i].is_protected = 1;
523  }
524 
525  } else if (lpc2000_info->variant == LPC800) {
526  lpc2000_info->cmd51_dst_boundary = 64;
527  lpc2000_info->checksum_vector = 7;
528  lpc2000_info->iap_max_stack = 208; /* 148byte for LPC81x,208byte for LPC82x. */
529  lpc2000_info->cmd51_max_buffer = 256; /* smallest MCU in the series, LPC810, has 1 kB of SRAM */
530 
531  switch (bank->size) {
532  case 4 * 1024:
533  bank->num_sectors = 4;
534  break;
535  case 8 * 1024:
536  bank->num_sectors = 8;
537  break;
538  case 16 * 1024:
539  bank->num_sectors = 16;
540  break;
541  case 30 * 1024:
542  lpc2000_info->cmd51_max_buffer = 1024; /* For LPC8N04 and NHS31xx, have 8kB of SRAM */
543  bank->num_sectors = 30; /* There have only 30kB of writable Flash out of 32kB */
544  break;
545  case 32 * 1024:
546  lpc2000_info->cmd51_max_buffer = 1024; /* For LPC824, has 8kB of SRAM */
547  bank->num_sectors = 32;
548  break;
549  case 64 * 1024:
550  lpc2000_info->cmd51_max_buffer = 1024; /* For LPC844, has 8kB of SRAM */
551  bank->num_sectors = 64;
552  break;
553  default:
554  LOG_ERROR("BUG: unknown bank->size encountered");
555  exit(-1);
556  }
557 
558  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
559 
560  for (unsigned int i = 0; i < bank->num_sectors; i++) {
561  bank->sectors[i].offset = offset;
562  /* all sectors are 1kB-sized for LPC8xx devices */
563  bank->sectors[i].size = 1 * 1024;
564  offset += bank->sectors[i].size;
565  bank->sectors[i].is_erased = -1;
566  bank->sectors[i].is_protected = 1;
567  }
568 
569  } else if (lpc2000_info->variant == LPC1100) {
570  lpc2000_info->cmd51_dst_boundary = 256;
571  lpc2000_info->checksum_vector = 7;
572  lpc2000_info->iap_max_stack = 128;
573 
574  if ((bank->size % (4 * 1024)) != 0) {
575  LOG_ERROR("BUG: unknown bank->size encountered,\nLPC1100 flash size must be a multiple of 4096");
576  exit(-1);
577  }
578  lpc2000_info->cmd51_max_buffer = 512; /* smallest MCU in the series, LPC1110, has 1 kB of SRAM */
579  unsigned int large_sectors = 0;
580  unsigned int normal_sectors = bank->size / 4096;
581 
582  if (normal_sectors > LPC11XX_REG_SECTORS) {
583  large_sectors = (normal_sectors - LPC11XX_REG_SECTORS) / 8;
584  normal_sectors = LPC11XX_REG_SECTORS;
585  }
586 
587  bank->num_sectors = normal_sectors + large_sectors;
588 
589  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
590 
591  for (unsigned int i = 0; i < bank->num_sectors; i++) {
592  bank->sectors[i].offset = offset;
593  bank->sectors[i].size = (i < LPC11XX_REG_SECTORS ? 4 : 32) * 1024;
594  offset += bank->sectors[i].size;
595  bank->sectors[i].is_erased = -1;
596  bank->sectors[i].is_protected = 1;
597  }
598 
599  } else if (lpc2000_info->variant == LPC1500) {
600  lpc2000_info->cmd51_dst_boundary = 256;
601  lpc2000_info->checksum_vector = 7;
602  lpc2000_info->iap_max_stack = 128;
603 
604  switch (bank->size) {
605  case 64 * 1024:
606  bank->num_sectors = 16;
607  break;
608  case 128 * 1024:
609  bank->num_sectors = 32;
610  break;
611  case 256 * 1024:
612  bank->num_sectors = 64;
613  break;
614  default:
615  LOG_ERROR("BUG: unknown bank->size encountered");
616  exit(-1);
617  }
618 
619  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
620 
621  for (unsigned int i = 0; i < bank->num_sectors; i++) {
622  bank->sectors[i].offset = offset;
623  /* all sectors are 4kB-sized */
624  bank->sectors[i].size = 4 * 1024;
625  offset += bank->sectors[i].size;
626  bank->sectors[i].is_erased = -1;
627  bank->sectors[i].is_protected = 1;
628  }
629 
630  } else if (lpc2000_info->variant == LPC54100) {
631  lpc2000_info->cmd51_dst_boundary = 256;
632  lpc2000_info->checksum_vector = 7;
633  lpc2000_info->iap_max_stack = 128;
634 
635  switch (bank->size) {
636  case 256 * 1024:
637  bank->num_sectors = 8;
638  break;
639  case 512 * 1024:
640  bank->num_sectors = 16;
641  break;
642  default:
643  LOG_ERROR("BUG: unknown bank->size encountered");
644  exit(-1);
645  }
646 
647  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
648 
649  for (unsigned int i = 0; i < bank->num_sectors; i++) {
650  bank->sectors[i].offset = offset;
651  /* all sectors are 32kB-sized */
652  bank->sectors[i].size = 32 * 1024;
653  offset += bank->sectors[i].size;
654  bank->sectors[i].is_erased = -1;
655  bank->sectors[i].is_protected = 1;
656  }
657 
658  } else {
659  LOG_ERROR("BUG: unknown lpc2000_info->variant encountered");
660  exit(-1);
661  }
662 
663  return ERROR_OK;
664 }
665 
666 /* this function allocates and initializes working area used for IAP algorithm
667  * uses 52 + max IAP stack bytes working area
668  * 0x0 to 0x7: jump gate (BX to thumb state, b -2 to wait)
669  * 0x8 to 0x1f: command parameter table (1+5 words)
670  * 0x20 to 0x33: command result table (1+4 words)
671  * 0x34 to 0xb3|0x104: stack
672  * (128b needed for lpc1xxx/2000/5410x, 208b for lpc43xx/lpc82x and 148b for lpc81x)
673  */
674 
675 static int lpc2000_iap_working_area_init(struct flash_bank *bank, struct working_area **iap_working_area)
676 {
677  struct target *target = bank->target;
678  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
679 
680  if (target_alloc_working_area(target, IAP_CODE_LEN + lpc2000_info->iap_max_stack, iap_working_area) != ERROR_OK) {
681  LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
683  }
684 
685  uint8_t jump_gate[8];
686 
687  /* write IAP code to working area */
688  switch (lpc2000_info->variant) {
689  case LPC800:
690  case LPC1100:
691  case LPC1500:
692  case LPC1700:
693  case LPC4300:
694  case LPC54100:
695  case LPC_AUTO:
696  target_buffer_set_u32(target, jump_gate, ARMV4_5_T_BX(12));
697  target_buffer_set_u32(target, jump_gate + 4, ARMV5_T_BKPT(0));
698  break;
699  case LPC2000_V1:
700  case LPC2000_V2:
701  target_buffer_set_u32(target, jump_gate, ARMV4_5_BX(12));
702  target_buffer_set_u32(target, jump_gate + 4, ARMV4_5_B(0xfffffe, 0));
703  break;
704  default:
705  LOG_ERROR("BUG: unknown lpc2000_info->variant encountered");
706  exit(-1);
707  }
708 
709  int retval = target_write_memory(target, (*iap_working_area)->address, 4, 2, jump_gate);
710  if (retval != ERROR_OK) {
711  LOG_ERROR("Write memory at address " TARGET_ADDR_FMT " failed (check work_area definition)",
712  (*iap_working_area)->address);
713  target_free_working_area(target, *iap_working_area);
714  }
715 
716  return retval;
717 }
718 
719 /* call LPC8xx/LPC1xxx/LPC4xxx/LPC5410x/LPC2000 IAP function */
720 
721 static int lpc2000_iap_call(struct flash_bank *bank, struct working_area *iap_working_area, int code,
722  uint32_t param_table[5], uint32_t result_table[4])
723 {
724  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
725  struct target *target = bank->target;
726 
727  struct arm_algorithm arm_algo; /* for LPC2000 */
728  struct armv7m_algorithm armv7m_info; /* for LPC8xx/LPC1xxx/LPC4xxx/LPC5410x */
729  uint32_t iap_entry_point = 0; /* to make compiler happier */
730 
731  switch (lpc2000_info->variant) {
732  case LPC800:
733  case LPC1100:
734  case LPC1700:
735  case LPC_AUTO:
736  armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
737  armv7m_info.core_mode = ARM_MODE_THREAD;
738  iap_entry_point = 0x1fff1ff1;
739  break;
740  case LPC1500:
741  case LPC54100:
742  armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
743  armv7m_info.core_mode = ARM_MODE_THREAD;
744  iap_entry_point = 0x03000205;
745  break;
746  case LPC2000_V1:
747  case LPC2000_V2:
748  arm_algo.common_magic = ARM_COMMON_MAGIC;
749  arm_algo.core_mode = ARM_MODE_SVC;
750  arm_algo.core_state = ARM_STATE_ARM;
751  iap_entry_point = 0x7ffffff1;
752  break;
753  case LPC4300:
754  armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
755  armv7m_info.core_mode = ARM_MODE_THREAD;
756  /* read out IAP entry point from ROM driver table at 0x10400100 */
757  target_read_u32(target, 0x10400100, &iap_entry_point);
758  break;
759  default:
760  LOG_ERROR("BUG: unknown lpc2000->variant encountered");
761  exit(-1);
762  }
763 
764  if (lpc2000_info->iap_entry_alternative != 0x0)
765  iap_entry_point = lpc2000_info->iap_entry_alternative;
766 
767  struct mem_param mem_params[2];
768 
769  /* command parameter table */
770  init_mem_param(&mem_params[0], iap_working_area->address + 8, 6 * 4, PARAM_OUT);
771  target_buffer_set_u32(target, mem_params[0].value, code);
772  target_buffer_set_u32(target, mem_params[0].value + 0x04, param_table[0]);
773  target_buffer_set_u32(target, mem_params[0].value + 0x08, param_table[1]);
774  target_buffer_set_u32(target, mem_params[0].value + 0x0c, param_table[2]);
775  target_buffer_set_u32(target, mem_params[0].value + 0x10, param_table[3]);
776  target_buffer_set_u32(target, mem_params[0].value + 0x14, param_table[4]);
777 
778  struct reg_param reg_params[5];
779 
780  init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
781  buf_set_u32(reg_params[0].value, 0, 32, iap_working_area->address + 0x08);
782 
783  /* command result table */
784  init_mem_param(&mem_params[1], iap_working_area->address + 0x20, 5 * 4, PARAM_IN);
785 
786  init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
787  buf_set_u32(reg_params[1].value, 0, 32, iap_working_area->address + 0x20);
788 
789  /* IAP entry point */
790  init_reg_param(&reg_params[2], "r12", 32, PARAM_OUT);
791  buf_set_u32(reg_params[2].value, 0, 32, iap_entry_point);
792 
793  switch (lpc2000_info->variant) {
794  case LPC800:
795  case LPC1100:
796  case LPC1500:
797  case LPC1700:
798  case LPC4300:
799  case LPC54100:
800  case LPC_AUTO:
801  /* IAP stack */
802  init_reg_param(&reg_params[3], "sp", 32, PARAM_OUT);
803  buf_set_u32(reg_params[3].value, 0, 32,
804  iap_working_area->address + IAP_CODE_LEN + lpc2000_info->iap_max_stack);
805 
806  /* return address */
807  init_reg_param(&reg_params[4], "lr", 32, PARAM_OUT);
808  buf_set_u32(reg_params[4].value, 0, 32, (iap_working_area->address + 0x04) | 1);
809  /* bit0 of LR = 1 to return in Thumb mode */
810 
811  target_run_algorithm(target, 2, mem_params, 5, reg_params, iap_working_area->address, 0, 10000,
812  &armv7m_info);
813  break;
814  case LPC2000_V1:
815  case LPC2000_V2:
816  /* IAP stack */
817  init_reg_param(&reg_params[3], "sp_svc", 32, PARAM_OUT);
818  buf_set_u32(reg_params[3].value, 0, 32,
819  iap_working_area->address + IAP_CODE_LEN + lpc2000_info->iap_max_stack);
820 
821  /* return address */
822  init_reg_param(&reg_params[4], "lr_svc", 32, PARAM_OUT);
823  buf_set_u32(reg_params[4].value, 0, 32, iap_working_area->address + 0x04);
824 
825  target_run_algorithm(target, 2, mem_params, 5, reg_params, iap_working_area->address,
826  iap_working_area->address + 0x4, 10000, &arm_algo);
827  break;
828  default:
829  LOG_ERROR("BUG: unknown lpc2000->variant encountered");
830  exit(-1);
831  }
832 
833  int status_code = target_buffer_get_u32(target, mem_params[1].value);
834  result_table[0] = target_buffer_get_u32(target, mem_params[1].value + 0x04);
835  result_table[1] = target_buffer_get_u32(target, mem_params[1].value + 0x08);
836  result_table[2] = target_buffer_get_u32(target, mem_params[1].value + 0x0c);
837  result_table[3] = target_buffer_get_u32(target, mem_params[1].value + 0x10);
838 
839  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
840  ") completed with result = %8.8x",
841  code, param_table[0], param_table[1], param_table[2], param_table[3], param_table[4], status_code);
842 
843  destroy_mem_param(&mem_params[0]);
844  destroy_mem_param(&mem_params[1]);
845 
846  destroy_reg_param(&reg_params[0]);
847  destroy_reg_param(&reg_params[1]);
848  destroy_reg_param(&reg_params[2]);
849  destroy_reg_param(&reg_params[3]);
850  destroy_reg_param(&reg_params[4]);
851 
852  return status_code;
853 }
854 
855 static int lpc2000_iap_blank_check(struct flash_bank *bank, unsigned int first,
856  unsigned int last)
857 {
858  if (last >= bank->num_sectors)
860 
861  uint32_t param_table[5] = {0};
862  uint32_t result_table[4];
863  struct working_area *iap_working_area;
864 
865  int retval = lpc2000_iap_working_area_init(bank, &iap_working_area);
866 
867  if (retval != ERROR_OK)
868  return retval;
869 
870  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
871  if (lpc2000_info->variant == LPC4300)
872  param_table[2] = lpc2000_info->lpc4300_bank;
873 
874  for (unsigned int i = first; i <= last && retval == ERROR_OK; i++) {
875  /* check single sector */
876  param_table[0] = param_table[1] = i;
877  int status_code = lpc2000_iap_call(bank, iap_working_area, 53, param_table, result_table);
878 
879  switch (status_code) {
882  break;
883  case LPC2000_CMD_SUCCESS:
884  bank->sectors[i].is_erased = 1;
885  break;
887  bank->sectors[i].is_erased = 0;
888  break;
890  bank->sectors[i].is_erased = 0;
891  break;
892  case LPC2000_BUSY:
893  retval = ERROR_FLASH_BUSY;
894  break;
895  default:
896  LOG_ERROR("BUG: unknown LPC2000 status code %i", status_code);
897  exit(-1);
898  }
899  }
900 
901  struct target *target = bank->target;
902  target_free_working_area(target, iap_working_area);
903 
904  return retval;
905 }
906 
907 /*
908  * flash bank lpc2000 <base> <size> 0 0 <target#> <lpc_variant> <cclk> [calc_checksum]
909  */
910 FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command)
911 {
912  if (CMD_ARGC < 8)
914 
915  struct lpc2000_flash_bank *lpc2000_info = calloc(1, sizeof(*lpc2000_info));
916  lpc2000_info->probed = false;
917 
918  bank->driver_priv = lpc2000_info;
919 
920  if (strcmp(CMD_ARGV[6], "lpc2000_v1") == 0) {
921  lpc2000_info->variant = LPC2000_V1;
922  } else if (strcmp(CMD_ARGV[6], "lpc2000_v2") == 0) {
923  lpc2000_info->variant = LPC2000_V2;
924  } else if (strcmp(CMD_ARGV[6], "lpc1700") == 0 || strcmp(CMD_ARGV[6], "lpc4000") == 0) {
925  lpc2000_info->variant = LPC1700;
926  } else if (strcmp(CMD_ARGV[6], "lpc1800") == 0 || strcmp(CMD_ARGV[6], "lpc4300") == 0) {
927  lpc2000_info->variant = LPC4300;
928  } else if (strcmp(CMD_ARGV[6], "lpc800") == 0) {
929  lpc2000_info->variant = LPC800;
930  } else if (strcmp(CMD_ARGV[6], "lpc1100") == 0) {
931  lpc2000_info->variant = LPC1100;
932  } else if (strcmp(CMD_ARGV[6], "lpc1500") == 0) {
933  lpc2000_info->variant = LPC1500;
934  } else if (strcmp(CMD_ARGV[6], "lpc54100") == 0) {
935  lpc2000_info->variant = LPC54100;
936  } else if (strcmp(CMD_ARGV[6], "auto") == 0) {
937  lpc2000_info->variant = LPC_AUTO;
938  } else {
939  LOG_ERROR("unknown LPC2000 variant: %s", CMD_ARGV[6]);
940  free(lpc2000_info);
942  }
943 
944  /* Maximum size required for the IAP stack.
945  This value only gets used when probing, only for auto, lpc1100 and lpc1700.
946  We use the maximum size for any part supported by the driver(!) to be safe
947  in case the auto variant is mistakenly used on a MCU from one of the series
948  for which we don't support auto-probing. */
949  lpc2000_info->iap_max_stack = 208;
950 
951  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[7], lpc2000_info->cclk);
952  lpc2000_info->calc_checksum = 0;
953 
954  uint32_t temp_base = 0;
955  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], temp_base);
956  if (temp_base >= 0x1B000000)
957  lpc2000_info->lpc4300_bank = 1; /* bank B */
958  else
959  lpc2000_info->lpc4300_bank = 0; /* bank A */
960 
961  if (CMD_ARGC >= 9) {
962  if (strcmp(CMD_ARGV[8], "calc_checksum") == 0)
963  lpc2000_info->calc_checksum = 1;
964  }
965  if (CMD_ARGC >= 10 && !lpc2000_info->iap_entry_alternative)
966  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[9], lpc2000_info->iap_entry_alternative);
967 
968  return ERROR_OK;
969 }
970 
971 static int lpc2000_erase(struct flash_bank *bank, unsigned int first,
972  unsigned int last)
973 {
974  if (bank->target->state != TARGET_HALTED) {
975  LOG_ERROR("Target not halted");
977  }
978 
979  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
980  uint32_t param_table[5] = {0};
981 
982  param_table[0] = first;
983  param_table[1] = last;
984 
985  if (lpc2000_info->variant == LPC4300)
986  param_table[2] = lpc2000_info->lpc4300_bank;
987  else
988  param_table[2] = lpc2000_info->cclk;
989 
990  uint32_t result_table[4];
991  struct working_area *iap_working_area;
992 
993  int retval = lpc2000_iap_working_area_init(bank, &iap_working_area);
994 
995  if (retval != ERROR_OK)
996  return retval;
997 
998  if (lpc2000_info->variant == LPC4300)
999  /* Init IAP Anyway */
1000  lpc2000_iap_call(bank, iap_working_area, 49, param_table, result_table);
1001 
1002  /* Prepare sectors */
1003  int status_code = lpc2000_iap_call(bank, iap_working_area, 50, param_table, result_table);
1004  switch (status_code) {
1007  break;
1008  case LPC2000_CMD_SUCCESS:
1009  break;
1011  retval = ERROR_FLASH_SECTOR_INVALID;
1012  break;
1013  default:
1014  LOG_WARNING("lpc2000 prepare sectors returned %i", status_code);
1016  break;
1017  }
1018 
1019  if (retval == ERROR_OK) {
1020  /* Erase sectors */
1021  param_table[2] = lpc2000_info->cclk;
1022  if (lpc2000_info->variant == LPC4300)
1023  param_table[3] = lpc2000_info->lpc4300_bank;
1024 
1025  status_code = lpc2000_iap_call(bank, iap_working_area, 52, param_table, result_table);
1026  switch (status_code) {
1029  break;
1030  case LPC2000_CMD_SUCCESS:
1031  break;
1033  retval = ERROR_FLASH_SECTOR_INVALID;
1034  break;
1035  default:
1036  LOG_WARNING("lpc2000 erase sectors returned %i", status_code);
1038  break;
1039  }
1040  }
1041 
1042  struct target *target = bank->target;
1043  target_free_working_area(target, iap_working_area);
1044 
1045  return retval;
1046 }
1047 
1048 static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
1049 {
1050  struct target *target = bank->target;
1051 
1052  if (bank->target->state != TARGET_HALTED) {
1053  LOG_ERROR("Target not halted");
1054  return ERROR_TARGET_NOT_HALTED;
1055  }
1056 
1057  if (offset + count > bank->size)
1059 
1060  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
1061 
1062  uint32_t dst_min_alignment = lpc2000_info->cmd51_dst_boundary;
1063 
1064  if (offset % dst_min_alignment) {
1065  LOG_WARNING("offset 0x%" PRIx32 " breaks required alignment 0x%" PRIx32, offset, dst_min_alignment);
1067  }
1068 
1069  int first_sector = 0;
1070  int last_sector = 0;
1071 
1072  for (unsigned int i = 0; i < bank->num_sectors; i++) {
1073  if (offset >= bank->sectors[i].offset)
1074  first_sector = i;
1075  if (offset + DIV_ROUND_UP(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset)
1076  last_sector = i;
1077  }
1078 
1079  LOG_DEBUG("first_sector: %i, last_sector: %i", first_sector, last_sector);
1080 
1081  /* check if exception vectors should be flashed */
1082  if ((offset == 0) && (count >= 0x20) && lpc2000_info->calc_checksum) {
1083  assert(lpc2000_info->checksum_vector < 8);
1084  uint32_t checksum = 0;
1085  for (int i = 0; i < 8; i++) {
1086  LOG_DEBUG("Vector 0x%2.2x: 0x%8.8" PRIx32, i * 4, buf_get_u32(buffer + (i * 4), 0, 32));
1087  if (i != lpc2000_info->checksum_vector)
1088  checksum += buf_get_u32(buffer + (i * 4), 0, 32);
1089  }
1090  checksum = 0 - checksum;
1091  LOG_DEBUG("checksum: 0x%8.8" PRIx32, checksum);
1092 
1093  uint32_t original_value = buf_get_u32(buffer + (lpc2000_info->checksum_vector * 4), 0, 32);
1094  if (original_value != checksum) {
1095  LOG_WARNING("Boot verification checksum in image (0x%8.8" PRIx32 ") to be written to flash is "
1096  "different from calculated vector checksum (0x%8.8" PRIx32 ").", original_value, checksum);
1097  LOG_WARNING("OpenOCD will write the correct checksum. To remove this warning modify build tools on developer PC to inject correct LPC vector "
1098  "checksum.");
1099  }
1100 
1101  /* FIXME: WARNING! This code is broken because it modifies the callers buffer in place. */
1102  buf_set_u32((uint8_t *)buffer + (lpc2000_info->checksum_vector * 4), 0, 32, checksum);
1103  }
1104 
1105  struct working_area *iap_working_area;
1106 
1107  int retval = lpc2000_iap_working_area_init(bank, &iap_working_area);
1108 
1109  if (retval != ERROR_OK)
1110  return retval;
1111 
1112  struct working_area *download_area;
1113 
1114  /* allocate a working area */
1115  if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK) {
1116  LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
1117  target_free_working_area(target, iap_working_area);
1119  }
1120 
1121  uint32_t bytes_remaining = count;
1122  uint32_t bytes_written = 0;
1123  uint32_t param_table[5] = {0};
1124  uint32_t result_table[4];
1125 
1126  if (lpc2000_info->variant == LPC4300)
1127  /* Init IAP Anyway */
1128  lpc2000_iap_call(bank, iap_working_area, 49, param_table, result_table);
1129 
1130  while (bytes_remaining > 0) {
1131  uint32_t thisrun_bytes;
1132  if (bytes_remaining >= lpc2000_info->cmd51_max_buffer)
1133  thisrun_bytes = lpc2000_info->cmd51_max_buffer;
1134  else
1135  thisrun_bytes = lpc2000_info->cmd51_dst_boundary;
1136 
1137  /* Prepare sectors */
1138  param_table[0] = first_sector;
1139  param_table[1] = last_sector;
1140 
1141  if (lpc2000_info->variant == LPC4300)
1142  param_table[2] = lpc2000_info->lpc4300_bank;
1143  else
1144  param_table[2] = lpc2000_info->cclk;
1145 
1146  int status_code = lpc2000_iap_call(bank, iap_working_area, 50, param_table, result_table);
1147  switch (status_code) {
1150  break;
1151  case LPC2000_CMD_SUCCESS:
1152  break;
1154  retval = ERROR_FLASH_SECTOR_INVALID;
1155  break;
1156  default:
1157  LOG_WARNING("lpc2000 prepare sectors returned %i", status_code);
1159  break;
1160  }
1161 
1162  /* Exit if error occurred */
1163  if (retval != ERROR_OK)
1164  break;
1165 
1166  if (bytes_remaining >= thisrun_bytes) {
1167  retval = target_write_buffer(bank->target, download_area->address, thisrun_bytes, buffer + bytes_written);
1168  if (retval != ERROR_OK) {
1170  break;
1171  }
1172  } else {
1173  uint8_t *last_buffer = malloc(thisrun_bytes);
1174  memcpy(last_buffer, buffer + bytes_written, bytes_remaining);
1175  memset(last_buffer + bytes_remaining, 0xff, thisrun_bytes - bytes_remaining);
1176  target_write_buffer(bank->target, download_area->address, thisrun_bytes, last_buffer);
1177  free(last_buffer);
1178  }
1179 
1180  LOG_DEBUG("writing 0x%" PRIx32 " bytes to address " TARGET_ADDR_FMT,
1181  thisrun_bytes, bank->base + offset + bytes_written);
1182 
1183  /* Write data */
1184  param_table[0] = bank->base + offset + bytes_written;
1185  param_table[1] = download_area->address;
1186  param_table[2] = thisrun_bytes;
1187  param_table[3] = lpc2000_info->cclk;
1188  status_code = lpc2000_iap_call(bank, iap_working_area, 51, param_table, result_table);
1189  switch (status_code) {
1192  break;
1193  case LPC2000_CMD_SUCCESS:
1194  break;
1196  retval = ERROR_FLASH_SECTOR_INVALID;
1197  break;
1198  default:
1199  LOG_WARNING("lpc2000 returned %i", status_code);
1201  break;
1202  }
1203 
1204  /* Exit if error occurred */
1205  if (retval != ERROR_OK)
1206  break;
1207 
1208  if (bytes_remaining > thisrun_bytes)
1209  bytes_remaining -= thisrun_bytes;
1210  else
1211  bytes_remaining = 0;
1212  bytes_written += thisrun_bytes;
1213  }
1214 
1215  target_free_working_area(target, iap_working_area);
1216  target_free_working_area(target, download_area);
1217 
1218  return retval;
1219 }
1220 
1221 static int get_lpc2000_part_id(struct flash_bank *bank, uint32_t *part_id)
1222 {
1223  if (bank->target->state != TARGET_HALTED) {
1224  LOG_ERROR("Target not halted");
1225  return ERROR_TARGET_NOT_HALTED;
1226  }
1227 
1228  uint32_t param_table[5] = {0};
1229  uint32_t result_table[4];
1230  struct working_area *iap_working_area;
1231 
1232  int retval = lpc2000_iap_working_area_init(bank, &iap_working_area);
1233 
1234  if (retval != ERROR_OK)
1235  return retval;
1236 
1237  /* The status seems to be bogus with the part ID command on some IAP
1238  firmwares, so ignore it. */
1239  lpc2000_iap_call(bank, iap_working_area, 54, param_table, result_table);
1240 
1241  struct target *target = bank->target;
1242  target_free_working_area(target, iap_working_area);
1243 
1244  /* If the result is zero, the command probably didn't work out. */
1245  if (result_table[0] == 0)
1246  return LPC2000_INVALID_COMMAND;
1247 
1248  *part_id = result_table[0];
1249  return LPC2000_CMD_SUCCESS;
1250 }
1251 
1253 {
1254  uint32_t part_id;
1255  int retval;
1256  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
1257 
1258  if (bank->target->state != TARGET_HALTED) {
1259  LOG_ERROR("Target not halted");
1260  return ERROR_TARGET_NOT_HALTED;
1261  }
1262 
1263  retval = get_lpc2000_part_id(bank, &part_id);
1264  if (retval != LPC2000_CMD_SUCCESS) {
1265  LOG_ERROR("Could not get part ID");
1266  return retval;
1267  }
1268 
1269  switch (part_id) {
1270  case LPC1110_1:
1271  case LPC1110_2:
1272  lpc2000_info->variant = LPC1100;
1273  bank->size = 4 * 1024;
1274  break;
1275 
1276  case LPC1111_002_1:
1277  case LPC1111_002_2:
1278  case LPC1111_101_1:
1279  case LPC1111_101_2:
1280  case LPC1111_103_1:
1281  case LPC1111_201_1:
1282  case LPC1111_201_2:
1283  case LPC1111_203_1:
1284  case LPC11A11_001_1:
1285  case LPC11E11_101:
1286  case LPC1311:
1287  case LPC1311_1:
1288  lpc2000_info->variant = LPC1100;
1289  bank->size = 8 * 1024;
1290  break;
1291 
1292  case LPC1112_101_1:
1293  case LPC1112_101_2:
1294  case LPC1112_102_1:
1295  case LPC1112_102_2:
1296  case LPC1112_103_1:
1297  case LPC1112_201_1:
1298  case LPC1112_201_2:
1299  case LPC1112_203_1:
1300  case LPC11A02_1:
1301  case LPC11C12_301_1:
1302  case LPC11C22_301_1:
1303  case LPC11A12_101_1:
1304  case LPC11E12_201:
1305  case LPC11U12_201_1:
1306  case LPC11U12_201_2:
1307  case LPC1342:
1308  lpc2000_info->variant = LPC1100;
1309  bank->size = 16 * 1024;
1310  break;
1311 
1312  case LPC1113_201_1:
1313  case LPC1113_201_2:
1314  case LPC1113_203_1:
1315  case LPC1113_301_1:
1316  case LPC1113_301_2:
1317  case LPC1113_303_1:
1318  case LPC11A13_201_1:
1319  case LPC11E13_301:
1320  case LPC11U13_201_1:
1321  case LPC11U13_201_2:
1322  case LPC11U23_301:
1323  lpc2000_info->variant = LPC1100;
1324  bank->size = 24 * 1024;
1325  break;
1326 
1327  case LPC1114_102_1:
1328  case LPC1114_102_2:
1329  case LPC1114_201_1:
1330  case LPC1114_201_2:
1331  case LPC1114_203_1:
1332  case LPC1114_301_1:
1333  case LPC1114_301_2:
1334  case LPC1114_303_1:
1335  case LPC11A04_1:
1336  case LPC11A14_301_1:
1337  case LPC11A14_301_2:
1338  case LPC11C14_301_1:
1339  case LPC11C24_301_1:
1340  case LPC11E14_401:
1341  case LPC11U14_201_1:
1342  case LPC11U14_201_2:
1343  case LPC11U24_301:
1344  case LPC11U24_401:
1345  case LPC1313:
1346  case LPC1313_1:
1347  case LPC1315:
1348  case LPC1343:
1349  case LPC1343_1:
1350  case LPC1345:
1351  lpc2000_info->variant = LPC1100;
1352  bank->size = 32 * 1024;
1353  break;
1354 
1355  case LPC1751_1:
1356  case LPC1751_2:
1357  lpc2000_info->variant = LPC1700;
1358  bank->size = 32 * 1024;
1359  break;
1360 
1361  case LPC11U34_311:
1362  lpc2000_info->variant = LPC1100;
1363  bank->size = 40 * 1024;
1364  break;
1365 
1366  case LPC1114_323_1:
1367  case LPC11U34_421:
1368  case LPC1316:
1369  case LPC1346:
1370  lpc2000_info->variant = LPC1100;
1371  bank->size = 48 * 1024;
1372  break;
1373 
1374  case LPC1114_333_1:
1375  lpc2000_info->variant = LPC1100;
1376  bank->size = 56 * 1024;
1377  break;
1378 
1379  case LPC1115_303_1:
1380  case LPC11U35_401:
1381  case LPC11U35_501:
1382  case LPC11E66:
1383  case LPC11U66:
1384  case LPC1317:
1385  case LPC1347:
1386  lpc2000_info->variant = LPC1100;
1387  bank->size = 64 * 1024;
1388  break;
1389 
1390  case LPC1752:
1391  case LPC4072:
1392  lpc2000_info->variant = LPC1700;
1393  bank->size = 64 * 1024;
1394  break;
1395 
1396  case LPC11E36_501:
1397  case LPC11U36_401:
1398  lpc2000_info->variant = LPC1100;
1399  bank->size = 96 * 1024;
1400  break;
1401 
1402  case LPC11E37_401:
1403  case LPC11E37_501:
1404  case LPC11U37_401:
1405  case LPC11U37H_401:
1406  case LPC11U37_501:
1407  case LPC11E67:
1408  case LPC11E68:
1409  case LPC11U67_1:
1410  case LPC11U67_2:
1411  lpc2000_info->variant = LPC1100;
1412  bank->size = 128 * 1024;
1413  break;
1414 
1415  case LPC1754:
1416  case LPC1764:
1417  case LPC1774:
1418  case LPC4074:
1419  lpc2000_info->variant = LPC1700;
1420  bank->size = 128 * 1024;
1421  break;
1422 
1423  case LPC11U68_1:
1424  case LPC11U68_2:
1425  lpc2000_info->variant = LPC1100;
1426  bank->size = 256 * 1024;
1427  break;
1428 
1429  case LPC1756:
1430  case LPC1763:
1431  case LPC1765:
1432  case LPC1766:
1433  case LPC1776:
1434  case LPC1785:
1435  case LPC1786:
1436  case LPC4076:
1437  lpc2000_info->variant = LPC1700;
1438  bank->size = 256 * 1024;
1439  break;
1440 
1441  case LPC1758:
1442  case LPC1759:
1443  case LPC1767:
1444  case LPC1768:
1445  case LPC1769:
1446  case LPC1777:
1447  case LPC1778:
1448  case LPC1787:
1449  case LPC1788:
1450  case LPC4078:
1451  case LPC4088:
1452  lpc2000_info->variant = LPC1700;
1453  bank->size = 512 * 1024;
1454  break;
1455 
1456  case LPC810_021:
1457  lpc2000_info->variant = LPC800;
1458  bank->size = 4 * 1024;
1459  break;
1460 
1461  case LPC811_001:
1462  lpc2000_info->variant = LPC800;
1463  bank->size = 8 * 1024;
1464  break;
1465 
1466  case LPC812_101:
1467  case LPC812_101_1:
1468  case LPC812_101_2:
1469  case LPC812_101_3:
1470  case LPC822_101:
1471  case LPC822_101_1:
1472  lpc2000_info->variant = LPC800;
1473  bank->size = 16 * 1024;
1474  break;
1475 
1476  case LPC824_201:
1477  case LPC824_201_1:
1478  lpc2000_info->variant = LPC800;
1479  bank->size = 32 * 1024;
1480  break;
1481 
1482  case LPC8N04:
1483  case NHS3100:
1484  case NHS3152:
1485  case NHS3153:
1486  lpc2000_info->variant = LPC800;
1487  bank->size = 30 * 1024;
1488  break;
1489 
1490  case LPC844_201:
1491  case LPC844_201_1:
1492  case LPC844_201_2:
1493  case LPC845_301:
1494  case LPC845_301_1:
1495  case LPC845_301_2:
1496  case LPC845_301_3:
1497  lpc2000_info->variant = LPC800;
1498  bank->size = 64 * 1024;
1499  break;
1500 
1501  default:
1502  LOG_ERROR("BUG: unknown Part ID encountered: 0x%" PRIx32, part_id);
1503  exit(-1);
1504  }
1505 
1506  return ERROR_OK;
1507 }
1508 
1509 static int lpc2000_probe(struct flash_bank *bank)
1510 {
1511  int status;
1512  uint32_t part_id;
1513  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
1514 
1515  if (!lpc2000_info->probed) {
1516  if (lpc2000_info->variant == LPC_AUTO) {
1518  if (status != ERROR_OK)
1519  return status;
1520  } else if (lpc2000_info->variant == LPC1100 || lpc2000_info->variant == LPC1700) {
1521  status = get_lpc2000_part_id(bank, &part_id);
1522  if (status == LPC2000_CMD_SUCCESS)
1523  LOG_INFO("If auto-detection fails for this part, please email "
1524  "openocd-devel@lists.sourceforge.net, citing part id 0x%" PRIx32 ".\n", part_id);
1525  }
1526 
1528  lpc2000_info->probed = true;
1529  }
1530 
1531  return ERROR_OK;
1532 }
1533 
1535 {
1536  if (bank->target->state != TARGET_HALTED) {
1537  LOG_ERROR("Target not halted");
1538  return ERROR_TARGET_NOT_HALTED;
1539  }
1540 
1541  return lpc2000_iap_blank_check(bank, 0, bank->num_sectors - 1);
1542 }
1543 
1545 {
1546  struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
1547 
1548  command_print_sameline(cmd, "lpc2000 flash driver variant: %i, clk: %" PRIu32 "kHz",
1549  lpc2000_info->variant, lpc2000_info->cclk);
1550 
1551  return ERROR_OK;
1552 }
1553 
1554 COMMAND_HANDLER(lpc2000_handle_part_id_command)
1555 {
1556  if (CMD_ARGC < 1)
1558 
1559  struct flash_bank *bank;
1560  int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
1561  if (retval != ERROR_OK)
1562  return retval;
1563 
1564  if (bank->target->state != TARGET_HALTED) {
1565  LOG_ERROR("Target not halted");
1566  return ERROR_TARGET_NOT_HALTED;
1567  }
1568 
1569  uint32_t part_id;
1570  int status_code = get_lpc2000_part_id(bank, &part_id);
1571  if (status_code != 0x0) {
1572  if (status_code == ERROR_FLASH_OPERATION_FAILED) {
1573  command_print(CMD, "no sufficient working area specified, can't access LPC2000 IAP interface");
1574  } else
1575  command_print(CMD, "lpc2000 IAP returned status code %i", status_code);
1576  } else
1577  command_print(CMD, "lpc2000 part id: 0x%8.8" PRIx32, part_id);
1578 
1579  return retval;
1580 }
1581 
1582 static const struct command_registration lpc2000_exec_command_handlers[] = {
1583  {
1584  .name = "part_id",
1585  .handler = lpc2000_handle_part_id_command,
1586  .mode = COMMAND_EXEC,
1587  .help = "print part id of lpc2000 flash bank <num>",
1588  .usage = "<bank>",
1589  },
1591 };
1592 static const struct command_registration lpc2000_command_handlers[] = {
1593  {
1594  .name = "lpc2000",
1595  .mode = COMMAND_ANY,
1596  .help = "lpc2000 flash command group",
1597  .usage = "",
1599  },
1601 };
1602 
1603 const struct flash_driver lpc2000_flash = {
1604  .name = "lpc2000",
1605  .commands = lpc2000_command_handlers,
1606  .flash_bank_command = lpc2000_flash_bank_command,
1607  .erase = lpc2000_erase,
1608  .write = lpc2000_write,
1609  .read = default_flash_read,
1610  .probe = lpc2000_probe,
1611  .auto_probe = lpc2000_probe,
1612  .erase_check = lpc2000_erase_check,
1613  .info = get_lpc2000_info,
1614  .free_driver_priv = default_flash_free_driver_priv,
1615 };
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
Definition: algorithm.c:29
void destroy_mem_param(struct mem_param *param)
Definition: algorithm.c:23
void destroy_reg_param(struct reg_param *param)
Definition: algorithm.c:37
void init_mem_param(struct mem_param *param, uint32_t address, uint32_t size, enum param_direction direction)
Definition: algorithm.c:15
@ PARAM_OUT
Definition: algorithm.h:16
@ PARAM_IN
Definition: algorithm.h:15
#define ARM_COMMON_MAGIC
Definition: arm.h:166
@ ARM_MODE_SVC
Definition: arm.h:86
@ ARM_MODE_THREAD
Definition: arm.h:94
@ ARM_STATE_ARM
Definition: arm.h:151
Macros used to generate various ARM or Thumb opcodes.
#define ARMV4_5_T_BX(rm)
Definition: arm_opcodes.h:299
#define ARMV4_5_BX(rm)
Definition: arm_opcodes.h:122
#define ARMV5_T_BKPT(im)
Definition: arm_opcodes.h:313
#define ARMV4_5_B(im, l)
Definition: arm_opcodes.h:117
#define ARMV7M_COMMON_MAGIC
Definition: armv7m.h:220
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:420
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
Definition: command.h:118
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint8_t bank
Definition: esirisc.c:135
#define ERROR_FLASH_BANK_INVALID
Definition: flash/common.h:28
#define ERROR_FLASH_SECTOR_INVALID
Definition: flash/common.h:29
#define ERROR_FLASH_OPERATION_FAILED
Definition: flash/common.h:30
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
Definition: flash/common.h:32
#define ERROR_FLASH_BUSY
Definition: flash/common.h:33
#define ERROR_FLASH_DST_OUT_OF_BANK
Definition: flash/common.h:31
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
#define LPC11U68_2
Definition: lpc2000.c:200
#define LPC1114_303_1
Definition: lpc2000.c:148
#define LPC11U35_401
Definition: lpc2000.c:185
#define LPC4076
Definition: lpc2000.c:241
#define LPC11E12_201
Definition: lpc2000.c:167
static int lpc2000_build_sector_list(struct flash_bank *bank)
Definition: lpc2000.c:326
#define LPC1767
Definition: lpc2000.c:227
#define LPC11U68_1
Definition: lpc2000.c:199
#define LPC1769
Definition: lpc2000.c:229
lpc2000_variant
Definition: lpc2000.c:275
@ LPC1500
Definition: lpc2000.c:282
@ LPC54100
Definition: lpc2000.c:283
@ LPC1100
Definition: lpc2000.c:281
@ LPC800
Definition: lpc2000.c:280
@ LPC2000_V2
Definition: lpc2000.c:277
@ LPC4300
Definition: lpc2000.c:279
@ LPC_AUTO
Definition: lpc2000.c:284
@ LPC1700
Definition: lpc2000.c:278
@ LPC2000_V1
Definition: lpc2000.c:276
#define LPC1111_002_1
Definition: lpc2000.c:119
#define LPC11U37_401
Definition: lpc2000.c:188
#define LPC845_301
Definition: lpc2000.c:266
#define LPC1787
Definition: lpc2000.c:236
#define LPC824_201
Definition: lpc2000.c:254
#define LPC1778
Definition: lpc2000.c:233
static int lpc2000_probe(struct flash_bank *bank)
Definition: lpc2000.c:1509
#define LPC1110_1
Definition: lpc2000.c:117
#define LPC11A04_1
Definition: lpc2000.c:154
#define LPC11A02_1
Definition: lpc2000.c:153
#define LPC1785
Definition: lpc2000.c:234
static int lpc2000_auto_probe_flash(struct flash_bank *bank)
Definition: lpc2000.c:1252
#define LPC11U24_301
Definition: lpc2000.c:181
#define LPC11E13_301
Definition: lpc2000.c:168
#define LPC4072
Definition: lpc2000.c:239
#define LPC11U66
Definition: lpc2000.c:196
#define LPC11C12_301_1
Definition: lpc2000.c:161
#define LPC1111_101_2
Definition: lpc2000.c:122
#define LPC1114_201_2
Definition: lpc2000.c:144
#define LPC1114_203_1
Definition: lpc2000.c:145
#define LPC1113_203_1
Definition: lpc2000.c:137
#define LPC1114_301_1
Definition: lpc2000.c:146
FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command)
Definition: lpc2000.c:910
#define LPC4074
Definition: lpc2000.c:240
COMMAND_HANDLER(lpc2000_handle_part_id_command)
Definition: lpc2000.c:1554
#define NHS3152
Definition: lpc2000.c:259
#define LPC11U34_311
Definition: lpc2000.c:183
#define LPC1112_201_2
Definition: lpc2000.c:133
#define NHS3100
Definition: lpc2000.c:258
const struct flash_driver lpc2000_flash
Definition: lpc2000.c:1603
#define LPC11E37_401
Definition: lpc2000.c:171
#define LPC844_201_1
Definition: lpc2000.c:263
#define LPC1777
Definition: lpc2000.c:232
#define LPC4088
Definition: lpc2000.c:243
#define LPC1114_102_2
Definition: lpc2000.c:142
#define LPC11U37H_401
Definition: lpc2000.c:189
#define LPC1758
Definition: lpc2000.c:221
#define LPC810_021
Definition: lpc2000.c:245
#define LPC1113_301_2
Definition: lpc2000.c:139
#define LPC1114_201_1
Definition: lpc2000.c:143
#define LPC11A14_301_1
Definition: lpc2000.c:158
#define LPC11C24_301_1
Definition: lpc2000.c:164
#define LPC1113_201_2
Definition: lpc2000.c:136
#define LPC1111_203_1
Definition: lpc2000.c:126
#define LPC1751_2
Definition: lpc2000.c:217
#define LPC1113_201_1
Definition: lpc2000.c:135
#define LPC11A14_301_2
Definition: lpc2000.c:159
#define LPC11XX_REG_SECTORS
Definition: lpc2000.c:273
#define LPC11C22_301_1
Definition: lpc2000.c:163
#define LPC1751_1
Definition: lpc2000.c:216
#define LPC1315
Definition: lpc2000.c:206
#define LPC11U67_2
Definition: lpc2000.c:198
#define LPC1111_103_1
Definition: lpc2000.c:123
#define LPC1756
Definition: lpc2000.c:220
static int lpc2000_iap_working_area_init(struct flash_bank *bank, struct working_area **iap_working_area)
Definition: lpc2000.c:675
#define LPC812_101_2
Definition: lpc2000.c:249
#define LPC1317
Definition: lpc2000.c:208
#define LPC1313
Definition: lpc2000.c:204
#define LPC1111_002_2
Definition: lpc2000.c:120
#define LPC1759
Definition: lpc2000.c:222
#define LPC1114_323_1
Definition: lpc2000.c:149
#define LPC1114_301_2
Definition: lpc2000.c:147
static int lpc2000_iap_blank_check(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: lpc2000.c:855
#define LPC11U36_401
Definition: lpc2000.c:187
#define LPC11U34_421
Definition: lpc2000.c:184
lpc2000_status_codes
Definition: lpc2000.c:300
@ LPC2000_INVALID_SECTOR
Definition: lpc2000.c:308
@ LPC2000_DST_ADDR_ERROR
Definition: lpc2000.c:304
@ LPC2000_COMPARE_ERROR
Definition: lpc2000.c:311
@ LPC2000_INVALID_COMMAND
Definition: lpc2000.c:302
@ LPC2000_SRC_ADDR_ERROR
Definition: lpc2000.c:303
@ LPC2000_INVALID_STOP_BIT
Definition: lpc2000.c:319
@ LPC2000_ADDR_NOT_MAPPED
Definition: lpc2000.c:315
@ LPC2000_CRP_ENABLED
Definition: lpc2000.c:320
@ LPC2000_INVALID_BAUD_RATE
Definition: lpc2000.c:318
@ LPC2000_INVALID_FLASH_UNIT
Definition: lpc2000.c:321
@ LPC2000_CMD_NOT_LOCKED
Definition: lpc2000.c:316
@ LPC2000_SECTOR_NOT_PREPARED
Definition: lpc2000.c:310
@ LPC2000_CMD_SUCCESS
Definition: lpc2000.c:301
@ LPC2000_SRC_ADDR_NOT_MAPPED
Definition: lpc2000.c:305
@ LPC2000_SECTOR_NOT_BLANK
Definition: lpc2000.c:309
@ LPC2000_INVALID_CODE
Definition: lpc2000.c:317
@ LPC2000_PARAM_ERROR
Definition: lpc2000.c:313
@ LPC2000_ADDR_ERROR
Definition: lpc2000.c:314
@ LPC2000_DST_ADDR_NOT_MAPPED
Definition: lpc2000.c:306
@ LPC2000_USER_CODE_CHECKSUM
Definition: lpc2000.c:322
@ LPC2000_BUSY
Definition: lpc2000.c:312
@ LPC2000_COUNT_ERROR
Definition: lpc2000.c:307
@ LCP2000_ERROR_SETTING_ACTIVE_PARTITION
Definition: lpc2000.c:323
#define LPC1316
Definition: lpc2000.c:207
static const struct command_registration lpc2000_command_handlers[]
Definition: lpc2000.c:1592
#define IAP_CODE_LEN
Definition: lpc2000.c:271
#define LPC1113_301_1
Definition: lpc2000.c:138
#define LPC11E68
Definition: lpc2000.c:194
#define LPC1754
Definition: lpc2000.c:219
#define LPC1788
Definition: lpc2000.c:237
#define LPC11U13_201_1
Definition: lpc2000.c:176
static int lpc2000_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: lpc2000.c:971
#define LPC11E67
Definition: lpc2000.c:193
#define LPC812_101
Definition: lpc2000.c:247
#define LPC822_101
Definition: lpc2000.c:252
#define LPC11E37_501
Definition: lpc2000.c:172
#define LPC1112_201_1
Definition: lpc2000.c:132
#define LPC11E36_501
Definition: lpc2000.c:170
static const struct command_registration lpc2000_exec_command_handlers[]
Definition: lpc2000.c:1582
#define LPC845_301_1
Definition: lpc2000.c:267
#define LPC1112_101_2
Definition: lpc2000.c:128
#define LPC11E66
Definition: lpc2000.c:192
#define LPC1768
Definition: lpc2000.c:228
#define LPC1313_1
Definition: lpc2000.c:205
#define LPC1764
Definition: lpc2000.c:224
#define LPC11U13_201_2
Definition: lpc2000.c:177
#define LPC1345
Definition: lpc2000.c:212
#define NHS3153
Definition: lpc2000.c:260
#define LPC11E11_101
Definition: lpc2000.c:166
#define LPC1111_201_2
Definition: lpc2000.c:125
#define LPC11U37_501
Definition: lpc2000.c:190
#define LPC1342
Definition: lpc2000.c:209
#define LPC11A13_201_1
Definition: lpc2000.c:157
#define LPC1346
Definition: lpc2000.c:213
#define LPC844_201
Definition: lpc2000.c:262
#define LPC822_101_1
Definition: lpc2000.c:253
#define LPC1112_102_1
Definition: lpc2000.c:129
#define LPC1110_2
Definition: lpc2000.c:118
#define LPC1765
Definition: lpc2000.c:225
#define LPC811_001
Definition: lpc2000.c:246
#define LPC1311_1
Definition: lpc2000.c:203
#define LPC11C14_301_1
Definition: lpc2000.c:162
#define LPC11U12_201_1
Definition: lpc2000.c:174
#define LPC1111_101_1
Definition: lpc2000.c:121
#define LPC1763
Definition: lpc2000.c:223
static int get_lpc2000_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: lpc2000.c:1544
#define LPC1113_303_1
Definition: lpc2000.c:140
#define LPC1776
Definition: lpc2000.c:231
#define LPC845_301_3
Definition: lpc2000.c:269
#define LPC4078
Definition: lpc2000.c:242
#define LPC1112_203_1
Definition: lpc2000.c:134
#define LPC11E14_401
Definition: lpc2000.c:169
#define LPC11U35_501
Definition: lpc2000.c:186
#define LPC845_301_2
Definition: lpc2000.c:268
#define LPC1752
Definition: lpc2000.c:218
static int lpc2000_iap_call(struct flash_bank *bank, struct working_area *iap_working_area, int code, uint32_t param_table[5], uint32_t result_table[4])
Definition: lpc2000.c:721
#define LPC11U23_301
Definition: lpc2000.c:180
#define LPC844_201_2
Definition: lpc2000.c:264
static int get_lpc2000_part_id(struct flash_bank *bank, uint32_t *part_id)
Definition: lpc2000.c:1221
#define LPC11A12_101_1
Definition: lpc2000.c:156
#define LPC824_201_1
Definition: lpc2000.c:255
#define LPC1115_303_1
Definition: lpc2000.c:151
#define LPC1347
Definition: lpc2000.c:214
static int lpc2000_erase_check(struct flash_bank *bank)
Definition: lpc2000.c:1534
#define LPC1311
Definition: lpc2000.c:202
#define LPC1114_333_1
Definition: lpc2000.c:150
#define LPC1774
Definition: lpc2000.c:230
static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: lpc2000.c:1048
#define LPC1112_103_1
Definition: lpc2000.c:131
#define LPC1114_102_1
Definition: lpc2000.c:141
#define LPC1343_1
Definition: lpc2000.c:211
#define LPC812_101_3
Definition: lpc2000.c:250
#define LPC1111_201_1
Definition: lpc2000.c:124
#define LPC11A11_001_1
Definition: lpc2000.c:155
#define LPC11U12_201_2
Definition: lpc2000.c:175
#define LPC812_101_1
Definition: lpc2000.c:248
#define LPC11U24_401
Definition: lpc2000.c:182
#define LPC11U67_1
Definition: lpc2000.c:197
#define LPC11U14_201_1
Definition: lpc2000.c:178
#define LPC1786
Definition: lpc2000.c:235
#define LPC1343
Definition: lpc2000.c:210
#define LPC11U14_201_2
Definition: lpc2000.c:179
#define LPC8N04
Definition: lpc2000.c:257
#define LPC1112_102_2
Definition: lpc2000.c:130
#define LPC1112_101_1
Definition: lpc2000.c:127
#define LPC1766
Definition: lpc2000.c:226
unsigned int common_magic
Definition: arm.h:274
enum arm_mode core_mode
Definition: arm.h:276
enum arm_state core_state
Definition: arm.h:277
unsigned int common_magic
Definition: armv7m.h:295
enum arm_mode core_mode
Definition: armv7m.h:297
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
const char * name
Definition: command.h:235
Provides details of a flash bank, available either on-chip or through a major interface.
Definition: nor/core.h:75
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
Definition: nor/driver.h:39
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Definition: nor/driver.h:44
Describes the geometry and status of a single flash sector within a flash bank.
Definition: nor/core.h:28
lpc2000_variant variant
Definition: lpc2000.c:288
uint32_t cmd51_max_buffer
Definition: lpc2000.c:292
int cmd51_dst_boundary
Definition: lpc2000.c:290
uint32_t cclk
Definition: lpc2000.c:289
uint32_t lpc4300_bank
Definition: lpc2000.c:295
uint32_t iap_entry_alternative
Definition: lpc2000.c:296
uint32_t iap_max_stack
Definition: lpc2000.c:294
uint8_t * value
Definition: algorithm.h:23
uint8_t * value
Definition: algorithm.h:30
Definition: target.h:116
bool free
Definition: target.h:88
target_addr_t address
Definition: target.h:86
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:352
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2342
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
Definition: target.c:773
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
Definition: target.c:1265
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2060
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
Definition: target.c:2118
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2550
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:316
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:790
@ TARGET_HALTED
Definition: target.h:56
#define TARGET_ADDR_FMT
Definition: types.h:342
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
uint8_t status[4]
Definition: vdebug.c:17
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22