OpenOCD
str9x.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  * Copyright (C) 2008 by Spencer Oliver *
8  * spen@spen-soft.co.uk *
9  *
10  * Copyright (C) 2008 by Oyvind Harboe *
11  * oyvind.harboe@zylin.com *
12  ***************************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include "imp.h"
19 #include <target/arm966e.h>
20 #include <target/algorithm.h>
21 
22 /* Flash registers */
23 
24 #define FLASH_BBSR 0x54000000 /* Boot Bank Size Register */
25 #define FLASH_NBBSR 0x54000004 /* Non-Boot Bank Size Register */
26 #define FLASH_BBADR 0x5400000C /* Boot Bank Base Address Register */
27 #define FLASH_NBBADR 0x54000010 /* Non-Boot Bank Base Address Register */
28 #define FLASH_CR 0x54000018 /* Control Register */
29 #define FLASH_SR 0x5400001C /* Status Register */
30 #define FLASH_BCE5ADDR 0x54000020 /* BC Fifth Entry Target Address Register */
31 
33  uint32_t *sector_bits;
34  int variant;
35  int bank1;
36 };
37 
50  STR9X_BUSY = 11
51 };
52 
53 static uint32_t bank1start = 0x00080000;
54 
56 {
57  struct str9x_flash_bank *str9x_info = bank->driver_priv;
58 
59  int i;
60  unsigned int num_sectors;
61  int b0_sectors = 0, b1_sectors = 0;
62  uint32_t offset = 0;
63 
64  /* set if we have large flash str9 */
65  str9x_info->variant = 0;
66  str9x_info->bank1 = 0;
67 
68  switch (bank->size) {
69  case (256 * 1024):
70  b0_sectors = 4;
71  break;
72  case (512 * 1024):
73  b0_sectors = 8;
74  break;
75  case (1024 * 1024):
76  bank1start = 0x00100000;
77  str9x_info->variant = 1;
78  b0_sectors = 16;
79  break;
80  case (2048 * 1024):
81  bank1start = 0x00200000;
82  str9x_info->variant = 1;
83  b0_sectors = 32;
84  break;
85  case (128 * 1024):
86  str9x_info->variant = 1;
87  str9x_info->bank1 = 1;
88  b1_sectors = 8;
89  bank1start = bank->base;
90  break;
91  case (32 * 1024):
92  str9x_info->bank1 = 1;
93  b1_sectors = 4;
94  bank1start = bank->base;
95  break;
96  default:
97  LOG_ERROR("BUG: unknown bank->size encountered");
98  return ERROR_FAIL;
99  }
100 
101  num_sectors = b0_sectors + b1_sectors;
102 
103  bank->num_sectors = num_sectors;
104  bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
105  str9x_info->sector_bits = malloc(sizeof(uint32_t) * num_sectors);
106 
107  num_sectors = 0;
108 
109  for (i = 0; i < b0_sectors; i++) {
110  bank->sectors[num_sectors].offset = offset;
111  bank->sectors[num_sectors].size = 0x10000;
112  offset += bank->sectors[i].size;
113  bank->sectors[num_sectors].is_erased = -1;
114  bank->sectors[num_sectors].is_protected = 1;
115  str9x_info->sector_bits[num_sectors++] = (1 << i);
116  }
117 
118  for (i = 0; i < b1_sectors; i++) {
119  bank->sectors[num_sectors].offset = offset;
120  bank->sectors[num_sectors].size = str9x_info->variant == 0 ? 0x2000 : 0x4000;
121  offset += bank->sectors[i].size;
122  bank->sectors[num_sectors].is_erased = -1;
123  bank->sectors[num_sectors].is_protected = 1;
124  if (str9x_info->variant)
125  str9x_info->sector_bits[num_sectors++] = (1 << i);
126  else
127  str9x_info->sector_bits[num_sectors++] = (1 << (i + 8));
128  }
129 
130  return ERROR_OK;
131 }
132 
133 /* flash bank str9x <base> <size> 0 0 <target#>
134  */
135 FLASH_BANK_COMMAND_HANDLER(str9x_flash_bank_command)
136 {
137  struct str9x_flash_bank *str9x_info;
138 
139  if (CMD_ARGC < 6)
141 
142  str9x_info = malloc(sizeof(struct str9x_flash_bank));
143  bank->driver_priv = str9x_info;
144 
145  int retval = str9x_build_block_list(bank);
146  if (retval != ERROR_OK) {
147  free(bank->driver_priv);
148  bank->driver_priv = NULL;
149  }
150  return retval;
151 }
152 
154 {
155  int retval;
156  struct str9x_flash_bank *str9x_info = bank->driver_priv;
157  struct target *target = bank->target;
158 
159  uint32_t adr;
160  uint32_t status = 0;
161  uint16_t hstatus = 0;
162 
163  if (bank->target->state != TARGET_HALTED) {
164  LOG_ERROR("Target not halted");
166  }
167 
168  /* read level one protection */
169 
170  if (str9x_info->variant) {
171  if (str9x_info->bank1) {
172  adr = bank1start + 0x18;
173  retval = target_write_u16(target, adr, 0x90);
174  if (retval != ERROR_OK)
175  return retval;
176  retval = target_read_u16(target, adr, &hstatus);
177  if (retval != ERROR_OK)
178  return retval;
179  status = hstatus;
180  } else {
181  adr = bank1start + 0x14;
182  retval = target_write_u16(target, adr, 0x90);
183  if (retval != ERROR_OK)
184  return retval;
185  retval = target_read_u32(target, adr, &status);
186  if (retval != ERROR_OK)
187  return retval;
188  }
189  } else {
190  adr = bank1start + 0x10;
191  retval = target_write_u16(target, adr, 0x90);
192  if (retval != ERROR_OK)
193  return retval;
194  retval = target_read_u16(target, adr, &hstatus);
195  if (retval != ERROR_OK)
196  return retval;
197  status = hstatus;
198  }
199 
200  /* read array command */
201  retval = target_write_u16(target, adr, 0xFF);
202  if (retval != ERROR_OK)
203  return retval;
204 
205  for (unsigned int i = 0; i < bank->num_sectors; i++) {
206  if (status & str9x_info->sector_bits[i])
207  bank->sectors[i].is_protected = 1;
208  else
209  bank->sectors[i].is_protected = 0;
210  }
211 
212  return ERROR_OK;
213 }
214 
215 static int str9x_erase(struct flash_bank *bank, unsigned int first,
216  unsigned int last)
217 {
218  struct target *target = bank->target;
219  uint32_t adr;
220  uint8_t status;
221  uint8_t erase_cmd;
222  int total_timeout;
223 
224  if (bank->target->state != TARGET_HALTED) {
225  LOG_ERROR("Target not halted");
227  }
228 
229  /* Check if we can erase whole bank */
230  if ((first == 0) && (last == (bank->num_sectors - 1))) {
231  /* Optimize to run erase bank command instead of sector */
232  erase_cmd = 0x80;
233  /* Add timeout duration since erase bank takes more time */
234  total_timeout = 1000 * bank->num_sectors;
235  } else {
236  /* Erase sector command */
237  erase_cmd = 0x20;
238  total_timeout = 1000;
239  }
240 
241  /* this is so the compiler can *know* */
242  assert(total_timeout > 0);
243 
244  for (unsigned int i = first; i <= last; i++) {
245  int retval;
246  adr = bank->base + bank->sectors[i].offset;
247 
248  /* erase sectors or block */
249  retval = target_write_u16(target, adr, erase_cmd);
250  if (retval != ERROR_OK)
251  return retval;
252  retval = target_write_u16(target, adr, 0xD0);
253  if (retval != ERROR_OK)
254  return retval;
255 
256  /* get status */
257  retval = target_write_u16(target, adr, 0x70);
258  if (retval != ERROR_OK)
259  return retval;
260 
261  int timeout;
262  for (timeout = 0; timeout < total_timeout; timeout++) {
263  retval = target_read_u8(target, adr, &status);
264  if (retval != ERROR_OK)
265  return retval;
266  if (status & 0x80)
267  break;
268  alive_sleep(1);
269  }
270  if (timeout == total_timeout) {
271  LOG_ERROR("erase timed out");
272  return ERROR_FAIL;
273  }
274 
275  /* clear status, also clear read array */
276  retval = target_write_u16(target, adr, 0x50);
277  if (retval != ERROR_OK)
278  return retval;
279 
280  /* read array command */
281  retval = target_write_u16(target, adr, 0xFF);
282  if (retval != ERROR_OK)
283  return retval;
284 
285  if (status & 0x22) {
286  LOG_ERROR("error erasing flash bank, status: 0x%x", status);
288  }
289 
290  /* If we ran erase bank command, we are finished */
291  if (erase_cmd == 0x80)
292  break;
293  }
294 
295  return ERROR_OK;
296 }
297 
298 static int str9x_protect(struct flash_bank *bank, int set, unsigned int first,
299  unsigned int last)
300 {
301  struct target *target = bank->target;
302  uint32_t adr;
303  uint8_t status;
304 
305  if (bank->target->state != TARGET_HALTED) {
306  LOG_ERROR("Target not halted");
308  }
309 
310  for (unsigned int i = first; i <= last; i++) {
311  /* Level One Protection */
312 
313  adr = bank->base + bank->sectors[i].offset;
314 
315  target_write_u16(target, adr, 0x60);
316  if (set)
317  target_write_u16(target, adr, 0x01);
318  else
319  target_write_u16(target, adr, 0xD0);
320 
321  /* query status */
322  target_read_u8(target, adr, &status);
323 
324  /* clear status, also clear read array */
325  target_write_u16(target, adr, 0x50);
326 
327  /* read array command */
328  target_write_u16(target, adr, 0xFF);
329  }
330 
331  return ERROR_OK;
332 }
333 
334 static int str9x_write_block(struct flash_bank *bank,
335  const uint8_t *buffer, uint32_t offset, uint32_t count)
336 {
337  struct target *target = bank->target;
338  uint32_t buffer_size = 32768;
339  struct working_area *write_algorithm;
340  struct working_area *source;
341  uint32_t address = bank->base + offset;
342  struct reg_param reg_params[4];
343  struct arm_algorithm arm_algo;
344  int retval = ERROR_OK;
345 
346  /* see contrib/loaders/flash/str9x.s for src */
347 
348  static const uint32_t str9x_flash_write_code[] = {
349  /* write: */
350  0xe3c14003, /* bic r4, r1, #3 */
351  0xe3a03040, /* mov r3, #0x40 */
352  0xe1c430b0, /* strh r3, [r4, #0] */
353  0xe0d030b2, /* ldrh r3, [r0], #2 */
354  0xe0c130b2, /* strh r3, [r1], #2 */
355  0xe3a03070, /* mov r3, #0x70 */
356  0xe1c430b0, /* strh r3, [r4, #0] */
357  /* busy: */
358  0xe5d43000, /* ldrb r3, [r4, #0] */
359  0xe3130080, /* tst r3, #0x80 */
360  0x0afffffc, /* beq busy */
361  0xe3a05050, /* mov r5, #0x50 */
362  0xe1c450b0, /* strh r5, [r4, #0] */
363  0xe3a050ff, /* mov r5, #0xFF */
364  0xe1c450b0, /* strh r5, [r4, #0] */
365  0xe3130012, /* tst r3, #0x12 */
366  0x1a000001, /* bne exit */
367  0xe2522001, /* subs r2, r2, #1 */
368  0x1affffed, /* bne write */
369  /* exit: */
370  0xe1200070, /* bkpt #0 */
371  };
372 
373  /* flash write code */
374  if (target_alloc_working_area(target, sizeof(str9x_flash_write_code),
375  &write_algorithm) != ERROR_OK) {
376  LOG_WARNING("no working area available, can't do block memory writes");
378  }
379 
380  uint8_t code[sizeof(str9x_flash_write_code)];
381  target_buffer_set_u32_array(target, code, ARRAY_SIZE(str9x_flash_write_code),
382  str9x_flash_write_code);
383  target_write_buffer(target, write_algorithm->address, sizeof(code), code);
384 
385  /* memory buffer */
387  buffer_size /= 2;
388  if (buffer_size <= 256) {
389  /* we already allocated the writing code, but failed to get a
390  * buffer, free the algorithm */
391  target_free_working_area(target, write_algorithm);
392 
393  LOG_WARNING("no large enough working area available, can't do block memory writes");
395  }
396  }
397 
398  arm_algo.common_magic = ARM_COMMON_MAGIC;
399  arm_algo.core_mode = ARM_MODE_SVC;
400  arm_algo.core_state = ARM_STATE_ARM;
401 
402  init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
403  init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
404  init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT);
405  init_reg_param(&reg_params[3], "r3", 32, PARAM_IN);
406 
407  while (count > 0) {
408  uint32_t thisrun_count = (count > (buffer_size / 2)) ? (buffer_size / 2) : count;
409 
410  target_write_buffer(target, source->address, thisrun_count * 2, buffer);
411 
412  buf_set_u32(reg_params[0].value, 0, 32, source->address);
413  buf_set_u32(reg_params[1].value, 0, 32, address);
414  buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
415 
416  retval = target_run_algorithm(target, 0, NULL, 4, reg_params,
417  write_algorithm->address,
418  0, 10000, &arm_algo);
419  if (retval != ERROR_OK) {
420  LOG_ERROR("error executing str9x flash write algorithm");
422  break;
423  }
424 
425  if (buf_get_u32(reg_params[3].value, 0, 32) != 0x80) {
427  break;
428  }
429 
430  buffer += thisrun_count * 2;
431  address += thisrun_count * 2;
432  count -= thisrun_count;
433  }
434 
436  target_free_working_area(target, write_algorithm);
437 
438  destroy_reg_param(&reg_params[0]);
439  destroy_reg_param(&reg_params[1]);
440  destroy_reg_param(&reg_params[2]);
441  destroy_reg_param(&reg_params[3]);
442 
443  return retval;
444 }
445 
446 static int str9x_write(struct flash_bank *bank,
447  const uint8_t *buffer, uint32_t offset, uint32_t count)
448 {
449  struct target *target = bank->target;
450  uint32_t words_remaining = (count / 2);
451  uint32_t bytes_remaining = (count & 0x00000001);
452  uint32_t address = bank->base + offset;
453  uint32_t bytes_written = 0;
454  uint8_t status;
455  int retval;
456  uint32_t check_address = offset;
457  uint32_t bank_adr;
458 
459  if (bank->target->state != TARGET_HALTED) {
460  LOG_ERROR("Target not halted");
462  }
463 
464  if (offset & 0x1) {
465  LOG_WARNING("offset 0x%" PRIx32 " breaks required 2-byte alignment", offset);
467  }
468 
469  for (unsigned int i = 0; i < bank->num_sectors; i++) {
470  uint32_t sec_start = bank->sectors[i].offset;
471  uint32_t sec_end = sec_start + bank->sectors[i].size;
472 
473  /* check if destination falls within the current sector */
474  if ((check_address >= sec_start) && (check_address < sec_end)) {
475  /* check if destination ends in the current sector */
476  if (offset + count < sec_end)
477  check_address = offset + count;
478  else
479  check_address = sec_end;
480  }
481  }
482 
483  if (check_address != offset + count)
485 
486  /* multiple half words (2-byte) to be programmed? */
487  if (words_remaining > 0) {
488  /* try using a block write */
489  retval = str9x_write_block(bank, buffer, offset, words_remaining);
490  if (retval != ERROR_OK) {
491  if (retval == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
492  /* if block write failed (no sufficient working area),
493  * we use normal (slow) single dword accesses */
494  LOG_WARNING("couldn't use block writes, falling back to single memory accesses");
495  } else if (retval == ERROR_FLASH_OPERATION_FAILED) {
496  LOG_ERROR("flash writing failed");
498  }
499  } else {
500  buffer += words_remaining * 2;
501  address += words_remaining * 2;
502  words_remaining = 0;
503  }
504  }
505 
506  while (words_remaining > 0) {
507  bank_adr = address & ~0x03;
508 
509  /* write data command */
510  target_write_u16(target, bank_adr, 0x40);
511  target_write_memory(target, address, 2, 1, buffer + bytes_written);
512 
513  /* get status command */
514  target_write_u16(target, bank_adr, 0x70);
515 
516  int timeout;
517  for (timeout = 0; timeout < 1000; timeout++) {
518  target_read_u8(target, bank_adr, &status);
519  if (status & 0x80)
520  break;
521  alive_sleep(1);
522  }
523  if (timeout == 1000) {
524  LOG_ERROR("write timed out");
525  return ERROR_FAIL;
526  }
527 
528  /* clear status reg and read array */
529  target_write_u16(target, bank_adr, 0x50);
530  target_write_u16(target, bank_adr, 0xFF);
531 
532  if (status & 0x10)
534  else if (status & 0x02)
536 
537  bytes_written += 2;
538  words_remaining--;
539  address += 2;
540  }
541 
542  if (bytes_remaining) {
543  uint8_t last_halfword[2] = {0xff, 0xff};
544 
545  /* copy the last remaining bytes into the write buffer */
546  memcpy(last_halfword, buffer+bytes_written, bytes_remaining);
547 
548  bank_adr = address & ~0x03;
549 
550  /* write data command */
551  target_write_u16(target, bank_adr, 0x40);
552  target_write_memory(target, address, 2, 1, last_halfword);
553 
554  /* query status command */
555  target_write_u16(target, bank_adr, 0x70);
556 
557  int timeout;
558  for (timeout = 0; timeout < 1000; timeout++) {
559  target_read_u8(target, bank_adr, &status);
560  if (status & 0x80)
561  break;
562  alive_sleep(1);
563  }
564  if (timeout == 1000) {
565  LOG_ERROR("write timed out");
566  return ERROR_FAIL;
567  }
568 
569  /* clear status reg and read array */
570  target_write_u16(target, bank_adr, 0x50);
571  target_write_u16(target, bank_adr, 0xFF);
572 
573  if (status & 0x10)
575  else if (status & 0x02)
577  }
578 
579  return ERROR_OK;
580 }
581 
582 static int str9x_probe(struct flash_bank *bank)
583 {
584  return ERROR_OK;
585 }
586 
587 #if 0
588 COMMAND_HANDLER(str9x_handle_part_id_command)
589 {
590  return ERROR_OK;
591 }
592 #endif
593 
594 COMMAND_HANDLER(str9x_handle_flash_config_command)
595 {
596  struct target *target = NULL;
597 
598  if (CMD_ARGC < 5)
600 
601  struct flash_bank *bank;
602  int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
603  if (retval != ERROR_OK)
604  return retval;
605 
606  uint32_t bbsr, nbbsr, bbadr, nbbadr;
607  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], bbsr);
608  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], nbbsr);
609  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], bbadr);
610  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[4], nbbadr);
611 
612  target = bank->target;
613 
614  if (bank->target->state != TARGET_HALTED) {
615  LOG_ERROR("Target not halted");
617  }
618 
619  /* config flash controller */
622  target_write_u32(target, FLASH_BBADR, bbadr >> 2);
623  target_write_u32(target, FLASH_NBBADR, nbbadr >> 2);
624 
625  /* set bit 18 instruction TCM order as per flash programming manual */
626  arm966e_write_cp15(target, 62, 0x40000);
627 
628  /* enable flash bank 1 */
630  return ERROR_OK;
631 }
632 
633 static const struct command_registration str9x_config_command_handlers[] = {
634  {
635  .name = "flash_config",
636  .handler = str9x_handle_flash_config_command,
637  .mode = COMMAND_EXEC,
638  .help = "Configure str9x flash controller, prior to "
639  "programming the flash.",
640  .usage = "bank_id BBSR NBBSR BBADR NBBADR",
641  },
643 };
644 
645 static const struct command_registration str9x_command_handlers[] = {
646  {
647  .name = "str9x",
648  .mode = COMMAND_ANY,
649  .help = "str9x flash command group",
650  .usage = "",
652  },
654 };
655 
656 const struct flash_driver str9x_flash = {
657  .name = "str9x",
658  .commands = str9x_command_handlers,
659  .flash_bank_command = str9x_flash_bank_command,
660  .erase = str9x_erase,
661  .protect = str9x_protect,
662  .write = str9x_write,
663  .read = default_flash_read,
664  .probe = str9x_probe,
665  .auto_probe = str9x_probe,
666  .erase_check = default_flash_blank_check,
667  .protect_check = str9x_protect_check,
668  .free_driver_priv = default_flash_free_driver_priv,
669 };
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
Definition: algorithm.c:29
void destroy_reg_param(struct reg_param *param)
Definition: algorithm.c:38
@ PARAM_OUT
Definition: algorithm.h:16
@ PARAM_IN
Definition: algorithm.h:15
int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
Definition: arm966e.c:126
#define ARM_COMMON_MAGIC
Definition: arm.h:167
@ ARM_MODE_SVC
Definition: arm.h:86
@ ARM_STATE_ARM
Definition: arm.h:152
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
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
Definition: command.h:123
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#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:445
#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
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t buffer_size
Size of dw_spi_program::buffer.
Definition: dw-spi-helper.h:5
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
uint8_t bank
Definition: esirisc.c:135
#define ERROR_FLASH_OPERATION_FAILED
Definition: flash/common.h:30
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
Definition: flash/common.h:32
#define ERROR_FLASH_DST_OUT_OF_BANK
Definition: flash/common.h:31
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:478
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define ERROR_OK
Definition: log.h:182
struct rtt_source source
Definition: rtt/rtt.c:23
static const struct command_registration str9x_command_handlers[]
Definition: str9x.c:645
#define FLASH_NBBSR
Definition: str9x.c:25
const struct flash_driver str9x_flash
Definition: str9x.c:656
FLASH_BANK_COMMAND_HANDLER(str9x_flash_bank_command)
Definition: str9x.c:135
static int str9x_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: str9x.c:334
str9x_status_codes
Definition: str9x.c:38
@ STR9X_BUSY
Definition: str9x.c:50
@ STR9X_DST_ADDR_NOT_MAPPED
Definition: str9x.c:44
@ STR9X_SECTOR_NOT_PREPARED
Definition: str9x.c:48
@ STR9X_DST_ADDR_ERROR
Definition: str9x.c:42
@ STR9X_CMD_SUCCESS
Definition: str9x.c:39
@ STR9X_SRC_ADDR_ERROR
Definition: str9x.c:41
@ STR9X_SECTOR_NOT_BLANK
Definition: str9x.c:47
@ STR9X_INVALID_SECTOR
Definition: str9x.c:46
@ STR9X_INVALID_COMMAND
Definition: str9x.c:40
@ STR9X_COUNT_ERROR
Definition: str9x.c:45
@ STR9X_SRC_ADDR_NOT_MAPPED
Definition: str9x.c:43
@ STR9X_COMPARE_ERROR
Definition: str9x.c:49
#define FLASH_BBADR
Definition: str9x.c:26
static const struct command_registration str9x_config_command_handlers[]
Definition: str9x.c:633
static int str9x_probe(struct flash_bank *bank)
Definition: str9x.c:582
#define FLASH_BBSR
Definition: str9x.c:24
#define FLASH_CR
Definition: str9x.c:28
static int str9x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: str9x.c:215
static int str9x_build_block_list(struct flash_bank *bank)
Definition: str9x.c:55
static int str9x_protect_check(struct flash_bank *bank)
Definition: str9x.c:153
static int str9x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: str9x.c:446
static int str9x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: str9x.c:298
#define FLASH_NBBADR
Definition: str9x.c:27
COMMAND_HANDLER(str9x_handle_flash_config_command)
Definition: str9x.c:594
static uint32_t bank1start
Definition: str9x.c:53
unsigned int common_magic
Definition: arm.h:275
enum arm_mode core_mode
Definition: arm.h:277
enum arm_state core_state
Definition: arm.h:278
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
Describes the geometry and status of a single flash sector within a flash bank.
Definition: nor/core.h:28
uint32_t * sector_bits
Definition: str9x.c:33
Definition: target.h:119
Definition: psoc6.c:83
target_addr_t address
Definition: target.h:89
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2410
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2693
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
Definition: target.c:2642
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:787
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:1289
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_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2018
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
Definition: target.c:2622
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2602
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
Definition: target.c:428
#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
#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 offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22