OpenOCD
str7x.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) 2010 Øyvind 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/arm.h>
20 #include <helper/binarybuffer.h>
21 #include <target/algorithm.h>
22 
23 /* Flash registers */
24 
25 #define FLASH_CR0 0x00000000
26 #define FLASH_CR1 0x00000004
27 #define FLASH_DR0 0x00000008
28 #define FLASH_DR1 0x0000000C
29 #define FLASH_AR 0x00000010
30 #define FLASH_ER 0x00000014
31 #define FLASH_NVWPAR 0x0000DFB0
32 #define FLASH_NVAPR0 0x0000DFB8
33 #define FLASH_NVAPR1 0x0000DFBC
34 
35 /* FLASH_CR0 register bits */
36 
37 #define FLASH_WMS 0x80000000
38 #define FLASH_SUSP 0x40000000
39 #define FLASH_WPG 0x20000000
40 #define FLASH_DWPG 0x10000000
41 #define FLASH_SER 0x08000000
42 #define FLASH_SPR 0x01000000
43 #define FLASH_BER 0x04000000
44 #define FLASH_MER 0x02000000
45 #define FLASH_LOCK 0x00000010
46 #define FLASH_BSYA1 0x00000004
47 #define FLASH_BSYA0 0x00000002
48 
49 /* FLASH_CR1 register bits */
50 
51 #define FLASH_B1S 0x02000000
52 #define FLASH_B0S 0x01000000
53 #define FLASH_B1F1 0x00020000
54 #define FLASH_B1F0 0x00010000
55 #define FLASH_B0F7 0x00000080
56 #define FLASH_B0F6 0x00000040
57 #define FLASH_B0F5 0x00000020
58 #define FLASH_B0F4 0x00000010
59 #define FLASH_B0F3 0x00000008
60 #define FLASH_B0F2 0x00000004
61 #define FLASH_B0F1 0x00000002
62 #define FLASH_B0F0 0x00000001
63 
64 /* FLASH_ER register bits */
65 
66 #define FLASH_WPF 0x00000100
67 #define FLASH_RESER 0x00000080
68 #define FLASH_SEQER 0x00000040
69 #define FLASH_10ER 0x00000008
70 #define FLASH_PGER 0x00000004
71 #define FLASH_ERER 0x00000002
72 #define FLASH_ERR 0x00000001
73 
74 
76  uint32_t *sector_bits;
77  uint32_t disable_bit;
78  uint32_t busy_bits;
79  uint32_t register_base;
80 };
81 
83  uint32_t sector_start;
84  uint32_t sector_size;
85  uint32_t sector_bit;
86 };
87 
100  STR7X_BUSY = 11
101 };
102 
103 static const struct str7x_mem_layout mem_layout_str7bank0[] = {
104  {0x00000000, 0x02000, 0x01},
105  {0x00002000, 0x02000, 0x02},
106  {0x00004000, 0x02000, 0x04},
107  {0x00006000, 0x02000, 0x08},
108  {0x00008000, 0x08000, 0x10},
109  {0x00010000, 0x10000, 0x20},
110  {0x00020000, 0x10000, 0x40},
111  {0x00030000, 0x10000, 0x80}
112 };
113 
114 static const struct str7x_mem_layout mem_layout_str7bank1[] = {
115  {0x00000000, 0x02000, 0x10000},
116  {0x00002000, 0x02000, 0x20000}
117 };
118 
119 static int str7x_get_flash_adr(struct flash_bank *bank, uint32_t reg)
120 {
121  struct str7x_flash_bank *str7x_info = bank->driver_priv;
122  return str7x_info->register_base | reg;
123 }
124 
126 {
127  struct str7x_flash_bank *str7x_info = bank->driver_priv;
128 
129  int i;
130  unsigned int num_sectors;
131  int b0_sectors = 0, b1_sectors = 0;
132 
133  switch (bank->size) {
134  case 16 * 1024:
135  b1_sectors = 2;
136  break;
137  case 64 * 1024:
138  b0_sectors = 5;
139  break;
140  case 128 * 1024:
141  b0_sectors = 6;
142  break;
143  case 256 * 1024:
144  b0_sectors = 8;
145  break;
146  default:
147  LOG_ERROR("BUG: unknown bank->size encountered");
148  return ERROR_FAIL;
149  }
150 
151  num_sectors = b0_sectors + b1_sectors;
152 
153  bank->num_sectors = num_sectors;
154  bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
155  str7x_info->sector_bits = malloc(sizeof(uint32_t) * num_sectors);
156 
157  num_sectors = 0;
158 
159  for (i = 0; i < b0_sectors; i++) {
160  bank->sectors[num_sectors].offset = mem_layout_str7bank0[i].sector_start;
161  bank->sectors[num_sectors].size = mem_layout_str7bank0[i].sector_size;
162  bank->sectors[num_sectors].is_erased = -1;
163  /* the reset_init handler marks all the sectors unprotected,
164  * matching hardware after reset; keep the driver in sync
165  */
166  bank->sectors[num_sectors].is_protected = 0;
167  str7x_info->sector_bits[num_sectors++] = mem_layout_str7bank0[i].sector_bit;
168  }
169 
170  for (i = 0; i < b1_sectors; i++) {
171  bank->sectors[num_sectors].offset = mem_layout_str7bank1[i].sector_start;
172  bank->sectors[num_sectors].size = mem_layout_str7bank1[i].sector_size;
173  bank->sectors[num_sectors].is_erased = -1;
174  /* the reset_init handler marks all the sectors unprotected,
175  * matching hardware after reset; keep the driver in sync
176  */
177  bank->sectors[num_sectors].is_protected = 0;
178  str7x_info->sector_bits[num_sectors++] = mem_layout_str7bank1[i].sector_bit;
179  }
180 
181  return ERROR_OK;
182 }
183 
184 /* flash bank str7x <base> <size> 0 0 <target#> <str71_variant>
185  */
186 FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command)
187 {
188  struct str7x_flash_bank *str7x_info;
189 
190  if (CMD_ARGC < 7)
192 
193  str7x_info = malloc(sizeof(struct str7x_flash_bank));
194  bank->driver_priv = str7x_info;
195 
196  /* set default bits for str71x flash */
197  str7x_info->busy_bits = (FLASH_LOCK | FLASH_BSYA1 | FLASH_BSYA0);
198  str7x_info->disable_bit = (1 << 1);
199 
200  int retval = ERROR_OK;
201  if (strcmp(CMD_ARGV[6], "STR71x") == 0) {
202  str7x_info->register_base = 0x40100000;
203  } else if (strcmp(CMD_ARGV[6], "STR73x") == 0) {
204  str7x_info->register_base = 0x80100000;
205  str7x_info->busy_bits = (FLASH_LOCK | FLASH_BSYA0);
206  } else if (strcmp(CMD_ARGV[6], "STR75x") == 0) {
207  str7x_info->register_base = 0x20100000;
208  str7x_info->disable_bit = (1 << 0);
209  } else {
210  LOG_ERROR("unknown STR7x variant: '%s'", CMD_ARGV[6]);
211  retval = ERROR_FLASH_BANK_INVALID;
212  }
213 
214  if (retval == ERROR_OK)
215  retval = str7x_build_block_list(bank);
216 
217  if (retval != ERROR_OK) {
218  free(bank->driver_priv);
219  bank->driver_priv = NULL;
220  }
221  return retval;
222 }
223 
224 /* wait for flash to become idle or report errors.
225 
226  FIX!!! what's the maximum timeout??? The documentation doesn't
227  state any maximum time.... by inspection it seems > 1000ms is to be
228  expected.
229 
230  10000ms is long enough that it should cover anything, yet not
231  quite be equivalent to an infinite loop.
232 
233  */
234 static int str7x_waitbusy(struct flash_bank *bank)
235 {
236  int err;
237  int i;
238  struct target *target = bank->target;
239  struct str7x_flash_bank *str7x_info = bank->driver_priv;
240 
241  for (i = 0 ; i < 10000; i++) {
242  uint32_t retval;
244  if (err != ERROR_OK)
245  return err;
246 
247  if ((retval & str7x_info->busy_bits) == 0)
248  return ERROR_OK;
249 
250  alive_sleep(1);
251  }
252  LOG_ERROR("Timed out waiting for str7x flash");
253  return ERROR_FAIL;
254 }
255 
256 
257 static int str7x_result(struct flash_bank *bank)
258 {
259  struct target *target = bank->target;
260  uint32_t flash_flags;
261 
262  int retval;
263  retval = target_read_u32(target, str7x_get_flash_adr(bank, FLASH_ER), &flash_flags);
264  if (retval != ERROR_OK)
265  return retval;
266 
267  if (flash_flags & FLASH_WPF) {
268  LOG_ERROR("str7x hw write protection set");
269  retval = ERROR_FAIL;
270  }
271  if (flash_flags & FLASH_RESER) {
272  LOG_ERROR("str7x suspended program erase not resumed");
273  retval = ERROR_FAIL;
274  }
275  if (flash_flags & FLASH_10ER) {
276  LOG_ERROR("str7x trying to set bit to 1 when it is already 0");
277  retval = ERROR_FAIL;
278  }
279  if (flash_flags & FLASH_PGER) {
280  LOG_ERROR("str7x program error");
281  retval = ERROR_FAIL;
282  }
283  if (flash_flags & FLASH_ERER) {
284  LOG_ERROR("str7x erase error");
285  retval = ERROR_FAIL;
286  }
287  if (retval == ERROR_OK) {
288  if (flash_flags & FLASH_ERR) {
289  /* this should always be set if one of the others are set... */
290  LOG_ERROR("str7x write operation failed / bad setup");
291  retval = ERROR_FAIL;
292  }
293  }
294 
295  return retval;
296 }
297 
299 {
300  struct str7x_flash_bank *str7x_info = bank->driver_priv;
301  struct target *target = bank->target;
302 
303  uint32_t flash_flags;
304 
305  if (bank->target->state != TARGET_HALTED) {
306  LOG_ERROR("Target not halted");
308  }
309 
310  int retval;
311  retval = target_read_u32(target, str7x_get_flash_adr(bank, FLASH_NVWPAR), &flash_flags);
312  if (retval != ERROR_OK)
313  return retval;
314 
315  for (unsigned int i = 0; i < bank->num_sectors; i++) {
316  if (flash_flags & str7x_info->sector_bits[i])
317  bank->sectors[i].is_protected = 0;
318  else
319  bank->sectors[i].is_protected = 1;
320  }
321 
322  return ERROR_OK;
323 }
324 
325 static int str7x_erase(struct flash_bank *bank, unsigned int first,
326  unsigned int last)
327 {
328  struct str7x_flash_bank *str7x_info = bank->driver_priv;
329  struct target *target = bank->target;
330 
331  uint32_t cmd;
332  uint32_t sectors = 0;
333  int err;
334 
335  if (bank->target->state != TARGET_HALTED) {
336  LOG_ERROR("Target not halted");
338  }
339 
340  for (unsigned int i = first; i <= last; i++)
341  sectors |= str7x_info->sector_bits[i];
342 
343  LOG_DEBUG("sectors: 0x%" PRIx32, sectors);
344 
345  /* clear FLASH_ER register */
347  if (err != ERROR_OK)
348  return err;
349 
350  cmd = FLASH_SER;
352  if (err != ERROR_OK)
353  return err;
354 
355  cmd = sectors;
357  if (err != ERROR_OK)
358  return err;
359 
360  cmd = FLASH_SER | FLASH_WMS;
362  if (err != ERROR_OK)
363  return err;
364 
365  err = str7x_waitbusy(bank);
366  if (err != ERROR_OK)
367  return err;
368 
369  err = str7x_result(bank);
370  if (err != ERROR_OK)
371  return err;
372 
373  return ERROR_OK;
374 }
375 
376 static int str7x_protect(struct flash_bank *bank, int set, unsigned int first,
377  unsigned int last)
378 {
379  struct str7x_flash_bank *str7x_info = bank->driver_priv;
380  struct target *target = bank->target;
381  uint32_t cmd;
382  uint32_t protect_blocks;
383 
384  if (bank->target->state != TARGET_HALTED) {
385  LOG_ERROR("Target not halted");
387  }
388 
389  protect_blocks = 0xFFFFFFFF;
390 
391  if (set) {
392  for (unsigned int i = first; i <= last; i++)
393  protect_blocks &= ~(str7x_info->sector_bits[i]);
394  }
395 
396  /* clear FLASH_ER register */
397  int err;
399  if (err != ERROR_OK)
400  return err;
401 
402  cmd = FLASH_SPR;
404  if (err != ERROR_OK)
405  return err;
406 
409  if (err != ERROR_OK)
410  return err;
411 
412  cmd = protect_blocks;
414  if (err != ERROR_OK)
415  return err;
416 
417  cmd = FLASH_SPR | FLASH_WMS;
419  if (err != ERROR_OK)
420  return err;
421 
422  err = str7x_waitbusy(bank);
423  if (err != ERROR_OK)
424  return err;
425 
426  err = str7x_result(bank);
427  if (err != ERROR_OK)
428  return err;
429 
430  return ERROR_OK;
431 }
432 
433 static int str7x_write_block(struct flash_bank *bank, const uint8_t *buffer,
434  uint32_t offset, uint32_t count)
435 {
436  struct str7x_flash_bank *str7x_info = bank->driver_priv;
437  struct target *target = bank->target;
438  uint32_t buffer_size = 32768;
439  struct working_area *write_algorithm;
440  struct working_area *source;
441  uint32_t address = bank->base + offset;
442  struct reg_param reg_params[6];
443  struct arm_algorithm arm_algo;
444  int retval = ERROR_OK;
445 
446  /* see contrib/loaders/flash/str7x.s for src */
447 
448  static const uint32_t str7x_flash_write_code[] = {
449  /* write: */
450  0xe3a04201, /* mov r4, #0x10000000 */
451  0xe5824000, /* str r4, [r2, #0x0] */
452  0xe5821010, /* str r1, [r2, #0x10] */
453  0xe4904004, /* ldr r4, [r0], #4 */
454  0xe5824008, /* str r4, [r2, #0x8] */
455  0xe4904004, /* ldr r4, [r0], #4 */
456  0xe582400c, /* str r4, [r2, #0xc] */
457  0xe3a04209, /* mov r4, #0x90000000 */
458  0xe5824000, /* str r4, [r2, #0x0] */
459  /* busy: */
460  0xe5924000, /* ldr r4, [r2, #0x0] */
461  0xe1140005, /* tst r4, r5 */
462  0x1afffffc, /* bne busy */
463  0xe5924014, /* ldr r4, [r2, #0x14] */
464  0xe31400ff, /* tst r4, #0xff */
465  0x03140c01, /* tsteq r4, #0x100 */
466  0x1a000002, /* bne exit */
467  0xe2811008, /* add r1, r1, #0x8 */
468  0xe2533001, /* subs r3, r3, #1 */
469  0x1affffec, /* bne write */
470  /* exit: */
471  0xeafffffe, /* b exit */
472  };
473 
474  /* flash write code */
475  if (target_alloc_working_area_try(target, sizeof(str7x_flash_write_code),
476  &write_algorithm) != ERROR_OK) {
478  }
479 
480  uint8_t code[sizeof(str7x_flash_write_code)];
481  target_buffer_set_u32_array(target, code, ARRAY_SIZE(str7x_flash_write_code),
482  str7x_flash_write_code);
483  target_write_buffer(target, write_algorithm->address, sizeof(code), code);
484 
485  /* memory buffer */
487  buffer_size /= 2;
488  if (buffer_size <= 256) {
489  /* we already allocated the writing code, but failed to get a
490  * buffer, free the algorithm */
491  target_free_working_area(target, write_algorithm);
492 
493  LOG_WARNING("no large enough working area available, can't do block memory writes");
495  }
496  }
497 
498  arm_algo.common_magic = ARM_COMMON_MAGIC;
499  arm_algo.core_mode = ARM_MODE_SVC;
500  arm_algo.core_state = ARM_STATE_ARM;
501 
502  init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
503  init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
504  init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT);
505  init_reg_param(&reg_params[3], "r3", 32, PARAM_OUT);
506  init_reg_param(&reg_params[4], "r4", 32, PARAM_IN);
507  init_reg_param(&reg_params[5], "r5", 32, PARAM_OUT);
508 
509  while (count > 0) {
510  uint32_t thisrun_count = (count > (buffer_size / 8)) ? (buffer_size / 8) : count;
511 
512  target_write_buffer(target, source->address, thisrun_count * 8, buffer);
513 
514  buf_set_u32(reg_params[0].value, 0, 32, source->address);
515  buf_set_u32(reg_params[1].value, 0, 32, address);
516  buf_set_u32(reg_params[2].value, 0, 32, str7x_get_flash_adr(bank, FLASH_CR0));
517  buf_set_u32(reg_params[3].value, 0, 32, thisrun_count);
518  buf_set_u32(reg_params[5].value, 0, 32, str7x_info->busy_bits);
519 
520  retval = target_run_algorithm(target, 0, NULL, 6, reg_params,
521  write_algorithm->address,
522  write_algorithm->address + (sizeof(str7x_flash_write_code) - 4),
523  10000, &arm_algo);
524  if (retval != ERROR_OK)
525  break;
526 
527  if (buf_get_u32(reg_params[4].value, 0, 32) != 0x00) {
528  retval = str7x_result(bank);
529  break;
530  }
531 
532  buffer += thisrun_count * 8;
533  address += thisrun_count * 8;
534  count -= thisrun_count;
535  }
536 
538  target_free_working_area(target, write_algorithm);
539 
540  destroy_reg_param(&reg_params[0]);
541  destroy_reg_param(&reg_params[1]);
542  destroy_reg_param(&reg_params[2]);
543  destroy_reg_param(&reg_params[3]);
544  destroy_reg_param(&reg_params[4]);
545  destroy_reg_param(&reg_params[5]);
546 
547  return retval;
548 }
549 
550 static int str7x_write(struct flash_bank *bank, const uint8_t *buffer,
551  uint32_t offset, uint32_t count)
552 {
553  struct target *target = bank->target;
554  uint32_t dwords_remaining = (count / 8);
555  uint32_t bytes_remaining = (count & 0x00000007);
556  uint32_t address = bank->base + offset;
557  uint32_t bytes_written = 0;
558  uint32_t cmd;
559  int retval;
560  uint32_t check_address = offset;
561 
562  if (bank->target->state != TARGET_HALTED) {
563  LOG_ERROR("Target not halted");
565  }
566 
567  if (offset & 0x7) {
568  LOG_WARNING("offset 0x%" PRIx32 " breaks required 8-byte alignment", offset);
570  }
571 
572  for (unsigned int i = 0; i < bank->num_sectors; i++) {
573  uint32_t sec_start = bank->sectors[i].offset;
574  uint32_t sec_end = sec_start + bank->sectors[i].size;
575 
576  /* check if destination falls within the current sector */
577  if ((check_address >= sec_start) && (check_address < sec_end)) {
578  /* check if destination ends in the current sector */
579  if (offset + count < sec_end)
580  check_address = offset + count;
581  else
582  check_address = sec_end;
583  }
584  }
585 
586  if (check_address != offset + count)
588 
589  /* clear FLASH_ER register */
591 
592  /* multiple dwords (8-byte) to be programmed? */
593  if (dwords_remaining > 0) {
594  /* try using a block write */
595  retval = str7x_write_block(bank, buffer, offset, dwords_remaining);
596  if (retval != ERROR_OK) {
597  if (retval == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
598  /* if block write failed (no sufficient working area),
599  * we use normal (slow) single dword accesses */
600  LOG_WARNING("couldn't use block writes, falling back to single memory accesses");
601  } else {
602  return retval;
603  }
604  } else {
605  buffer += dwords_remaining * 8;
606  address += dwords_remaining * 8;
607  dwords_remaining = 0;
608  }
609  }
610 
611  while (dwords_remaining > 0) {
612  /* command */
613  cmd = FLASH_DWPG;
615 
616  /* address */
618 
619  /* data word 1 */
621  4, 1, buffer + bytes_written);
622  bytes_written += 4;
623 
624  /* data word 2 */
626  4, 1, buffer + bytes_written);
627  bytes_written += 4;
628 
629  /* start programming cycle */
632 
633  int err;
634  err = str7x_waitbusy(bank);
635  if (err != ERROR_OK)
636  return err;
637 
638  err = str7x_result(bank);
639  if (err != ERROR_OK)
640  return err;
641 
642  dwords_remaining--;
643  address += 8;
644  }
645 
646  if (bytes_remaining) {
647  uint8_t last_dword[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
648 
649  /* copy the last remaining bytes into the write buffer */
650  memcpy(last_dword, buffer+bytes_written, bytes_remaining);
651 
652  /* command */
653  cmd = FLASH_DWPG;
655 
656  /* address */
658 
659  /* data word 1 */
661  4, 1, last_dword);
662 
663  /* data word 2 */
665  4, 1, last_dword + 4);
666 
667  /* start programming cycle */
670 
671  int err;
672  err = str7x_waitbusy(bank);
673  if (err != ERROR_OK)
674  return err;
675 
676  err = str7x_result(bank);
677  if (err != ERROR_OK)
678  return err;
679  }
680 
681  return ERROR_OK;
682 }
683 
684 static int str7x_probe(struct flash_bank *bank)
685 {
686  return ERROR_OK;
687 }
688 
689 #if 0
690 COMMAND_HANDLER(str7x_handle_part_id_command)
691 {
692  return ERROR_OK;
693 }
694 #endif
695 
697 {
698  /* Setting the write protection on a sector is a permanent change but it
699  * can be disabled temporarily. FLASH_NVWPAR reflects the permanent
700  * protection state of the sectors, not the temporary.
701  */
702  command_print_sameline(cmd, "STR7x flash protection info is only valid after a power cycle, "
703  "clearing the protection is only temporary and may not be reflected in the current "
704  "info returned.");
705  return ERROR_OK;
706 }
707 
708 COMMAND_HANDLER(str7x_handle_disable_jtag_command)
709 {
710  struct target *target = NULL;
711  struct str7x_flash_bank *str7x_info = NULL;
712 
713  uint32_t flash_cmd;
714  uint16_t protection_level = 0;
715  uint16_t protection_regs;
716 
717  if (CMD_ARGC < 1)
719 
720  struct flash_bank *bank;
721  int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
722  if (retval != ERROR_OK)
723  return retval;
724 
725  str7x_info = bank->driver_priv;
726 
727  target = bank->target;
728 
729  if (target->state != TARGET_HALTED) {
730  LOG_ERROR("Target not halted");
732  }
733 
734  /* first we get protection status */
735  uint32_t reg;
737 
738  if (!(reg & str7x_info->disable_bit))
739  protection_level = 1;
740 
742  protection_regs = ~(reg >> 16);
743 
744  while ((protection_regs != 0) && (protection_level < 16)) {
745  protection_regs >>= 1;
746  protection_level++;
747  }
748 
749  if (protection_level == 0) {
750  flash_cmd = FLASH_SPR;
754  flash_cmd = FLASH_SPR | FLASH_WMS;
756  } else {
757  flash_cmd = FLASH_SPR;
761  ~(1U << (15 + protection_level)));
762  flash_cmd = FLASH_SPR | FLASH_WMS;
764  }
765 
766  return ERROR_OK;
767 }
768 
769 static const struct command_registration str7x_exec_command_handlers[] = {
770  {
771  .name = "disable_jtag",
772  .usage = "<bank>",
773  .handler = str7x_handle_disable_jtag_command,
774  .mode = COMMAND_EXEC,
775  .help = "disable jtag access",
776  },
778 };
779 
780 static const struct command_registration str7x_command_handlers[] = {
781  {
782  .name = "str7x",
783  .mode = COMMAND_ANY,
784  .help = "str7x flash command group",
785  .usage = "",
787  },
789 };
790 
791 const struct flash_driver str7x_flash = {
792  .name = "str7x",
793  .commands = str7x_command_handlers,
794  .flash_bank_command = str7x_flash_bank_command,
795  .erase = str7x_erase,
796  .protect = str7x_protect,
797  .write = str7x_write,
798  .read = default_flash_read,
799  .probe = str7x_probe,
800  .auto_probe = str7x_probe,
801  .erase_check = default_flash_blank_check,
802  .protect_check = str7x_protect_check,
803  .info = get_str7x_info,
804  .free_driver_priv = default_flash_free_driver_priv,
805 };
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
Holds the interface to ARM cores.
#define ARM_COMMON_MAGIC
Definition: arm.h:167
@ ARM_MODE_SVC
Definition: arm.h:86
@ ARM_STATE_ARM
Definition: arm.h:152
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
Definition: command.c:378
#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_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_BANK_INVALID
Definition: flash/common.h:28
#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 LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
struct rtt_source source
Definition: rtt/rtt.c:23
str7x_status_codes
Definition: str7x.c:88
@ STR7X_CMD_SUCCESS
Definition: str7x.c:89
@ STR7X_INVALID_SECTOR
Definition: str7x.c:96
@ STR7X_INVALID_COMMAND
Definition: str7x.c:90
@ STR7X_COUNT_ERROR
Definition: str7x.c:95
@ STR7X_SECTOR_NOT_PREPARED
Definition: str7x.c:98
@ STR7X_SRC_ADDR_ERROR
Definition: str7x.c:91
@ STR7X_BUSY
Definition: str7x.c:100
@ STR7X_DST_ADDR_NOT_MAPPED
Definition: str7x.c:94
@ STR7X_SECTOR_NOT_BLANK
Definition: str7x.c:97
@ STR7X_DST_ADDR_ERROR
Definition: str7x.c:92
@ STR7X_SRC_ADDR_NOT_MAPPED
Definition: str7x.c:93
@ STR7X_COMPARE_ERROR
Definition: str7x.c:99
#define FLASH_ERER
Definition: str7x.c:71
#define FLASH_NVAPR0
Definition: str7x.c:32
#define FLASH_PGER
Definition: str7x.c:70
#define FLASH_AR
Definition: str7x.c:29
#define FLASH_CR1
Definition: str7x.c:26
#define FLASH_SPR
Definition: str7x.c:42
#define FLASH_DR0
Definition: str7x.c:27
#define FLASH_DR1
Definition: str7x.c:28
static const struct command_registration str7x_exec_command_handlers[]
Definition: str7x.c:769
#define FLASH_ER
Definition: str7x.c:30
static int str7x_build_block_list(struct flash_bank *bank)
Definition: str7x.c:125
#define FLASH_NVAPR1
Definition: str7x.c:33
static int str7x_protect_check(struct flash_bank *bank)
Definition: str7x.c:298
static const struct str7x_mem_layout mem_layout_str7bank0[]
Definition: str7x.c:103
#define FLASH_RESER
Definition: str7x.c:67
static int str7x_probe(struct flash_bank *bank)
Definition: str7x.c:684
static const struct str7x_mem_layout mem_layout_str7bank1[]
Definition: str7x.c:114
static int str7x_get_flash_adr(struct flash_bank *bank, uint32_t reg)
Definition: str7x.c:119
static int str7x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: str7x.c:325
#define FLASH_SER
Definition: str7x.c:41
static int str7x_result(struct flash_bank *bank)
Definition: str7x.c:257
#define FLASH_10ER
Definition: str7x.c:69
#define FLASH_NVWPAR
Definition: str7x.c:31
static const struct command_registration str7x_command_handlers[]
Definition: str7x.c:780
#define FLASH_WPF
Definition: str7x.c:66
static int str7x_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: str7x.c:433
#define FLASH_DWPG
Definition: str7x.c:40
#define FLASH_LOCK
Definition: str7x.c:45
static int get_str7x_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: str7x.c:696
#define FLASH_BSYA0
Definition: str7x.c:47
static int str7x_waitbusy(struct flash_bank *bank)
Definition: str7x.c:234
COMMAND_HANDLER(str7x_handle_disable_jtag_command)
Definition: str7x.c:708
#define FLASH_BSYA1
Definition: str7x.c:46
#define FLASH_WMS
Definition: str7x.c:37
static int str7x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: str7x.c:376
#define FLASH_CR0
Definition: str7x.c:25
static int str7x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: str7x.c:550
const struct flash_driver str7x_flash
Definition: str7x.c:791
#define FLASH_ERR
Definition: str7x.c:72
FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command)
Definition: str7x.c:186
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
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: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
Definition: register.h:111
uint32_t busy_bits
Definition: str7x.c:78
uint32_t register_base
Definition: str7x.c:79
uint32_t * sector_bits
Definition: str7x.c:76
uint32_t disable_bit
Definition: str7x.c:77
uint32_t sector_size
Definition: str7x.c:84
uint32_t sector_bit
Definition: str7x.c:85
uint32_t sector_start
Definition: str7x.c:83
Definition: target.h:119
enum target_state state
Definition: target.h:167
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_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_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_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 cmd
Definition: vdebug.c:1
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22