OpenOCD
am13e230x.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2026 Texas Instruments Incorporated - https://www.ti.com/
5  *
6  * NOR flash driver for AM13E230X class of uC from Texas Instruments.
7  *
8  * Erase uses direct register writes via the debug probe.
9  * Write uses an on-device algorithm loaded into SRAM
10  * (see contrib/loaders/flash/am13e230x/ and flash.h).
11  ***************************************************************************/
12 
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #include "imp.h"
18 #include <helper/binarybuffer.h>
19 #include <helper/bits.h>
20 #include <helper/time_support.h>
21 #include <target/algorithm.h>
22 #include <target/armv7m.h>
23 
24 /* Region memory map */
25 #define AM13_FLASH_BASE_MAIN 0x00000000
26 #define AM13_FLASH_BASE_NONMAIN 0x60100000
27 #define AM13_NONMAIN_SIZE_PER_BANK 0x1000
28 
29 /*
30  * Factory region registers (at 0x60111000, in the non-main flash area).
31  *
32  * AM13_DID (0x60111004) is the DEVICEID / JTAGIDCODE register ("the
33  * JTAGIDCODE that comes from the Ramp system", per TRM SPRUJF2A Table
34  * 18-1). Its manufacturer ID field lives in bits[11:1] per the JTAG
35  * IEEE 1149.1 encoding, which is what am13_probe() validates.
36  *
37  * This is distinct from PARTIDL/PARTIDH at 0x0005D008, which encode
38  * package type and quality grade. Those fields are not used here
39  * because they vary by package variant and are not needed to confirm
40  * that the target is an AM13E230X-class device.
41  */
42 #define AM13_FACTORYREGION 0x60111000
43 #define AM13_TRACEID (AM13_FACTORYREGION + 0x000)
44 #define AM13_DID (AM13_FACTORYREGION + 0x004) /* JTAGIDCODE */
45 #define AM13_SRAMFLASH (AM13_FACTORYREGION + 0x01C)
46 
47 /* Flash controller (NVMNW) registers */
48 #define FLASH_CONTROL_BASE 0x40042000
49 #define FCTL_REG_CMDEXEC (FLASH_CONTROL_BASE + 0x1100)
50 #define FCTL_REG_CMDTYPE (FLASH_CONTROL_BASE + 0x1104)
51 #define FCTL_REG_CMDADDR (FLASH_CONTROL_BASE + 0x1120)
52 #define FCTL_REG_CMDBYTEN (FLASH_CONTROL_BASE + 0x1124)
53 #define FCTL_REG_CMDDATAINDEX (FLASH_CONTROL_BASE + 0x112C)
54 #define FCTL_REG_CMDDATA0 (FLASH_CONTROL_BASE + 0x1130)
55 #define FCTL_REG_CMDWEPROTA (FLASH_CONTROL_BASE + 0x11D0)
56 #define FCTL_REG_CMDWEPROTB (FLASH_CONTROL_BASE + 0x11D4)
57 #define FCTL_REG_CMDWEPROTNM (FLASH_CONTROL_BASE + 0x1210)
58 #define FCTL_REG_STATCMD (FLASH_CONTROL_BASE + 0x13D0)
59 
60 /* GSC flash semaphore registers */
61 #define GSC_BASE 0x40046000
62 #define GSC_REG_FPC_FLSEMREQ (GSC_BASE + 0x1800)
63 #define GSC_REG_FPC_FLSEMCLR (GSC_BASE + 0x1804)
64 
65 /* STATCMD bits */
66 #define FCTL_STATCMD_CMDDONE 0x00000001
67 #define FCTL_STATCMD_CMDPASS 0x00000002
68 #define FCTL_STATCMD_CMDINPROGRESS 0x00000004
69 
70 /* CMDEXEC / CMDTYPE constants */
71 #define FCTL_CMDEXEC_EXECUTE 0x00000001
72 #define FCTL_CMDTYPE_PROGRAM 0x00000001
73 #define FCTL_CMDTYPE_ERASE 0x00000002
74 #define FCTL_CMDTYPE_CLEARSTATUS 0x00000005
75 #define FCTL_CMDTYPE_SIZE_ONEWORD 0x00000000
76 #define FCTL_CMDTYPE_SIZE_SECTOR 0x00000040
77 
78 #define AM13_FLASH_WORD_SIZE 16
79 
80 #define AM13_FLASH_TIMEOUT_MS 8000
81 #define AM13_SECTOR_SIZE_BYTES 0x800
82 #define TI_MANUFACTURER_ID 0x17
83 
84 /* Algorithm is loaded at the base of SRAM */
85 #define AM13_ALGO_BASE 0x20000000
86 
87 /* Parameter blocks (two, for ping-pong) */
88 #define AM13_ALGO_PARAMS_0 0x20002000
89 #define AM13_ALGO_PARAMS_1 0x20002014
90 
91 /* Data buffers (each one sector = 2 KB) */
92 #define AM13_ALGO_BUFFER_0 0x20002100
93 #define AM13_ALGO_BUFFER_1 0x20002900
94 
95 /* Total working area needed */
96 #define AM13_ALGO_WORKING_SIZE (AM13_ALGO_BUFFER_1 + 0x800 - AM13_ALGO_BASE)
97 
98 /* Handshake values (must match loader main.c) */
99 #define AM13_BUFFER_EMPTY 0x00000000
100 #define AM13_BUFFER_FULL 0xFFFFFFFF
101 
102 /* Offset of the status field within flash_params */
103 #define AM13_STATUS_OFFSET 0x0C
104 
105 /* Commands (must match loader main.c) */
106 #define AM13_CMD_NO_ACTION 0
107 #define AM13_CMD_PROGRAM 1
108 #define AM13_CMD_ERASE_AND_PROGRAM 2
109 #define AM13_CMD_ERASE_SECTORS 3
110 
111 /* Parameter block layout (matches struct flash_params in loader) */
113  uint8_t dest[4];
114  uint8_t len[4];
115  uint8_t cmd[4];
116  uint8_t status[4];
117  uint8_t buf_addr[4];
118 };
119 
120 /* Flash loader algorithm binary */
121 static const uint8_t am13_algo[] = {
122 #include "../../../contrib/loaders/flash/am13e230x/am13e230x_algo.inc"
123 };
124 
126  uint32_t did;
127  uint32_t traceid;
128  unsigned int main_flash_size_kb;
129  unsigned int main_flash_num_banks;
130  unsigned int sram_size_kb;
131  unsigned int sector_size;
132 
133  /* Algorithm state */
136 };
137 
138 static int am13_auto_probe(struct flash_bank *bank);
139 
140 /*
141  * GSC flash semaphore must be held before any flash operation.
142  * The debug probe and the CPU have separate ownership tracking
143  * (FLSEMSTAT.DBGACC), so the erase path (debug probe) and the
144  * write path (on-device algorithm) each acquire it independently.
145  */
146 
148 {
149  int retval = target_write_u32(bank->target, GSC_REG_FPC_FLSEMREQ, 1);
150  if (retval != ERROR_OK)
151  LOG_ERROR("AM13: failed to acquire GSC flash semaphore");
152  return retval;
153 }
154 
156 {
157  int retval = target_write_u32(bank->target, GSC_REG_FPC_FLSEMCLR, 1);
158  if (retval != ERROR_OK)
159  LOG_ERROR("AM13: failed to release GSC flash semaphore");
160  return retval;
161 }
162 
163 /* ---------- Flash controller helpers (erase path only) ---------- */
164 
165 static const struct {
166  unsigned char bit;
167  const char *name;
168 } am13_fctl_errors[] = {
169  { 2, "CMDINPROGRESS" },
170  { 4, "FAILWEPROT" },
171  { 5, "FAILVERIFY" },
172  { 6, "FAILILLADDR" },
173  { 7, "FAILMODE" },
174  { 12, "FAILMISC" },
175 };
176 
177 static const char *am13_fctl_strerror(uint32_t status)
178 {
179  for (unsigned int i = 0; i < ARRAY_SIZE(am13_fctl_errors); i++) {
180  if (status & BIT(am13_fctl_errors[i].bit))
181  return am13_fctl_errors[i].name;
182  }
183  return "FAILUNKNOWN";
184 }
185 
187 {
188  struct target *target = bank->target;
189  uint32_t status = 0;
190  int64_t start_ms = timeval_ms();
191  bool timed_out = false;
192 
193  while ((status & FCTL_STATCMD_CMDDONE) == 0) {
195  if (retval != ERROR_OK)
196  return retval;
197  if (timeval_ms() - start_ms > AM13_FLASH_TIMEOUT_MS) {
198  timed_out = true;
199  break;
200  }
201  keep_alive();
202  }
203 
204  if ((status & FCTL_STATCMD_CMDPASS) == 0) {
205  if (timed_out)
206  LOG_ERROR("AM13: flash command timed out after %d ms", AM13_FLASH_TIMEOUT_MS);
207  else
208  LOG_ERROR("AM13: flash command failed: %s", am13_fctl_strerror(status));
209  return ERROR_FAIL;
210  }
211 
212  return ERROR_OK;
213 }
214 
216 {
217  struct target *target = bank->target;
218  uint32_t status;
219  int64_t start_ms;
220  int retval;
221 
223  if (retval != ERROR_OK)
224  return retval;
225 
227  if (retval != ERROR_OK)
228  return retval;
229 
230  start_ms = timeval_ms();
231  do {
233  if (retval != ERROR_OK)
234  return retval;
235  if (timeval_ms() - start_ms > AM13_FLASH_TIMEOUT_MS) {
236  LOG_ERROR("Timeout waiting for clear status");
237  return ERROR_FAIL;
238  }
239  keep_alive();
241 
242  return ERROR_OK;
243 }
244 
246 {
247  struct target *target = bank->target;
248  int retval;
249 
250  switch (bank->base) {
253  if (retval != ERROR_OK)
254  return retval;
258  default:
260  }
261 }
262 
263 static int am13_fctl_erase(struct flash_bank *bank, uint32_t addr, uint32_t cmd_size)
264 {
265  struct target *target = bank->target;
266  int retval;
267 
268  retval = am13_fctl_clear_status(bank);
269  if (retval != ERROR_OK)
270  return retval;
271 
272  retval = am13_fctl_unprotect(bank);
273  if (retval != ERROR_OK)
274  return retval;
275 
277  FCTL_CMDTYPE_ERASE | cmd_size);
278  if (retval != ERROR_OK)
279  return retval;
280 
281  retval = target_write_u32(target, FCTL_REG_CMDADDR, addr & 0xFFFFFFF0);
282  if (retval != ERROR_OK)
283  return retval;
284 
286  if (retval != ERROR_OK)
287  return retval;
288 
289  return am13_fctl_wait_done(bank);
290 }
291 
292 /* ---------- Flash driver callbacks ---------- */
293 
294 FLASH_BANK_COMMAND_HANDLER(am13_flash_bank_command)
295 {
296  switch (bank->base) {
299  break;
300  default:
301  LOG_ERROR("Invalid bank address " TARGET_ADDR_FMT, bank->base);
302  return ERROR_FAIL;
303  }
304 
305  struct am13_flash_bank *am13_info = calloc(1, sizeof(*am13_info));
306  if (!am13_info)
307  return ERROR_FAIL;
308 
309  bank->driver_priv = am13_info;
310  am13_info->sector_size = AM13_SECTOR_SIZE_BYTES;
311 
312  bank->write_start_alignment = AM13_FLASH_WORD_SIZE;
313  bank->write_end_alignment = AM13_FLASH_WORD_SIZE;
314 
315  return ERROR_OK;
316 }
317 
318 static int am13_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
319 {
320  struct am13_flash_bank *am13_info = bank->driver_priv;
321  int retval;
322 
323  if (bank->target->state != TARGET_HALTED) {
324  LOG_ERROR("Target not halted");
326  }
327 
329  if (retval != ERROR_OK)
330  return retval;
331 
332  for (unsigned int s = first; s <= last; s++) {
333  if (bank->sectors[s].is_protected) {
334  LOG_WARNING("AM13: NONMAIN sector %u (0x%08" TARGET_PRIxADDR
335  ") is factory-protected, skipping",
336  s, bank->base + s * am13_info->sector_size);
337  continue;
338  }
339 
340  uint32_t addr = bank->base + s * am13_info->sector_size;
341 
343  if (retval != ERROR_OK) {
344  LOG_ERROR("AM13: Sector erase failed at 0x%08" PRIx32 ", returned %d", addr, retval);
346  return retval;
347  }
348  }
349 
351 }
352 
353 /* ---------- Direct write fallback (via debug probe) ---------- */
354 
355 /*
356  * Word-by-word flash write using direct register access from the debug
357  * probe. Slower than the on-device algorithm but does not require SRAM,
358  * so it works as a fallback when the algorithm cannot be loaded (e.g.,
359  * SRAM is needed by a RAM-resident application).
360  */
361 static int am13_write_direct(struct flash_bank *bank, const uint8_t *buffer,
362  uint32_t offset, uint32_t count)
363 {
364  if (count == 0)
365  return ERROR_OK;
366 
367  struct target *target = bank->target;
368  uint32_t addr = bank->base + offset;
369  int retval = 0;
370 
372  if (retval != ERROR_OK)
373  return retval;
374 
375  while (count > 0) {
376  /* Clear status + unprotect before every word (per SDK) */
377  retval = am13_fctl_clear_status(bank);
378  if (retval != ERROR_OK)
379  break;
380 
381  retval = am13_fctl_unprotect(bank);
382  if (retval != ERROR_OK)
383  break;
384 
387  if (retval != ERROR_OK)
388  break;
389 
390  /* All 16 data bytes + both ECC chunks (bits 16-17) enabled */
391  retval = target_write_u32(target, FCTL_REG_CMDBYTEN, 0x0003FFFF);
392  if (retval != ERROR_OK)
393  break;
394 
396  if (retval != ERROR_OK)
397  break;
398 
400  (addr >> 4) & 3);
401  if (retval != ERROR_OK)
402  break;
403 
405  if (retval != ERROR_OK)
406  break;
407 
410  if (retval != ERROR_OK)
411  break;
412 
413  retval = am13_fctl_wait_done(bank);
414  if (retval != ERROR_OK)
415  break;
416 
420  }
421 
422  int sem_ret = am13_clear_gsc_semaphore(bank);
423  return (retval != ERROR_OK) ? retval : sem_ret;
424 }
425 
426 /* ---------- Flash loader algorithm ---------- */
427 
428 static int am13_algo_init(struct flash_bank *bank)
429 {
430  struct target *target = bank->target;
431  struct am13_flash_bank *am13_info = bank->driver_priv;
432  int retval;
433 
434  /* Allocate SRAM for algorithm + buffers */
436  am13_info->working_area = NULL;
437 
439  &am13_info->working_area);
440  if (retval != ERROR_OK) {
441  LOG_ERROR("AM13: insufficient SRAM for flash loader (%u bytes)",
443  return retval;
444  }
445 
446  /*
447  * The flash loader is not position-independent: it references
448  * parameter blocks (AM13_ALGO_PARAMS_0/1) and data buffers
449  * (AM13_ALGO_BUFFER_0/1) at absolute SRAM addresses assembled
450  * into the binary. The working area must start exactly at
451  * AM13_ALGO_BASE (0x20000000).
452  */
453  if (am13_info->working_area->address != AM13_ALGO_BASE) {
454  LOG_ERROR("AM13: working area allocated at 0x%08" TARGET_PRIxADDR
455  ", need 0x%08x; set '_WORKAREABASE 0x%08x' in target config",
456  am13_info->working_area->address,
459  am13_info->working_area = NULL;
461  }
462 
464  if (retval != ERROR_OK) {
465  LOG_ERROR("AM13: failed to load flash algorithm");
467  am13_info->working_area = NULL;
468  return retval;
469  }
470 
471  /*
472  * Release any debug-held GSC semaphore so the algorithm (CPU)
473  * can acquire it — the flash controller tracks ownership via
474  * FLSEMSTAT.DBGACC and rejects mismatched access.
475  */
476  retval = am13_clear_gsc_semaphore(bank);
477  if (retval != ERROR_OK) {
479  am13_info->working_area = NULL;
480  return retval;
481  }
482 
485 
486  LOG_DEBUG("AM13: starting flash algorithm");
487  retval = target_start_algorithm(target, 0, NULL, 0, NULL,
488  AM13_ALGO_BASE, 0,
489  &am13_info->armv7m_info);
490 
491  if (retval != ERROR_OK) {
492  LOG_ERROR("AM13: failed to start flash algorithm");
493  goto err_free_working_area;
494  }
495 
496  return ERROR_OK;
497 
498 err_free_working_area:
500  am13_info->working_area = NULL;
501  return retval;
502 }
503 
504 static int am13_algo_quit(struct flash_bank *bank)
505 {
506  struct target *target = bank->target;
507  struct am13_flash_bank *am13_info = bank->driver_priv;
508 
509  (void)target_halt(target);
510 
511  int retval = target_wait_algorithm(target, 0, NULL, 0, NULL,
513  &am13_info->armv7m_info);
514 
515  int sem_ret = am13_clear_gsc_semaphore(bank);
516 
518  am13_info->working_area = NULL;
519 
520  return (retval != ERROR_OK) ? retval : sem_ret;
521 }
522 
523 static int am13_algo_wait_done(struct flash_bank *bank, uint32_t params_addr)
524 {
525  struct target *target = bank->target;
526  uint32_t status = AM13_BUFFER_FULL;
527  int64_t start_ms = timeval_ms();
528  int retval;
529  bool timed_out = false;
530 
531  while (status == AM13_BUFFER_FULL) {
532  retval = target_read_u32(target, params_addr + AM13_STATUS_OFFSET,
533  &status);
534  if (retval != ERROR_OK)
535  return retval;
536 
537  int64_t elapsed_ms = timeval_ms() - start_ms;
538  if (elapsed_ms > 500)
539  keep_alive();
540  if (elapsed_ms > AM13_FLASH_TIMEOUT_MS) {
541  timed_out = true;
542  break;
543  }
544  }
545 
546  if (timed_out) {
547  LOG_ERROR("AM13: flash algorithm timed out after %d ms", AM13_FLASH_TIMEOUT_MS);
548  return ERROR_FAIL;
549  }
550 
551  if (status != AM13_BUFFER_EMPTY) {
552  LOG_ERROR("AM13: flash algorithm error, status=0x%08" PRIx32,
553  status);
554  return ERROR_FAIL;
555  }
556 
557  return ERROR_OK;
558 }
559 
560 static int am13_write(struct flash_bank *bank, const uint8_t *buffer,
561  uint32_t offset, uint32_t count)
562 {
563  struct target *target = bank->target;
564  struct am13_algo_params algo_params[2];
565  int retval;
566 
567  if (target->state != TARGET_HALTED) {
568  LOG_ERROR("Target not halted");
570  }
571 
572  retval = am13_algo_init(bank);
573  if (retval != ERROR_OK) {
574  LOG_INFO("AM13: algorithm unavailable, falling back to direct writes");
576  }
577 
578  static const uint32_t params_addr[] = {
580  };
581  static const uint32_t buffer_addr[] = {
583  };
584 
585  uint32_t address = bank->base + offset;
586  uint32_t index = 0;
587  int64_t start_ms = timeval_ms();
588 
589  buf_set_u32(algo_params[0].cmd, 0, 32, AM13_CMD_PROGRAM);
590  buf_set_u32(algo_params[1].cmd, 0, 32, AM13_CMD_PROGRAM);
591 
592  while (count > 0) {
594 
595  retval = target_write_buffer(target, buffer_addr[index], size, buffer);
596  if (retval != ERROR_OK)
597  break;
598 
599  buf_set_u32(algo_params[index].dest, 0, 32, address);
600  buf_set_u32(algo_params[index].len, 0, 32, size);
601  buf_set_u32(algo_params[index].status, 0, 32, AM13_BUFFER_FULL);
602 
603  /* Write dest/len/cmd/status only — preserve algorithm's buf_addr */
604  retval = target_write_buffer(target, params_addr[index],
605  offsetof(struct am13_algo_params, buf_addr),
606  (uint8_t *)&algo_params[index]);
607  if (retval != ERROR_OK)
608  break;
609 
610  index ^= 1;
611  retval = am13_algo_wait_done(bank, params_addr[index]);
612  if (retval != ERROR_OK)
613  break;
614 
615  count -= size;
616  buffer += size;
617  address += size;
618 
619  if (timeval_ms() - start_ms > 500)
620  keep_alive();
621  }
622 
623  /* Wait for the last submitted buffer */
624  if (retval == ERROR_OK) {
625  index ^= 1;
626  retval = am13_algo_wait_done(bank, params_addr[index]);
627  }
628 
629  int quit_ret = am13_algo_quit(bank);
630  return (retval != ERROR_OK) ? retval : quit_ret;
631 }
632 
633 /* ---------- Probe ---------- */
634 
635 static int am13_probe(struct flash_bank *bank)
636 {
637  struct target *target = bank->target;
638  struct am13_flash_bank *am13_info = bank->driver_priv;
639  uint32_t did, sramflash;
640  int retval;
641 
642  retval = target_read_u32(target, AM13_DID, &did);
643  if (retval != ERROR_OK)
644  return retval;
645 
646  if (((did & GENMASK(11, 1)) >> 1) != TI_MANUFACTURER_ID) {
647  LOG_ERROR("AM13: unexpected manufacturer ID in DID=0x%08" PRIx32,
648  did);
649  return ERROR_FAIL;
650  }
651 
652  am13_info->did = did;
653 
654  retval = target_read_u32(target, AM13_TRACEID, &am13_info->traceid);
655  if (retval != ERROR_OK)
656  return retval;
657 
658  retval = target_read_u32(target, AM13_SRAMFLASH, &sramflash);
659  if (retval != ERROR_OK)
660  return retval;
661 
662  am13_info->main_flash_size_kb = sramflash & GENMASK(11, 0);
663  am13_info->main_flash_num_banks = (sramflash & GENMASK(13, 12)) >> 12;
664  am13_info->sram_size_kb = (sramflash & GENMASK(25, 16)) >> 16;
665 
666  free(bank->sectors);
667  bank->sectors = NULL;
668 
669  unsigned int num_sectors;
670  switch (bank->base) {
672  bank->size = am13_info->main_flash_size_kb * 1024;
673  num_sectors = bank->size / am13_info->sector_size;
674  break;
677  num_sectors = bank->size / am13_info->sector_size;
678  break;
679  default:
680  LOG_ERROR("Invalid bank address " TARGET_ADDR_FMT, bank->base);
681  return ERROR_FAIL;
682  }
683 
684  if (num_sectors == 0) {
685  bank->num_sectors = 0;
686  bank->size = 0;
687  return ERROR_OK;
688  }
689 
690  bank->num_sectors = num_sectors;
691  bank->sectors = calloc(num_sectors, sizeof(struct flash_sector));
692  if (!bank->sectors)
693  return ERROR_FAIL;
694 
695  /*
696  * NONMAIN sector 0 of each bank contains factory trim and boot
697  * configuration records that are hardware-permanently protected.
698  * The NVMNW returns FAILILLADDR for any erase attempt on them.
699  */
700  unsigned int sectors_per_nm_bank =
701  (bank->base == AM13_FLASH_BASE_NONMAIN)
703  : 0;
704 
705  for (unsigned int i = 0; i < num_sectors; i++) {
706  bank->sectors[i].offset = i * am13_info->sector_size;
707  bank->sectors[i].size = am13_info->sector_size;
708  bank->sectors[i].is_erased = -1;
709  bank->sectors[i].is_protected =
710  (sectors_per_nm_bank && (i % sectors_per_nm_bank) == 0) ? 1 : 0;
711  }
712 
713  LOG_INFO("AM13: %s flash: %u KB (%u sectors), %u bank(s), SRAM: %u KB",
714  (bank->base == AM13_FLASH_BASE_MAIN) ? "MAIN" : "NONMAIN",
715  (unsigned int)(bank->size / 1024), num_sectors,
716  am13_info->main_flash_num_banks,
717  am13_info->sram_size_kb);
718 
719  return ERROR_OK;
720 }
721 
722 static int am13_auto_probe(struct flash_bank *bank)
723 {
724  struct am13_flash_bank *am13_info = bank->driver_priv;
725 
726  if (am13_info->did)
727  return ERROR_OK;
728 
729  return am13_probe(bank);
730 }
731 
732 static int get_am13_info(struct flash_bank *bank,
733  struct command_invocation *cmd)
734 {
735  struct am13_flash_bank *am13_info = bank->driver_priv;
736 
737  command_print_sameline(cmd, "AM13E23X: DID=0x%08" PRIx32
738  " TRACEID=0x%08" PRIx32
739  " banks=%u",
740  am13_info->did, am13_info->traceid,
741  am13_info->main_flash_num_banks);
742  return ERROR_OK;
743 }
744 
745 const struct flash_driver am13_flash = {
746  .name = "am13",
747  .flash_bank_command = am13_flash_bank_command,
748  .erase = am13_erase,
749  .protect = NULL,
750  .write = am13_write,
751  .read = default_flash_read,
752  .probe = am13_probe,
753  .auto_probe = am13_auto_probe,
754  .erase_check = default_flash_blank_check,
755  .protect_check = NULL,
756  .info = get_am13_info,
757  .free_driver_priv = default_flash_free_driver_priv,
758 };
#define AM13_ALGO_BASE
Definition: am13e230x.c:85
static const struct @4 am13_fctl_errors[]
static const uint8_t am13_algo[]
Definition: am13e230x.c:121
static int am13_algo_quit(struct flash_bank *bank)
Definition: am13e230x.c:504
#define AM13_DID
Definition: am13e230x.c:44
#define FCTL_CMDTYPE_SIZE_SECTOR
Definition: am13e230x.c:76
static int am13_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: am13e230x.c:560
static int am13_probe(struct flash_bank *bank)
Definition: am13e230x.c:635
#define AM13_ALGO_BUFFER_0
Definition: am13e230x.c:92
static int am13_write_direct(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: am13e230x.c:361
#define FCTL_REG_STATCMD
Definition: am13e230x.c:58
#define FCTL_CMDTYPE_PROGRAM
Definition: am13e230x.c:72
static int am13_algo_init(struct flash_bank *bank)
Definition: am13e230x.c:428
#define FCTL_CMDEXEC_EXECUTE
Definition: am13e230x.c:71
static int am13_fctl_unprotect(struct flash_bank *bank)
Definition: am13e230x.c:245
#define AM13_CMD_PROGRAM
Definition: am13e230x.c:107
#define FCTL_REG_CMDTYPE
Definition: am13e230x.c:50
#define AM13_FLASH_BASE_NONMAIN
Definition: am13e230x.c:26
static int am13_clear_gsc_semaphore(struct flash_bank *bank)
Definition: am13e230x.c:155
#define AM13_ALGO_BUFFER_1
Definition: am13e230x.c:93
#define FCTL_REG_CMDBYTEN
Definition: am13e230x.c:52
#define AM13_NONMAIN_SIZE_PER_BANK
Definition: am13e230x.c:27
#define AM13_ALGO_WORKING_SIZE
Definition: am13e230x.c:96
#define FCTL_STATCMD_CMDPASS
Definition: am13e230x.c:67
#define AM13_FLASH_BASE_MAIN
Definition: am13e230x.c:25
#define AM13_FLASH_TIMEOUT_MS
Definition: am13e230x.c:80
static int am13_fctl_clear_status(struct flash_bank *bank)
Definition: am13e230x.c:215
#define AM13_BUFFER_FULL
Definition: am13e230x.c:100
#define AM13_FLASH_WORD_SIZE
Definition: am13e230x.c:78
const char * name
Definition: am13e230x.c:167
static int am13_fctl_erase(struct flash_bank *bank, uint32_t addr, uint32_t cmd_size)
Definition: am13e230x.c:263
#define FCTL_REG_CMDDATAINDEX
Definition: am13e230x.c:53
#define FCTL_REG_CMDADDR
Definition: am13e230x.c:51
#define AM13_ALGO_PARAMS_0
Definition: am13e230x.c:88
#define AM13_ALGO_PARAMS_1
Definition: am13e230x.c:89
#define FCTL_REG_CMDWEPROTB
Definition: am13e230x.c:56
#define FCTL_CMDTYPE_ERASE
Definition: am13e230x.c:73
#define AM13_SECTOR_SIZE_BYTES
Definition: am13e230x.c:81
#define FCTL_REG_CMDEXEC
Definition: am13e230x.c:49
#define FCTL_CMDTYPE_CLEARSTATUS
Definition: am13e230x.c:74
#define AM13_TRACEID
Definition: am13e230x.c:43
static int am13_algo_wait_done(struct flash_bank *bank, uint32_t params_addr)
Definition: am13e230x.c:523
#define AM13_STATUS_OFFSET
Definition: am13e230x.c:103
static int am13_fctl_wait_done(struct flash_bank *bank)
Definition: am13e230x.c:186
#define TI_MANUFACTURER_ID
Definition: am13e230x.c:82
#define GSC_REG_FPC_FLSEMCLR
Definition: am13e230x.c:63
#define FCTL_STATCMD_CMDDONE
Definition: am13e230x.c:66
FLASH_BANK_COMMAND_HANDLER(am13_flash_bank_command)
Definition: am13e230x.c:294
#define FCTL_STATCMD_CMDINPROGRESS
Definition: am13e230x.c:68
#define AM13_BUFFER_EMPTY
Definition: am13e230x.c:99
#define AM13_SRAMFLASH
Definition: am13e230x.c:45
static const char * am13_fctl_strerror(uint32_t status)
Definition: am13e230x.c:177
#define FCTL_REG_CMDWEPROTA
Definition: am13e230x.c:55
unsigned char bit
Definition: am13e230x.c:166
#define GSC_REG_FPC_FLSEMREQ
Definition: am13e230x.c:62
static int am13_auto_probe(struct flash_bank *bank)
Definition: am13e230x.c:722
static int get_am13_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: am13e230x.c:732
#define FCTL_CMDTYPE_SIZE_ONEWORD
Definition: am13e230x.c:75
static int am13_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: am13e230x.c:318
static int am13_request_gsc_semaphore(struct flash_bank *bank)
Definition: am13e230x.c:147
const struct flash_driver am13_flash
Definition: am13e230x.c:745
#define FCTL_REG_CMDWEPROTNM
Definition: am13e230x.c:57
#define FCTL_REG_CMDDATA0
Definition: am13e230x.c:54
@ ARM_MODE_THREAD
Definition: arm.h:94
#define ARMV7M_COMMON_MAGIC
Definition: armv7m.h:229
Support functions to access arbitrary bits in a byte array.
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
#define GENMASK(h, l)
Definition: bits.h:24
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:378
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
uint8_t bank
Definition: esirisc.c:135
#define ERROR_FLASH_BANK_INVALID
Definition: flash/common.h:28
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 keep_alive(void)
Definition: log.c:437
#define LOG_WARNING(expr ...)
Definition: log.h:144
#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
#define MIN(a, b)
Definition: replacements.h:22
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
#define BIT(nr)
Definition: stm32l4x.h:18
uint8_t dest[4]
Definition: am13e230x.c:113
uint8_t len[4]
Definition: am13e230x.c:114
uint8_t status[4]
Definition: am13e230x.c:116
uint8_t buf_addr[4]
Definition: am13e230x.c:117
uint8_t cmd[4]
Definition: am13e230x.c:115
unsigned int main_flash_num_banks
Definition: am13e230x.c:129
unsigned int sram_size_kb
Definition: am13e230x.c:130
unsigned int main_flash_size_kb
Definition: am13e230x.c:128
struct armv7m_algorithm armv7m_info
Definition: am13e230x.c:135
unsigned int sector_size
Definition: am13e230x.c:131
struct working_area * working_area
Definition: am13e230x.c:134
uint32_t did
Definition: am13e230x.c:126
uint32_t traceid
Definition: am13e230x.c:127
unsigned int common_magic
Definition: armv7m.h:306
enum arm_mode core_mode
Definition: armv7m.h:308
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
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:167
target_addr_t address
Definition: target.h:89
int target_halt(struct target *target)
Definition: target.c:518
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2410
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2118
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2676
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
Definition: target.c:2174
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2602
int target_wait_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm started with target_start_algorithm() to complete.
Definition: target.c:874
int target_start_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Executes a target-specific native code algorithm and leaves it running.
Definition: target.c:829
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:818
@ TARGET_HALTED
Definition: target.h:58
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:822
int64_t timeval_ms(void)
#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 TARGET_PRIxADDR
Definition: types.h:284
#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