OpenOCD
ambiqmicro.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 
3 /******************************************************************************
4  *
5  * @file ambiqmicro.c
6  *
7  * @brief Ambiq Micro flash driver.
8  *
9  *****************************************************************************/
10 
11 /******************************************************************************
12  * Copyright (c) 2015, David Racine <dracine at ambiqmicro.com>
13  *
14  * Copyright (c) 2016, Rick Foos <rfoos at solengtech.com>
15  *
16  * Copyright (c) 2015-2016, Ambiq Micro, Inc.
17  *
18  * All rights reserved.
19  *****************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "jtag/interface.h"
25 #include "imp.h"
26 #include "target/algorithm.h"
27 #include "target/armv7m.h"
28 #include "target/cortex_m.h"
29 
31 #define CHECK_STATUS(rc, msg) { \
32  if (rc != ERROR_OK) { \
33  LOG_ERROR("status(%d):%s\n", rc, msg); } }
34 
35 /*
36  * Address and Key defines.
37  */
38 #define PROGRAM_KEY (0x12344321)
39 #define OTP_PROGRAM_KEY (0x87655678)
40 
41 #define FLASH_PROGRAM_MAIN_FROM_SRAM 0x0800005d
42 #define FLASH_PROGRAM_OTP_FROM_SRAM 0x08000061
43 #define FLASH_ERASE_LIST_MAIN_PAGES_FROM_SRAM 0x08000065
44 #define FLASH_MASS_ERASE_MAIN_PAGES_FROM_SRAM 0x08000069
45 
46 
47 static const uint32_t apollo_flash_size[] = {
48  1 << 15,
49  1 << 16,
50  1 << 17,
51  1 << 18,
52  1 << 19,
53  1 << 20,
54  1 << 21
55 };
56 
57 static const uint32_t apollo_sram_size[] = {
58  1 << 15,
59  1 << 16,
60  1 << 17,
61  1 << 18,
62  1 << 19,
63  1 << 20,
64  1 << 21
65 };
66 
68  /* chip id register */
69 
70  bool probed;
71 
72  const char *target_name;
73  uint8_t target_class;
74 
75  uint32_t sramsiz;
76  uint32_t flshsiz;
77 
78  /* flash geometry */
79  uint32_t num_pages;
80  uint32_t pagesize;
82 
83  /* nv memory bits */
84  uint16_t num_lockbits;
85 
86  /* main clock status */
87  uint32_t rcc;
88  uint32_t rcc2;
89  uint8_t mck_valid;
90  uint8_t xtal_mask;
91  uint32_t iosc_freq;
92  uint32_t mck_freq;
93  const char *iosc_desc;
94  const char *mck_desc;
95 };
96 
97 static struct {
98  uint8_t class;
99  uint8_t partno;
100  const char *partname;
101 } ambiqmicro_parts[6] = {
102  {0xFF, 0x00, "Unknown"},
103  {0x01, 0x00, "Apollo"},
104  {0x02, 0x00, "Apollo2"},
105  {0x03, 0x00, "Unknown"},
106  {0x04, 0x00, "Unknown"},
107  {0x05, 0x00, "Apollo"},
108 };
109 
110 static char *ambiqmicro_classname[6] = {
111  "Unknown", "Apollo", "Apollo2", "Unknown", "Unknown", "Apollo"
112 };
113 
114 /***************************************************************************
115 * openocd command interface *
116 ***************************************************************************/
117 
118 /* flash_bank ambiqmicro <base> <size> 0 0 <target#>
119  */
120 FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
121 {
122  struct ambiqmicro_flash_bank *ambiqmicro_info;
123 
124  if (CMD_ARGC < 6)
126 
127  ambiqmicro_info = calloc(1, sizeof(struct ambiqmicro_flash_bank));
128 
129  bank->driver_priv = ambiqmicro_info;
130 
131  ambiqmicro_info->target_name = "Unknown target";
132 
133  /* part wasn't probed yet */
134  ambiqmicro_info->probed = false;
135 
136  return ERROR_OK;
137 }
138 
140 {
141  struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
142  char *classname;
143 
144  if (!ambiqmicro_info->probed) {
145  LOG_ERROR("Target not probed");
147  }
148 
149  /* Check class name in range. */
150  if (ambiqmicro_info->target_class < sizeof(ambiqmicro_classname))
151  classname = ambiqmicro_classname[ambiqmicro_info->target_class];
152  else
153  classname = ambiqmicro_classname[0];
154 
155  command_print_sameline(cmd, "\nAmbiq Micro information: Chip is "
156  "class %d (%s) %s\n",
157  ambiqmicro_info->target_class,
158  classname,
159  ambiqmicro_info->target_name);
160 
161  return ERROR_OK;
162 }
163 
164 /***************************************************************************
165 * chip identification and status *
166 ***************************************************************************/
167 
168 /* Fill in driver info structure */
170 {
171  struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
172  struct target *target = bank->target;
173  uint32_t part_num = 0;
174  int retval;
175 
176  /*
177  * Read Part Number.
178  */
179  retval = target_read_u32(target, 0x40020000, &part_num);
180  if (retval != ERROR_OK) {
181  LOG_ERROR("status(0x%x):Could not read part_num.\n", retval);
182  /* Set part_num to default device */
183  part_num = 0;
184  }
185  LOG_DEBUG("Part number: 0x%" PRIx32, part_num);
186 
187  /*
188  * Determine device class.
189  */
190  ambiqmicro_info->target_class = (part_num & 0xFF000000) >> 24;
191 
192  switch (ambiqmicro_info->target_class) {
193  case 1: /* 1 - Apollo */
194  case 5: /* 5 - Apollo Bootloader */
195  bank->base = bank->bank_number * 0x40000;
196  ambiqmicro_info->pagesize = 2048;
197  ambiqmicro_info->flshsiz =
198  apollo_flash_size[(part_num & 0x00F00000) >> 20];
199  ambiqmicro_info->sramsiz =
200  apollo_sram_size[(part_num & 0x000F0000) >> 16];
201  ambiqmicro_info->num_pages = ambiqmicro_info->flshsiz /
202  ambiqmicro_info->pagesize;
203  if (ambiqmicro_info->num_pages > 128) {
204  ambiqmicro_info->num_pages = 128;
205  ambiqmicro_info->flshsiz = 1024 * 256;
206  }
207  break;
208 
209  default:
210  LOG_INFO("Unknown Class. Using Apollo-64 as default.");
211 
212  bank->base = bank->bank_number * 0x40000;
213  ambiqmicro_info->pagesize = 2048;
214  ambiqmicro_info->flshsiz = apollo_flash_size[1];
215  ambiqmicro_info->sramsiz = apollo_sram_size[0];
216  ambiqmicro_info->num_pages = ambiqmicro_info->flshsiz /
217  ambiqmicro_info->pagesize;
218  if (ambiqmicro_info->num_pages > 128) {
219  ambiqmicro_info->num_pages = 128;
220  ambiqmicro_info->flshsiz = 1024 * 256;
221  }
222  break;
223  }
224 
225  if (ambiqmicro_info->target_class < ARRAY_SIZE(ambiqmicro_parts))
226  ambiqmicro_info->target_name =
227  ambiqmicro_parts[ambiqmicro_info->target_class].partname;
228  else
229  ambiqmicro_info->target_name =
230  ambiqmicro_parts[0].partname;
231 
232  LOG_DEBUG("num_pages: %" PRIu32 ", pagesize: %" PRIu32 ", flash: %" PRIu32 ", sram: %" PRIu32,
233  ambiqmicro_info->num_pages,
234  ambiqmicro_info->pagesize,
235  ambiqmicro_info->flshsiz,
236  ambiqmicro_info->sramsiz);
237 
238  return ERROR_OK;
239 }
240 
241 /***************************************************************************
242 * flash operations *
243 ***************************************************************************/
244 
246 {
247  struct ambiqmicro_flash_bank *ambiqmicro = bank->driver_priv;
248  int status = ERROR_OK;
249  uint32_t i;
250 
251 
252  if (!ambiqmicro->probed) {
253  LOG_ERROR("Target not probed");
255  }
256 
257  for (i = 0; i < (unsigned) bank->num_sectors; i++)
258  bank->sectors[i].is_protected = -1;
259 
260  return status;
261 }
263 static int check_flash_status(struct target *target, uint32_t address)
264 {
265  uint32_t retflash;
266  int rc;
267  rc = target_read_u32(target, address, &retflash);
268  /* target connection failed. */
269  if (rc != ERROR_OK) {
270  LOG_DEBUG("%s:%d:%s(): status(0x%x)\n",
271  __FILE__, __LINE__, __func__, rc);
272  return rc;
273  }
274  /* target flash failed, unknown cause. */
275  if (retflash != 0) {
276  LOG_ERROR("Flash not happy: status(0x%" PRIx32 ")", retflash);
278  }
279  return ERROR_OK;
280 }
281 
283  uint32_t command,
284  uint32_t flash_return_address)
285 {
286  int retval, retflash;
287 
288  retval = target_resume(
289  target,
290  false,
291  command,
292  true,
293  true);
294 
295  CHECK_STATUS(retval, "error executing ambiqmicro command");
296 
297  /*
298  * Wait for halt.
299  */
300  for (;; ) {
302  if (target->state == TARGET_HALTED)
303  break;
304  else if (target->state == TARGET_RUNNING ||
306  /*
307  * Keep polling until target halts.
308  */
310  alive_sleep(100);
311  } else {
312  LOG_ERROR("Target not halted or running (state is %s)",
314  break;
315  }
316  }
317 
318  /*
319  * Read return value, flash error takes precedence.
320  */
321  retflash = check_flash_status(target, flash_return_address);
322  if (retflash != ERROR_OK)
323  retval = retflash;
324 
325  /* Return code from target_resume OR flash. */
326  return retval;
327 }
328 
330 {
331  struct target *target = NULL;
332  struct ambiqmicro_flash_bank *ambiqmicro_info = NULL;
333  int retval = ERROR_OK;
334 
335  ambiqmicro_info = bank->driver_priv;
336  target = bank->target;
337 
338  if (target->state != TARGET_HALTED) {
339  LOG_ERROR("Target not halted");
341  }
342 
343  if (!ambiqmicro_info->probed) {
344  LOG_ERROR("Target not probed");
346  }
347 
348  /*
349  * Clear Bootloader bit.
350  */
351  retval = target_write_u32(target, 0x400201a0, 0x0);
352  CHECK_STATUS(retval, "error clearing bootloader bit.");
353 
354  /*
355  * Set up the SRAM.
356  */
357 
358  /*
359  * Bank.
360  */
361  retval = target_write_u32(target, 0x10000000, bank->bank_number);
362  CHECK_STATUS(retval, "error writing target SRAM parameters.");
363 
364  /*
365  * Write Key.
366  */
367  retval = target_write_u32(target, 0x10000004, PROGRAM_KEY);
368  CHECK_STATUS(retval, "error writing target SRAM parameters.");
369 
370  /*
371  * Breakpoint.
372  */
373  retval = target_write_u32(target, 0x10000008, 0xfffffffe);
374  CHECK_STATUS(retval, "error writing target SRAM parameters.");
375 
376  /*
377  * Erase the main array.
378  */
379  LOG_INFO("Mass erase on bank %d.", bank->bank_number);
380 
381  /*
382  * passed pc, addr = ROM function, handle breakpoints, not debugging.
383  */
385  CHECK_STATUS(retval, "error executing ambiqmicro flash mass erase.");
386  if (retval != ERROR_OK)
387  return retval;
388 
389  /*
390  * Set Bootloader bit, regardless of command execution.
391  */
392  retval = target_write_u32(target, 0x400201a0, 0x1);
393  CHECK_STATUS(retval, "error setting bootloader bit.");
394 
395  return retval;
396 }
397 
398 
399 static int ambiqmicro_erase(struct flash_bank *bank, unsigned int first,
400  unsigned int last)
401 {
402  struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
403  struct target *target = bank->target;
404  int retval;
405 
406  if (bank->target->state != TARGET_HALTED) {
407  LOG_ERROR("Target not halted");
409  }
410 
411  if (!ambiqmicro_info->probed) {
412  LOG_ERROR("Target not probed");
414  }
415 
416  /*
417  * Check pages.
418  * Fix num_pages for the device.
419  */
420  if ((last < first) || (last >= ambiqmicro_info->num_pages))
422 
423  /*
424  * Just Mass Erase if all pages are given.
425  * TODO: Fix num_pages for the device
426  */
427  if ((first == 0) && (last == (ambiqmicro_info->num_pages - 1)))
428  return ambiqmicro_mass_erase(bank);
429 
430  /*
431  * Clear Bootloader bit.
432  */
433  retval = target_write_u32(target, 0x400201a0, 0x0);
434  CHECK_STATUS(retval, "error clearing bootloader bit.");
435 
436  /*
437  * Set up the SRAM.
438  */
439 
440  /*
441  * Bank.
442  */
443  retval = target_write_u32(target, 0x10000000, bank->bank_number);
444  CHECK_STATUS(retval, "error writing target SRAM parameters.");
445 
446  /*
447  * Number of pages to erase.
448  */
449  retval = target_write_u32(target, 0x10000004, 1 + (last-first));
450  CHECK_STATUS(retval, "error writing target SRAM parameters.");
451 
452  /*
453  * Write Key.
454  */
455  retval = target_write_u32(target, 0x10000008, PROGRAM_KEY);
456  CHECK_STATUS(retval, "error writing target SRAM parameters.");
457 
458  /*
459  * Breakpoint.
460  */
461  retval = target_write_u32(target, 0x1000000c, 0xfffffffe);
462  CHECK_STATUS(retval, "error writing target SRAM parameters.");
463 
464  /*
465  * Pointer to flash address.
466  */
467  retval = target_write_u32(target, 0x10000010, first);
468  CHECK_STATUS(retval, "error writing target SRAM parameters.");
469  if (retval != ERROR_OK)
470  return retval;
471 
472  /*
473  * Erase the pages.
474  */
475  LOG_INFO("Erasing pages %u to %u on bank %u", first, last, bank->bank_number);
476 
477  /*
478  * passed pc, addr = ROM function, handle breakpoints, not debugging.
479  */
481  CHECK_STATUS(retval, "error executing flash page erase");
482  if (retval != ERROR_OK)
483  return retval;
484 
485  LOG_INFO("%u pages erased!", 1+(last-first));
486 
487  if (first == 0) {
488  /*
489  * Set Bootloader bit.
490  */
491  retval = target_write_u32(target, 0x400201a0, 0x1);
492  CHECK_STATUS(retval, "error setting bootloader bit.");
493  if (retval != ERROR_OK)
494  return retval;
495  }
496 
497  return retval;
498 }
499 
500 static int ambiqmicro_protect(struct flash_bank *bank, int set,
501  unsigned int first, unsigned int last)
502 {
503  /* struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
504  * struct target *target = bank->target; */
505 
506  /*
507  * TODO
508  */
509  LOG_INFO("Not yet implemented");
510 
511  if (bank->target->state != TARGET_HALTED) {
512  LOG_ERROR("Target not halted");
514  }
515 
516  return ERROR_OK;
517 }
518 
520  const uint8_t *buffer, uint32_t offset, uint32_t count)
521 {
522  /* struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; */
523  struct target *target = bank->target;
524  uint32_t address = bank->base + offset;
525  uint32_t buffer_pointer = 0x10000010;
526  uint32_t maxbuffer;
527  uint32_t thisrun_count;
528  int retval = ERROR_OK;
529 
530  if (((count%4) != 0) || ((offset%4) != 0)) {
531  LOG_ERROR("write block must be multiple of 4 bytes in offset & length");
532  return ERROR_FAIL;
533  }
534 
535  /*
536  * Max buffer size for this device.
537  * Hard code 6kB for the buffer.
538  */
539  maxbuffer = 0x1800;
540 
541  LOG_INFO("Flashing main array");
542 
543  while (count > 0) {
544  if (count > maxbuffer)
545  thisrun_count = maxbuffer;
546  else
547  thisrun_count = count;
548 
549  /*
550  * Set up the SRAM.
551  */
552 
553  /*
554  * Pointer to flash.
555  */
556  retval = target_write_u32(target, 0x10000000, address);
557  CHECK_STATUS(retval, "error writing target SRAM parameters.");
558 
559  /*
560  * Number of 32-bit words to program.
561  */
562  retval = target_write_u32(target, 0x10000004, thisrun_count/4);
563  CHECK_STATUS(retval, "error writing target SRAM parameters.");
564 
565  /*
566  * Write Key.
567  */
568  retval = target_write_u32(target, 0x10000008, PROGRAM_KEY);
569  CHECK_STATUS(retval, "error writing target SRAM parameters.");
570 
571  /*
572  * Breakpoint.
573  */
574  retval = target_write_u32(target, 0x1000000c, 0xfffffffe);
575  CHECK_STATUS(retval, "error writing target SRAM parameters.");
576 
577  /*
578  * Write Buffer.
579  */
580  retval = target_write_buffer(target, buffer_pointer, thisrun_count, buffer);
581 
582  if (retval != ERROR_OK) {
583  CHECK_STATUS(retval, "error writing target SRAM parameters.");
584  break;
585  }
586 
587  LOG_DEBUG("address = 0x%08" PRIx32, address);
588 
590  CHECK_STATUS(retval, "error executing ambiqmicro flash write algorithm");
591  if (retval != ERROR_OK)
592  break;
593  buffer += thisrun_count;
594  address += thisrun_count;
595  count -= thisrun_count;
596  }
597 
598 
599  LOG_INFO("Main array flashed");
600 
601  /*
602  * Clear Bootloader bit.
603  */
604  retval = target_write_u32(target, 0x400201a0, 0x0);
605  CHECK_STATUS(retval, "error clearing bootloader bit");
606 
607  return retval;
608 }
609 
610 static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer,
611  uint32_t offset, uint32_t count)
612 {
613  int retval;
614 
615  /* try using a block write */
617  if (retval != ERROR_OK)
618  LOG_ERROR("write failed");
619 
620  return retval;
621 }
622 
623 static int ambiqmicro_probe(struct flash_bank *bank)
624 {
625  struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
626  int retval;
627 
628  /* If this is a ambiqmicro chip, it has flash; probe() is just
629  * to figure out how much is present. Only do it once.
630  */
631  if (ambiqmicro_info->probed) {
632  LOG_INFO("Target already probed");
633  return ERROR_OK;
634  }
635 
636  /* ambiqmicro_read_part_info() already handled error checking and
637  * reporting. Note that it doesn't write, so we don't care about
638  * whether the target is halted or not.
639  */
641  if (retval != ERROR_OK)
642  return retval;
643 
644  free(bank->sectors);
645 
646  /* provide this for the benefit of the NOR flash framework */
647  bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages;
648  bank->num_sectors = ambiqmicro_info->num_pages;
649  bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
650  for (unsigned int i = 0; i < bank->num_sectors; i++) {
651  bank->sectors[i].offset = i * ambiqmicro_info->pagesize;
652  bank->sectors[i].size = ambiqmicro_info->pagesize;
653  bank->sectors[i].is_erased = -1;
654  bank->sectors[i].is_protected = -1;
655  }
656 
657  /*
658  * Part has been probed.
659  */
660  ambiqmicro_info->probed = true;
661 
662  return retval;
663 }
664 
666  uint32_t offset, uint32_t count)
667 {
668  struct target *target = NULL;
669  struct ambiqmicro_flash_bank *ambiqmicro_info = NULL;
670  int retval;
671 
672  ambiqmicro_info = bank->driver_priv;
673  target = bank->target;
674 
675  if (target->state != TARGET_HALTED) {
676  LOG_ERROR("Target not halted");
678  }
679 
680  if (!ambiqmicro_info->probed) {
681  LOG_ERROR("Target not probed");
683  }
684 
685  if (count > 256) {
686  LOG_ERROR("Count must be < 256");
688  }
689 
690  /*
691  * Clear Bootloader bit.
692  */
693  retval = target_write_u32(target, 0x400201a0, 0x0);
694  CHECK_STATUS(retval, "error clearing bootloader bit.");
695 
696  /*
697  * Set up the SRAM.
698  */
699 
700  /*
701  * Bank.
702  */
703  retval = target_write_u32(target, 0x10000000, offset);
704  CHECK_STATUS(retval, "error setting target SRAM parameters.");
705 
706  /*
707  * Num of words to program.
708  */
709  retval = target_write_u32(target, 0x10000004, count);
710  CHECK_STATUS(retval, "error setting target SRAM parameters.");
711 
712  /*
713  * Write Key.
714  */
715  retval = target_write_u32(target, 0x10000008, OTP_PROGRAM_KEY);
716  CHECK_STATUS(retval, "error setting target SRAM parameters.");
717 
718  /*
719  * Breakpoint.
720  */
721  retval = target_write_u32(target, 0x1000000c, 0xfffffffe);
722  CHECK_STATUS(retval, "error setting target SRAM parameters.");
723  if (retval != ERROR_OK)
724  return retval;
725 
726  /*
727  * Program OTP.
728  */
729  LOG_INFO("Programming OTP offset 0x%08" PRIx32, offset);
730 
731  /*
732  * passed pc, addr = ROM function, handle breakpoints, not debugging.
733  */
735  CHECK_STATUS(retval, "error executing ambiqmicro otp program algorithm");
736 
737  LOG_INFO("Programming OTP finished.");
738 
739  return retval;
740 }
741 
742 
743 
744 COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command)
745 {
746  if (CMD_ARGC < 1)
748 
749  struct flash_bank *bank;
750  int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
751  if (retval != ERROR_OK)
752  return retval;
753 
755  command_print(CMD, "ambiqmicro mass erase complete");
756  else
757  command_print(CMD, "ambiqmicro mass erase failed");
758 
759  return ERROR_OK;
760 }
761 
762 COMMAND_HANDLER(ambiqmicro_handle_page_erase_command)
763 {
764  struct flash_bank *bank;
765  uint32_t first, last;
766  int retval;
767 
768  if (CMD_ARGC < 3)
770 
771  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], first);
772  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], last);
773 
774  retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
775  if (retval != ERROR_OK)
776  return retval;
777 
778  if (ambiqmicro_erase(bank, first, last) == ERROR_OK)
779  command_print(CMD, "ambiqmicro page erase complete");
780  else
781  command_print(CMD, "ambiqmicro page erase failed");
782 
783  return ERROR_OK;
784 }
785 
786 
790 COMMAND_HANDLER(ambiqmicro_handle_program_otp_command)
791 {
792  struct flash_bank *bank;
793  uint32_t offset, count;
794  int retval;
795 
796  if (CMD_ARGC < 3)
798 
801 
802  command_print(CMD, "offset=0x%08" PRIx32 " count=%" PRIu32, offset, count);
803 
804  CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
805 
807 
808  if (retval != ERROR_OK)
809  LOG_ERROR("error check log");
810 
811  return ERROR_OK;
812 }
813 
814 
815 
817  {
818  .name = "mass_erase",
819  .usage = "<bank>",
820  .handler = ambiqmicro_handle_mass_erase_command,
821  .mode = COMMAND_EXEC,
822  .help = "Erase entire device",
823  },
824  {
825  .name = "page_erase",
826  .usage = "<bank> <first> <last>",
827  .handler = ambiqmicro_handle_page_erase_command,
828  .mode = COMMAND_EXEC,
829  .help = "Erase device pages",
830  },
831  {
832  .name = "program_otp",
833  .handler = ambiqmicro_handle_program_otp_command,
834  .mode = COMMAND_EXEC,
835  .usage = "<bank> <offset> <count>",
836  .help =
837  "Program OTP (assumes you have already written array starting at 0x10000010)",
838  },
840 };
841 static const struct command_registration ambiqmicro_command_handlers[] = {
842  {
843  .name = "ambiqmicro",
844  .mode = COMMAND_EXEC,
845  .help = "ambiqmicro flash command group",
846  .usage = "Support for Ambiq Micro parts.",
848  },
850 };
851 
852 const struct flash_driver ambiqmicro_flash = {
853  .name = "ambiqmicro",
854  .commands = ambiqmicro_command_handlers,
855  .flash_bank_command = ambiqmicro_flash_bank_command,
856  .erase = ambiqmicro_erase,
857  .protect = ambiqmicro_protect,
858  .write = ambiqmicro_write,
859  .read = default_flash_read,
860  .probe = ambiqmicro_probe,
861  .auto_probe = ambiqmicro_probe,
862  .erase_check = default_flash_blank_check,
863  .protect_check = ambiqmicro_protect_check,
864  .info = get_ambiqmicro_info,
865  .free_driver_priv = default_flash_free_driver_priv,
866 };
const struct flash_driver ambiqmicro_flash
Definition: ambiqmicro.c:852
COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command)
Definition: ambiqmicro.c:744
#define PROGRAM_KEY
Definition: ambiqmicro.c:38
const char * partname
Definition: ambiqmicro.c:100
#define FLASH_PROGRAM_MAIN_FROM_SRAM
Definition: ambiqmicro.c:41
static int ambiqmicro_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: ambiqmicro.c:500
#define OTP_PROGRAM_KEY
Definition: ambiqmicro.c:39
static int check_flash_status(struct target *target, uint32_t address)
Read flash status from bootloader.
Definition: ambiqmicro.c:263
static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: ambiqmicro.c:610
static const struct command_registration ambiqmicro_command_handlers[]
Definition: ambiqmicro.c:841
#define FLASH_MASS_ERASE_MAIN_PAGES_FROM_SRAM
Definition: ambiqmicro.c:44
static const uint32_t apollo_flash_size[]
Definition: ambiqmicro.c:47
#define FLASH_ERASE_LIST_MAIN_PAGES_FROM_SRAM
Definition: ambiqmicro.c:43
static int ambiqmicro_otp_program(struct flash_bank *bank, uint32_t offset, uint32_t count)
Definition: ambiqmicro.c:665
static int ambiqmicro_exec_command(struct target *target, uint32_t command, uint32_t flash_return_address)
Definition: ambiqmicro.c:282
static int ambiqmicro_mass_erase(struct flash_bank *bank)
Definition: ambiqmicro.c:329
static int ambiqmicro_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: ambiqmicro.c:519
static const uint32_t apollo_sram_size[]
Definition: ambiqmicro.c:57
static int ambiqmicro_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: ambiqmicro.c:399
static struct @4 ambiqmicro_parts[6]
#define CHECK_STATUS(rc, msg)
Check error, log error.
Definition: ambiqmicro.c:31
uint8_t partno
Definition: ambiqmicro.c:99
static char * ambiqmicro_classname[6]
Definition: ambiqmicro.c:110
#define FLASH_PROGRAM_OTP_FROM_SRAM
Definition: ambiqmicro.c:42
static const struct command_registration ambiqmicro_exec_command_handlers[]
Definition: ambiqmicro.c:816
static int ambiqmicro_read_part_info(struct flash_bank *bank)
Definition: ambiqmicro.c:169
FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
Definition: ambiqmicro.c:120
static int ambiqmicro_protect_check(struct flash_bank *bank)
Definition: ambiqmicro.c:245
static int ambiqmicro_probe(struct flash_bank *bank)
Definition: ambiqmicro.c:623
static int get_ambiqmicro_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: ambiqmicro.c:139
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:348
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:371
#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:400
#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:440
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
@ COMMAND_EXEC
Definition: command.h:40
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
uint8_t bank
Definition: esirisc.c:135
#define ERROR_FLASH_SECTOR_INVALID
Definition: flash/common.h:29
#define ERROR_FLASH_BANK_NOT_PROBED
Definition: flash/common.h:35
#define ERROR_FLASH_OPERATION_FAILED
Definition: flash/common.h:30
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
Definition: flash/common.h:32
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.
void alive_sleep(uint64_t ms)
Definition: log.c:468
#define ERROR_FAIL
Definition: log.h:174
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
const char * iosc_desc
Definition: ambiqmicro.c:93
const char * mck_desc
Definition: ambiqmicro.c:94
const char * target_name
Definition: ambiqmicro.c:72
uint32_t pages_in_lockregion
Definition: ambiqmicro.c:81
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:234
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
Definition: target.h:119
enum target_state state
Definition: target.h:160
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2351
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2650
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:269
int target_poll(struct target *target)
Definition: target.c:486
int target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
Definition: target.c:565
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2559
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:786
@ TARGET_DEBUG_RUNNING
Definition: target.h:60
@ TARGET_HALTED
Definition: target.h:58
@ TARGET_RUNNING
Definition: target.h:57
#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 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