OpenOCD
at91sam4l.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2013 by Andrey Yurovsky *
5  * Andrey Yurovsky <yurovsky@gmail.com> *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include "imp.h"
13 
14 #include <jtag/jtag.h>
15 #include <target/cortex_m.h>
16 
17 /* At this time, the SAM4L Flash is available in these capacities:
18  * ATSAM4Lx4xx: 256KB (512 pages)
19  * ATSAM4Lx2xx: 128KB (256 pages)
20  * ATSAM4Lx8xx: 512KB (1024 pages)
21  */
22 
23 /* There are 16 lockable regions regardless of overall capacity. The number
24  * of pages per sector is therefore dependant on capacity. */
25 #define SAM4L_NUM_SECTORS 16
26 
27 /* Locations in memory map */
28 #define SAM4L_FLASH ((uint32_t)0x00000000) /* Flash region */
29 #define SAM4L_FLASH_USER 0x00800000 /* Flash user page region */
30 #define SAM4L_FLASHCALW 0x400A0000 /* Flash controller */
31 #define SAM4L_CHIPID 0x400E0740 /* Chip Identification */
32 
33 /* Offsets from SAM4L_FLASHCALW */
34 #define SAM4L_FCR 0x00 /* Flash Control Register (RW) */
35 #define SAM4L_FCMD 0x04 /* Flash Command Register (RW) */
36 #define SAM4L_FSR 0x08 /* Flash Status Register (RO) */
37 #define SAM4L_FPR 0x0C /* Flash Parameter Register (RO) */
38 #define SAM4L_FVR 0x10 /* Flash Version Register (RO) */
39 #define SAM4L_FGPFRHI 0x14 /* Flash General Purpose Register High (RO) */
40 #define SAM4L_FGPFRLO 0x18 /* Flash General Purpose Register Low (RO) */
41 
42 /* Offsets from SAM4L_CHIPID */
43 #define SAM4L_CIDR 0x00 /* Chip ID Register (RO) */
44 #define SAM4L_EXID 0x04 /* Chip ID Extension Register (RO) */
45 
46 /* Flash commands (for SAM4L_FCMD), see Table 14-5 */
47 #define SAM4L_FCMD_NOP 0 /* No Operation */
48 #define SAM4L_FCMD_WP 1 /* Write Page */
49 #define SAM4L_FCMD_EP 2 /* Erase Page */
50 #define SAM4L_FCMD_CPB 3 /* Clear Page Buffer */
51 #define SAM4L_FCMD_LP 4 /* Lock region containing given page */
52 #define SAM4L_FCMD_UP 5 /* Unlock region containing given page */
53 #define SAM4L_FCMD_EA 6 /* Erase All */
54 #define SAM4L_FCMD_WGPB 7 /* Write general-purpose fuse bit */
55 #define SAM4L_FCMD_EGPB 8 /* Erase general-purpose fuse bit */
56 #define SAM4L_FCMD_SSB 9 /* Set security fuses */
57 #define SAM4L_FCMD_PGPFB 10 /* Program general-purpose fuse byte */
58 #define SAM4L_FCMD_EAGPF 11 /* Erase all general-purpose fuse bits */
59 #define SAM4L_FCMD_QPR 12 /* Quick page read */
60 #define SAM4L_FCMD_WUP 13 /* Write user page */
61 #define SAM4L_FCMD_EUP 14 /* Erase user page */
62 #define SAM4L_FCMD_QPRUP 15 /* Quick page read (user page) */
63 #define SAM4L_FCMD_HSEN 16 /* High speed mode enable */
64 #define SAM4L_FCMD_HSDIS 17 /* High speed mode disable */
65 
66 #define SAM4L_FMCD_CMDKEY 0xA5UL /* 'key' to issue commands, see 14.10.2 */
67 
68 
69 /* SMAP registers and bits */
70 #define SMAP_BASE 0x400A3000
71 
72 #define SMAP_SCR (SMAP_BASE + 8)
73 #define SMAP_SCR_HCR (1 << 1)
74 
75 
77  uint32_t id;
78  uint32_t exid;
79  const char *name;
80 };
81 
82 /* These are taken from Table 9-1 in 42023E-SAM-07/2013 */
83 static const struct sam4l_chip_info sam4l_known_chips[] = {
84  { 0xAB0B0AE0, 0x1400000F, "ATSAM4LC8C" },
85  { 0xAB0A09E0, 0x0400000F, "ATSAM4LC4C" },
86  { 0xAB0A07E0, 0x0400000F, "ATSAM4LC2C" },
87  { 0xAB0B0AE0, 0x1300000F, "ATSAM4LC8B" },
88  { 0xAB0A09E0, 0x0300000F, "ATSAM4LC4B" },
89  { 0xAB0A07E0, 0x0300000F, "ATSAM4LC2B" },
90  { 0xAB0B0AE0, 0x1200000F, "ATSAM4LC8A" },
91  { 0xAB0A09E0, 0x0200000F, "ATSAM4LC4A" },
92  { 0xAB0A07E0, 0x0200000F, "ATSAM4LC2A" },
93  { 0xAB0B0AE0, 0x14000002, "ATSAM4LS8C" },
94  { 0xAB0A09E0, 0x04000002, "ATSAM4LS4C" },
95  { 0xAB0A07E0, 0x04000002, "ATSAM4LS2C" },
96  { 0xAB0B0AE0, 0x13000002, "ATSAM4LS8B" },
97  { 0xAB0A09E0, 0x03000002, "ATSAM4LS4B" },
98  { 0xAB0A07E0, 0x03000002, "ATSAM4LS2B" },
99  { 0xAB0B0AE0, 0x12000002, "ATSAM4LS8A" },
100  { 0xAB0A09E0, 0x02000002, "ATSAM4LS4A" },
101  { 0xAB0A07E0, 0x02000002, "ATSAM4LS2A" },
102 };
103 
104 /* Meaning of SRAMSIZ field in CHIPID, see 9.3.1 in 42023E-SAM-07/2013 */
105 static const uint16_t sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 };
106 
107 /* Meaning of PSZ field in FPR, see 14.10.4 in 42023E-SAM-07/2013 */
108 static const uint16_t sam4l_page_sizes[8] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 };
109 
110 struct sam4l_info {
111  const struct sam4l_chip_info *details;
112 
113  uint32_t flash_kb;
114  uint32_t ram_kb;
115  uint32_t page_size;
118  unsigned int pages_per_sector;
119 
120  bool probed;
121  struct target *target;
122 };
123 
124 
126 {
127  volatile unsigned int t = 0;
128  uint32_t st;
129  int res;
130 
131  /* Poll the status register until the FRDY bit is set */
132  do {
134  } while (res == ERROR_OK && !(st & (1<<0)) && ++t < 10);
135 
136  return res;
137 }
138 
139 static int sam4l_flash_check_error(struct target *target, uint32_t *err)
140 {
141  uint32_t st;
142  int res;
143 
145 
146  if (res == ERROR_OK)
147  *err = st & ((1<<3) | (1<<2)); /* grab PROGE and LOCKE bits */
148 
149  return res;
150 }
151 
152 static int sam4l_flash_command(struct target *target, uint8_t cmd, int page)
153 {
154  int res;
155  uint32_t fcmd;
156  uint32_t err;
157 
159  if (res != ERROR_OK)
160  return res;
161 
162  if (page >= 0) {
163  /* Set the page number. For some commands, the page number is just an
164  * argument (ex: fuse bit number). */
165  fcmd = (SAM4L_FMCD_CMDKEY << 24) | ((page & 0xFFFF) << 8) | (cmd & 0x3F);
166  } else {
167  /* Reuse the page number that was read from the flash command register. */
169  if (res != ERROR_OK)
170  return res;
171 
172  fcmd &= ~0x3F; /* clear out the command code */
173  fcmd |= (SAM4L_FMCD_CMDKEY << 24) | (cmd & 0x3F);
174  }
175 
176  /* Send the command */
178  if (res != ERROR_OK)
179  return res;
180 
181  res = sam4l_flash_check_error(target, &err);
182  if (res != ERROR_OK)
183  return res;
184 
185  if (err != 0)
186  LOG_ERROR("%s got error status 0x%08" PRIx32, __func__, err);
187 
189 }
190 
191 FLASH_BANK_COMMAND_HANDLER(sam4l_flash_bank_command)
192 {
193  if (bank->base != SAM4L_FLASH) {
194  LOG_ERROR("Address " TARGET_ADDR_FMT
195  " invalid bank address (try 0x%08" PRIx32
196  "[at91sam4l series] )",
197  bank->base, SAM4L_FLASH);
198  return ERROR_FAIL;
199  }
200 
201  struct sam4l_info *chip;
202  chip = calloc(1, sizeof(*chip));
203  if (!chip) {
204  LOG_ERROR("No memory for flash bank chip info");
205  return ERROR_FAIL;
206  }
207 
208  chip->target = bank->target;
209  chip->probed = false;
210 
211  bank->driver_priv = chip;
212 
213  return ERROR_OK;
214 }
215 
216 static const struct sam4l_chip_info *sam4l_find_chip_name(uint32_t id, uint32_t exid)
217 {
218  unsigned int i;
219 
220  id &= ~0xF;
221 
222  for (i = 0; i < ARRAY_SIZE(sam4l_known_chips); i++) {
223  if (sam4l_known_chips[i].id == id && sam4l_known_chips[i].exid == exid)
224  return &sam4l_known_chips[i];
225  }
226 
227  return NULL;
228 }
229 
230 static int sam4l_check_page_erased(struct flash_bank *bank, uint32_t pn,
231  bool *is_erased_p)
232 {
233  int res;
234  uint32_t st;
235 
236  /* Issue a quick page read to verify that we've erased this page */
237  res = sam4l_flash_command(bank->target, SAM4L_FCMD_QPR, pn);
238  if (res != ERROR_OK) {
239  LOG_ERROR("Quick page read %" PRIu32 " failed", pn);
240  return res;
241  }
242 
243  /* Retrieve the flash status */
244  res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
245  if (res != ERROR_OK) {
246  LOG_ERROR("Couldn't read erase status");
247  return res;
248  }
249 
250  /* Is the page in question really erased? */
251  *is_erased_p = !!(st & (1<<5));
252 
253  return ERROR_OK;
254 }
255 
256 static int sam4l_probe(struct flash_bank *bank)
257 {
258  uint32_t id, exid, param;
259  int res;
260  struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
261 
262  if (chip->probed)
263  return ERROR_OK;
264 
265  res = target_read_u32(bank->target, SAM4L_CHIPID + SAM4L_CIDR, &id);
266  if (res != ERROR_OK) {
267  LOG_ERROR("Couldn't read chip ID");
268  return res;
269  }
270 
271  res = target_read_u32(bank->target, SAM4L_CHIPID + SAM4L_EXID, &exid);
272  if (res != ERROR_OK) {
273  LOG_ERROR("Couldn't read extended chip ID");
274  return res;
275  }
276 
277  chip->details = sam4l_find_chip_name(id, exid);
278 
279  /* The RAM capacity is in a lookup table. */
280  chip->ram_kb = sam4l_ram_sizes[0xF & (id >> 16)];
281 
282  switch (0xF & (id >> 8)) {
283  case 0x07:
284  chip->flash_kb = 128;
285  break;
286  case 0x09:
287  chip->flash_kb = 256;
288  break;
289  case 0x0A:
290  chip->flash_kb = 512;
291  break;
292  default:
293  LOG_ERROR("Unknown flash size (chip ID is %08" PRIx32 "), assuming 128K", id);
294  chip->flash_kb = 128;
295  break;
296  }
297 
298  /* Retrieve the Flash parameters */
299  res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FPR, &param);
300  if (res != ERROR_OK) {
301  LOG_ERROR("Couldn't read Flash parameters");
302  return res;
303  }
304 
305  /* Fetch the page size from the parameter register. Technically the flash
306  * capacity is there too though the manual mentions that not all parts will
307  * have it set so we use the Chip ID capacity information instead. */
308  chip->page_size = sam4l_page_sizes[0x7 & (param >> 8)];
309  assert(chip->page_size);
310  chip->num_pages = chip->flash_kb * 1024 / chip->page_size;
311 
312  chip->sector_size = (chip->flash_kb * 1024) / SAM4L_NUM_SECTORS;
313  chip->pages_per_sector = chip->sector_size / chip->page_size;
314 
315  /* Make sure the bank size is correct */
316  bank->size = chip->flash_kb * 1024;
317 
318  /* Allocate the sector table. */
319  bank->num_sectors = SAM4L_NUM_SECTORS;
320  bank->sectors = calloc(bank->num_sectors, (sizeof((bank->sectors)[0])));
321  if (!bank->sectors)
322  return ERROR_FAIL;
323 
324  /* Fill out the sector information: all SAM4L sectors are the same size and
325  * there is always a fixed number of them. */
326  for (unsigned int i = 0; i < bank->num_sectors; i++) {
327  bank->sectors[i].size = chip->sector_size;
328  bank->sectors[i].offset = i * chip->sector_size;
329  /* mark as unknown */
330  bank->sectors[i].is_erased = -1;
331  bank->sectors[i].is_protected = -1;
332  }
333 
334  /* Done */
335  chip->probed = true;
336 
337  LOG_INFO("SAM4L MCU: %s (Rev %c) (%" PRIu32 "KB Flash with %d %" PRIu32 "B pages, %" PRIu32 "KB RAM)",
338  chip->details ? chip->details->name : "unknown", (char)('A' + (id & 0xF)),
339  chip->flash_kb, chip->num_pages, chip->page_size, chip->ram_kb);
340 
341  return ERROR_OK;
342 }
343 
345 {
346  int res;
347  uint32_t st;
348  struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
349 
350  if (bank->target->state != TARGET_HALTED) {
351  LOG_ERROR("Target not halted");
352 
354  }
355 
356  if (!chip->probed) {
357  if (sam4l_probe(bank) != ERROR_OK)
359  }
360 
361  res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
362  if (res != ERROR_OK)
363  return res;
364 
365  st >>= 16; /* There are 16 lock region bits in the upper half word */
366  for (unsigned int i = 0; i < bank->num_sectors; i++)
367  bank->sectors[i].is_protected = !!(st & (1<<i));
368 
369  return ERROR_OK;
370 }
371 
372 static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first,
373  unsigned int last)
374 {
375  struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
376 
377  if (bank->target->state != TARGET_HALTED) {
378  LOG_ERROR("Target not halted");
379 
381  }
382 
383  if (!chip->probed) {
384  if (sam4l_probe(bank) != ERROR_OK)
386  }
387 
388  /* Make sure the pages make sense. */
389  if (first >= bank->num_sectors || last >= bank->num_sectors) {
390  LOG_ERROR("Protect range %u - %u not valid (%u sectors total)", first, last,
391  bank->num_sectors);
392  return ERROR_FAIL;
393  }
394 
395  /* Try to lock or unlock each sector in the range. This is done by locking
396  * a region containing one page in that sector, we arbitrarily choose the 0th
397  * page in the sector. */
398  for (unsigned int i = first; i <= last; i++) {
399  int res;
400 
401  res = sam4l_flash_command(bank->target,
402  set ? SAM4L_FCMD_LP : SAM4L_FCMD_UP, i * chip->pages_per_sector);
403  if (res != ERROR_OK) {
404  LOG_ERROR("Can't %slock region containing page %d", set ? "" : "un", i);
405  return res;
406  }
407  }
408 
409  return ERROR_OK;
410 }
411 
412 static int sam4l_erase(struct flash_bank *bank, unsigned int first,
413  unsigned int last)
414 {
415  int ret;
416  struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
417 
418  if (bank->target->state != TARGET_HALTED) {
419  LOG_ERROR("Target not halted");
420 
422  }
423 
424  if (!chip->probed) {
425  if (sam4l_probe(bank) != ERROR_OK)
427  }
428 
429  /* Make sure the pages make sense. */
430  if (first >= bank->num_sectors || last >= bank->num_sectors) {
431  LOG_ERROR("Erase range %u - %u not valid (%u sectors total)", first, last,
432  bank->num_sectors);
433  return ERROR_FAIL;
434  }
435 
436  /* Erase */
437  if ((first == 0) && ((last + 1) == bank->num_sectors)) {
438  LOG_DEBUG("Erasing the whole chip");
439 
440  ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EA, -1);
441  if (ret != ERROR_OK) {
442  LOG_ERROR("Erase All failed");
443  return ret;
444  }
445  } else {
446  LOG_DEBUG("Erasing sectors %u through %u...\n", first, last);
447 
448  /* For each sector... */
449  for (unsigned int i = first; i <= last; i++) {
450  /* For each page in that sector... */
451  for (unsigned int j = 0; j < chip->pages_per_sector; j++) {
452  unsigned int pn = i * chip->pages_per_sector + j;
453  bool is_erased = false;
454 
455  /* Issue the page erase */
456  ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EP, pn);
457  if (ret != ERROR_OK) {
458  LOG_ERROR("Erasing page %u failed", pn);
459  return ret;
460  }
461 
462  ret = sam4l_check_page_erased(bank, pn, &is_erased);
463  if (ret != ERROR_OK)
464  return ret;
465 
466  if (!is_erased) {
467  LOG_DEBUG("Page %u was not erased.", pn);
468  return ERROR_FAIL;
469  }
470  }
471  }
472  }
473 
474  return ERROR_OK;
475 }
476 
477 /* Write an entire page from host buffer 'buf' to page-aligned 'address' in the
478  * Flash. */
479 static int sam4l_write_page(struct sam4l_info *chip, struct target *target,
480  uint32_t address, const uint8_t *buf)
481 {
482  int res;
483 
484  LOG_DEBUG("sam4l_write_page address=%08" PRIx32, address);
485 
486  /* Clear the page buffer before we write to it */
488  if (res != ERROR_OK) {
489  LOG_ERROR("%s: can't clear page buffer", __func__);
490  return res;
491  }
492 
493  /* Write the modified page back to the target's page buffer */
494  res = target_write_memory(target, address, 4, chip->page_size / 4, buf);
495 
496  if (res != ERROR_OK) {
497  LOG_ERROR("%s: %d", __func__, __LINE__);
498  return res;
499  }
500 
501  /* Commit the page contents to Flash: erase the current page and then
502  * write it out. */
504  if (res != ERROR_OK)
505  return res;
507 }
508 
509 /* Write partial contents into page-aligned 'address' on the Flash from host
510  * buffer 'buf' by writing 'nb' of 'buf' at 'offset' into the Flash page. */
511 static int sam4l_write_page_partial(struct sam4l_info *chip,
512  struct flash_bank *bank, uint32_t address, const uint8_t *buf,
513  uint32_t page_offset, uint32_t nb)
514 {
515  int res;
516  uint8_t *pg = malloc(chip->page_size);
517  if (!pg)
518  return ERROR_FAIL;
519 
520  LOG_DEBUG("sam4l_write_page_partial address=%08" PRIx32 " nb=%08" PRIx32, address, nb);
521 
522  assert(page_offset + nb < chip->page_size);
523  assert((address % chip->page_size) == 0);
524 
525  /* Retrieve the full page contents from Flash */
526  res = target_read_memory(bank->target, address, 4,
527  chip->page_size / 4, pg);
528  if (res != ERROR_OK) {
529  free(pg);
530  return res;
531  }
532 
533  /* Insert our partial page over the data from Flash */
534  memcpy(pg + (page_offset % chip->page_size), buf, nb);
535 
536  /* Write the page back out */
537  res = sam4l_write_page(chip, bank->target, address, pg);
538  free(pg);
539 
540  return res;
541 }
542 
543 static int sam4l_write(struct flash_bank *bank, const uint8_t *buffer,
544  uint32_t offset, uint32_t count)
545 {
546  int res;
547  uint32_t nb = 0;
548  struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
549 
550  LOG_DEBUG("sam4l_write offset=%08" PRIx32 " count=%08" PRIx32, offset, count);
551 
552  if (bank->target->state != TARGET_HALTED) {
553  LOG_ERROR("Target not halted");
554 
556  }
557 
558  if (!chip->probed) {
559  if (sam4l_probe(bank) != ERROR_OK)
561  }
562 
563  if (offset % chip->page_size) {
564  /* We're starting at an unaligned offset so we'll write a partial page
565  * comprising that offset and up to the end of that page. */
566  nb = chip->page_size - (offset % chip->page_size);
567  if (nb > count)
568  nb = count;
569  } else if (count < chip->page_size) {
570  /* We're writing an aligned but partial page. */
571  nb = count;
572  }
573 
574  if (nb > 0) {
575  res = sam4l_write_page_partial(chip, bank,
576  (offset / chip->page_size) * chip->page_size + bank->base,
577  buffer,
578  offset % chip->page_size, nb);
579  if (res != ERROR_OK)
580  return res;
581 
582  /* We're done with the page contents */
583  count -= nb;
584  offset += nb;
585  }
586 
587  /* There's at least one aligned page to write out. */
588  if (count >= chip->page_size) {
589  assert(chip->page_size > 0);
590  int np = count / chip->page_size + ((count % chip->page_size) ? 1 : 0);
591 
592  for (int i = 0; i < np; i++) {
593  if (count >= chip->page_size) {
594  res = sam4l_write_page(chip, bank->target,
595  bank->base + offset,
596  buffer + (i * chip->page_size));
597  /* Advance one page */
598  offset += chip->page_size;
599  count -= chip->page_size;
600  } else {
601  res = sam4l_write_page_partial(chip, bank,
602  bank->base + offset,
603  buffer + (i * chip->page_size), 0, count);
604  /* We're done after this. */
605  offset += count;
606  count = 0;
607  }
608 
609  if (res != ERROR_OK)
610  return res;
611  }
612  }
613 
614  return ERROR_OK;
615 }
616 
617 
618 COMMAND_HANDLER(sam4l_handle_reset_deassert)
619 {
621  int retval = ERROR_OK;
623 
624  /* If the target has been unresponsive before, try to re-establish
625  * communication now - CPU is held in reset by DSU, DAP is working */
629 
630  /* In case of sysresetreq, debug retains state set in cortex_m_assert_reset()
631  * so we just release reset held by SMAP
632  *
633  * n_RESET (srst) clears the DP, so reenable debug and set vector catch here
634  *
635  * After vectreset SMAP release is not needed however makes no harm
636  */
639  if (retval == ERROR_OK)
642  /* do not return on error here, releasing SMAP reset is more important */
643  }
644 
645  int retval2 = target_write_u32(target, SMAP_SCR, SMAP_SCR_HCR);
646  if (retval2 != ERROR_OK)
647  return retval2;
648 
649  return retval;
650 }
651 
653  {
654  .name = "smap_reset_deassert",
655  .handler = sam4l_handle_reset_deassert,
656  .mode = COMMAND_EXEC,
657  .help = "deassert internal reset held by SMAP",
658  .usage = "",
659  },
661 };
662 
663 static const struct command_registration at91sam4l_command_handlers[] = {
664  {
665  .name = "at91sam4l",
666  .mode = COMMAND_ANY,
667  .help = "at91sam4l flash command group",
668  .usage = "",
670  },
672 };
673 
674 const struct flash_driver at91sam4l_flash = {
675  .name = "at91sam4l",
676  .commands = at91sam4l_command_handlers,
677  .flash_bank_command = sam4l_flash_bank_command,
678  .erase = sam4l_erase,
679  .protect = sam4l_protect,
680  .write = sam4l_write,
681  .read = default_flash_read,
682  .probe = sam4l_probe,
683  .auto_probe = sam4l_probe,
684  .erase_check = default_flash_blank_check,
685  .protect_check = sam4l_protect_check,
686  .free_driver_priv = default_flash_free_driver_priv,
687 };
static const uint16_t sam4l_ram_sizes[16]
Definition: at91sam4l.c:105
const struct flash_driver at91sam4l_flash
Definition: at91sam4l.c:674
static int sam4l_write_page_partial(struct sam4l_info *chip, struct flash_bank *bank, uint32_t address, const uint8_t *buf, uint32_t page_offset, uint32_t nb)
Definition: at91sam4l.c:511
static const struct sam4l_chip_info sam4l_known_chips[]
Definition: at91sam4l.c:83
#define SAM4L_FCMD_CPB
Definition: at91sam4l.c:50
#define SAM4L_EXID
Definition: at91sam4l.c:44
static const uint16_t sam4l_page_sizes[8]
Definition: at91sam4l.c:108
#define SAM4L_FMCD_CMDKEY
Definition: at91sam4l.c:66
#define SMAP_SCR
Definition: at91sam4l.c:72
#define SAM4L_FLASHCALW
Definition: at91sam4l.c:30
static int sam4l_flash_command(struct target *target, uint8_t cmd, int page)
Definition: at91sam4l.c:152
static int sam4l_flash_wait_until_ready(struct target *target)
Definition: at91sam4l.c:125
#define SAM4L_FCMD_UP
Definition: at91sam4l.c:52
#define SMAP_SCR_HCR
Definition: at91sam4l.c:73
#define SAM4L_FSR
Definition: at91sam4l.c:36
#define SAM4L_FCMD_EP
Definition: at91sam4l.c:49
#define SAM4L_CIDR
Definition: at91sam4l.c:43
static int sam4l_probe(struct flash_bank *bank)
Definition: at91sam4l.c:256
static int sam4l_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: at91sam4l.c:543
static const struct command_registration at91sam4l_command_handlers[]
Definition: at91sam4l.c:663
#define SAM4L_NUM_SECTORS
Definition: at91sam4l.c:25
#define SAM4L_FPR
Definition: at91sam4l.c:37
static int sam4l_flash_check_error(struct target *target, uint32_t *err)
Definition: at91sam4l.c:139
FLASH_BANK_COMMAND_HANDLER(sam4l_flash_bank_command)
Definition: at91sam4l.c:191
static int sam4l_write_page(struct sam4l_info *chip, struct target *target, uint32_t address, const uint8_t *buf)
Definition: at91sam4l.c:479
COMMAND_HANDLER(sam4l_handle_reset_deassert)
Definition: at91sam4l.c:618
static const struct sam4l_chip_info * sam4l_find_chip_name(uint32_t id, uint32_t exid)
Definition: at91sam4l.c:216
static int sam4l_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: at91sam4l.c:412
static const struct command_registration at91sam4l_exec_command_handlers[]
Definition: at91sam4l.c:652
#define SAM4L_FCMD
Definition: at91sam4l.c:35
static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: at91sam4l.c:372
#define SAM4L_FCMD_LP
Definition: at91sam4l.c:51
#define SAM4L_FCMD_WP
Definition: at91sam4l.c:48
#define SAM4L_FLASH
Definition: at91sam4l.c:28
#define SAM4L_FCMD_EA
Definition: at91sam4l.c:53
#define SAM4L_CHIPID
Definition: at91sam4l.c:31
#define SAM4L_FCMD_QPR
Definition: at91sam4l.c:59
static int sam4l_check_page_erased(struct flash_bank *bank, uint32_t pn, bool *is_erased_p)
Definition: at91sam4l.c:230
static int sam4l_protect_check(struct flash_bank *bank)
Definition: at91sam4l.c:344
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:151
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
#define DBGKEY
Definition: cortex_m.h:175
#define C_HALT
Definition: cortex_m.h:177
#define VC_BUSERR
Definition: cortex_m.h:191
#define VC_CORERESET
Definition: cortex_m.h:196
#define DCB_DEMCR
Definition: cortex_m.h:89
#define C_DEBUGEN
Definition: cortex_m.h:176
#define DCB_DHCSR
Definition: cortex_m.h:86
#define TRCENA
Definition: cortex_m.h:188
#define VC_HARDERR
Definition: cortex_m.h:189
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t page_size
Page size.
Definition: dw-spi-helper.h:3
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
uint8_t bank
Definition: esirisc.c:135
#define ERROR_FLASH_BANK_NOT_PROBED
Definition: flash/common.h:35
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
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.
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1742
The JTAG interface can be implemented with a software or hardware fifo.
reset_types
Definition: jtag.h:215
@ RESET_HAS_SRST
Definition: jtag.h:218
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_INFO(expr ...)
Definition: log.h:141
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Definition: rtt/rtt.c:32
const char * name
Definition: command.h:239
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
uint32_t id
Definition: at91sam4l.c:77
const char * name
Definition: at91sam4l.c:79
uint32_t exid
Definition: at91sam4l.c:78
const struct sam4l_chip_info * details
Definition: at91sam4l.c:111
uint32_t flash_kb
Definition: at91sam4l.c:113
struct target * target
Definition: at91sam4l.c:121
unsigned int pages_per_sector
Definition: at91sam4l.c:118
uint32_t ram_kb
Definition: at91sam4l.c:114
int num_pages
Definition: at91sam4l.c:116
bool probed
Definition: at91sam4l.c:120
uint32_t page_size
Definition: at91sam4l.c:115
int sector_size
Definition: at91sam4l.c:117
Definition: target.h:119
bool reset_halt
Definition: target.h:154
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:1288
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2635
int target_examine_one(struct target *target)
Examine the specified target, letting it perform any Initialisation that requires JTAG access.
Definition: target.c:685
int target_poll(struct target *target)
Definition: target.c:487
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2561
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
Definition: target.c:1260
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:468
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:817
static bool target_was_examined(const struct target *target)
Definition: target.h:443
@ TARGET_HALTED
Definition: target.h:58
#define TARGET_ADDR_FMT
Definition: types.h:286
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22