1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
27 #include "time_support.h"
35 #include <sys/types.h>
40 /* command handlers */
41 int handle_flash_bank_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
42 int handle_flash_banks_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
43 int handle_flash_info_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
44 int handle_flash_probe_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
45 int handle_flash_erase_check_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
46 int handle_flash_protect_check_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
47 int handle_flash_erase_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
48 int handle_flash_write_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
49 int handle_flash_write_binary_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
50 int handle_flash_write_image_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
51 int handle_flash_protect_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
52 int handle_flash_auto_erase_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
56 extern flash_driver_t lpc2000_flash
;
57 extern flash_driver_t cfi_flash
;
58 extern flash_driver_t at91sam7_flash
;
59 extern flash_driver_t str7x_flash
;
60 extern flash_driver_t str9x_flash
;
61 extern flash_driver_t stellaris_flash
;
62 extern flash_driver_t str9xpec_flash
;
63 extern flash_driver_t stm32x_flash
;
65 flash_driver_t
*flash_drivers
[] =
78 flash_bank_t
*flash_banks
;
79 static command_t
*flash_cmd
;
80 static int auto_erase
= 0;
82 int flash_register_commands(struct command_context_s
*cmd_ctx
)
84 flash_cmd
= register_command(cmd_ctx
, NULL
, "flash", NULL
, COMMAND_ANY
, NULL
);
86 register_command(cmd_ctx
, flash_cmd
, "bank", handle_flash_bank_command
, COMMAND_CONFIG
, NULL
);
91 int flash_init(struct command_context_s
*cmd_ctx
)
95 register_command(cmd_ctx
, flash_cmd
, "banks", handle_flash_banks_command
, COMMAND_EXEC
,
96 "list configured flash banks ");
97 register_command(cmd_ctx
, flash_cmd
, "info", handle_flash_info_command
, COMMAND_EXEC
,
98 "print info about flash bank <num>");
99 register_command(cmd_ctx
, flash_cmd
, "probe", handle_flash_probe_command
, COMMAND_EXEC
,
100 "identify flash bank <num>");
101 register_command(cmd_ctx
, flash_cmd
, "erase_check", handle_flash_erase_check_command
, COMMAND_EXEC
,
102 "check erase state of sectors in flash bank <num>");
103 register_command(cmd_ctx
, flash_cmd
, "protect_check", handle_flash_protect_check_command
, COMMAND_EXEC
,
104 "check protection state of sectors in flash bank <num>");
105 register_command(cmd_ctx
, flash_cmd
, "erase", handle_flash_erase_command
, COMMAND_EXEC
,
106 "erase sectors at <bank> <first> <last>");
107 register_command(cmd_ctx
, flash_cmd
, "write", handle_flash_write_binary_command
, COMMAND_EXEC
,
108 "DEPRECATED, use 'write_binary' or 'write_image' instead");
109 register_command(cmd_ctx
, flash_cmd
, "write_binary", handle_flash_write_binary_command
, COMMAND_EXEC
,
110 "write binary <bank> <file> <offset>");
111 register_command(cmd_ctx
, flash_cmd
, "write_image", handle_flash_write_image_command
, COMMAND_EXEC
,
112 "write image <file> [offset] [type]");
113 register_command(cmd_ctx
, flash_cmd
, "protect", handle_flash_protect_command
, COMMAND_EXEC
,
114 "set protection of sectors at <bank> <first> <last> <on|off>");
115 register_command(cmd_ctx
, flash_cmd
, "auto_erase", handle_flash_auto_erase_command
, COMMAND_EXEC
,
116 "auto erase flash sectors <on|off>");
122 flash_bank_t
*get_flash_bank_by_num(int num
)
127 for (p
= flash_banks
; p
; p
= p
->next
)
138 /* flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]
140 int handle_flash_bank_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
148 WARNING("incomplete flash_bank configuration");
149 WARNING("flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
153 if ((target
= get_target_by_num(strtoul(args
[5], NULL
, 0))) == NULL
)
155 ERROR("target %lu not defined", strtoul(args
[5], NULL
, 0));
159 for (i
= 0; flash_drivers
[i
]; i
++)
161 if (strcmp(args
[0], flash_drivers
[i
]->name
) == 0)
165 /* register flash specific commands */
166 if (flash_drivers
[i
]->register_commands(cmd_ctx
) != ERROR_OK
)
168 ERROR("couldn't register '%s' commands", args
[0]);
172 c
= malloc(sizeof(flash_bank_t
));
174 c
->driver
= flash_drivers
[i
];
175 c
->driver_priv
= NULL
;
176 c
->base
= strtoul(args
[1], NULL
, 0);
177 c
->size
= strtoul(args
[2], NULL
, 0);
178 c
->chip_width
= strtoul(args
[3], NULL
, 0);
179 c
->bus_width
= strtoul(args
[4], NULL
, 0);
182 if (flash_drivers
[i
]->flash_bank_command(cmd_ctx
, cmd
, args
, argc
, c
) != ERROR_OK
)
184 ERROR("'%s' driver rejected flash bank at 0x%8.8x", args
[0], c
->base
);
189 /* put flash bank in linked list */
192 /* find last flash bank */
193 for (p
= flash_banks
; p
&& p
->next
; p
= p
->next
);
206 /* no matching flash driver found */
209 ERROR("flash driver '%s' not found", args
[0]);
216 int handle_flash_banks_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
223 command_print(cmd_ctx
, "no flash banks configured");
227 for (p
= flash_banks
; p
; p
= p
->next
)
229 command_print(cmd_ctx
, "#%i: %s at 0x%8.8x, size 0x%8.8x, buswidth %i, chipwidth %i",
230 i
++, p
->driver
->name
, p
->base
, p
->size
, p
->bus_width
, p
->chip_width
);
236 int handle_flash_info_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
244 command_print(cmd_ctx
, "usage: flash info <num>");
248 for (p
= flash_banks
; p
; p
= p
->next
, i
++)
250 if (i
== strtoul(args
[0], NULL
, 0))
254 command_print(cmd_ctx
, "#%i: %s at 0x%8.8x, size 0x%8.8x, buswidth %i, chipwidth %i",
255 i
, p
->driver
->name
, p
->base
, p
->size
, p
->bus_width
, p
->chip_width
);
256 for (j
= 0; j
< p
->num_sectors
; j
++)
258 char *erase_state
, *protect_state
;
260 if (p
->sectors
[j
].is_erased
== 0)
261 erase_state
= "not erased";
262 else if (p
->sectors
[j
].is_erased
== 1)
263 erase_state
= "erased";
265 erase_state
= "erase state unknown";
267 if (p
->sectors
[j
].is_protected
== 0)
268 protect_state
= "not protected";
269 else if (p
->sectors
[j
].is_protected
== 1)
270 protect_state
= "protected";
272 protect_state
= "protection state unknown";
274 command_print(cmd_ctx
, "\t#%i: 0x%8.8x (0x%x %ikB) %s, %s",
275 j
, p
->sectors
[j
].offset
, p
->sectors
[j
].size
, p
->sectors
[j
].size
>>10,
276 erase_state
, protect_state
);
279 p
->driver
->info(p
, buf
, 1024);
280 command_print(cmd_ctx
, "%s", buf
);
287 int handle_flash_probe_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
294 command_print(cmd_ctx
, "usage: flash probe <num>");
298 p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
301 if ((retval
= p
->driver
->probe(p
)) == ERROR_OK
)
303 command_print(cmd_ctx
, "flash '%s' found at 0x%8.8x", p
->driver
->name
, p
->base
);
305 else if (retval
== ERROR_FLASH_BANK_INVALID
)
307 command_print(cmd_ctx
, "probing failed for flash bank '#%s' at 0x%8.8x",
312 command_print(cmd_ctx
, "unknown error when probing flash bank '#%s' at 0x%8.8x",
318 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
324 int handle_flash_erase_check_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
331 command_print(cmd_ctx
, "usage: flash erase_check <num>");
335 p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
338 if ((retval
= p
->driver
->erase_check(p
)) == ERROR_OK
)
340 command_print(cmd_ctx
, "successfully checked erase state", p
->driver
->name
, p
->base
);
344 command_print(cmd_ctx
, "unknown error when checking erase state of flash bank #%s at 0x%8.8x",
350 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
356 int handle_flash_protect_check_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
363 command_print(cmd_ctx
, "usage: flash protect_check <num>");
367 p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
370 if ((retval
= p
->driver
->protect_check(p
)) == ERROR_OK
)
372 command_print(cmd_ctx
, "successfully checked protect state");
374 else if (retval
== ERROR_FLASH_OPERATION_FAILED
)
376 command_print(cmd_ctx
, "checking protection state failed (possibly unsupported) by flash #%s at 0x%8.8x", args
[0], p
->base
);
380 command_print(cmd_ctx
, "unknown error when checking protection state of flash bank '#%s' at 0x%8.8x", args
[0], p
->base
);
385 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
391 int handle_flash_erase_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
395 int first
= strtoul(args
[1], NULL
, 0);
396 int last
= strtoul(args
[2], NULL
, 0);
398 flash_bank_t
*p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
402 duration_start_measure(&duration
);
406 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
410 if ((retval
= p
->driver
->erase(p
, first
, last
)) != ERROR_OK
)
414 case ERROR_TARGET_NOT_HALTED
:
415 command_print(cmd_ctx
, "can't work with this flash while target is running");
417 case ERROR_INVALID_ARGUMENTS
:
418 command_print(cmd_ctx
, "usage: flash_erase <bank> <first> <last>");
420 case ERROR_FLASH_BANK_INVALID
:
421 command_print(cmd_ctx
, "no '%s' flash found at 0x%8.8x", p
->driver
->name
, p
->base
);
423 case ERROR_FLASH_OPERATION_FAILED
:
424 command_print(cmd_ctx
, "flash erase error");
426 case ERROR_FLASH_SECTOR_INVALID
:
427 command_print(cmd_ctx
, "sector number(s) invalid");
430 command_print(cmd_ctx
, "erased flash sectors %i to %i", first
, last
);
433 command_print(cmd_ctx
, "unknown error");
438 duration_stop_measure(&duration
, &duration_text
);
440 command_print(cmd_ctx
, "erased sectors %i through %i on flash bank %i in %s", first
, last
, strtoul(args
[0], 0, 0), duration_text
);
446 command_print(cmd_ctx
, "usage: flash erase <bank> <first> <last>");
452 int handle_flash_protect_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
456 int first
= strtoul(args
[1], NULL
, 0);
457 int last
= strtoul(args
[2], NULL
, 0);
460 flash_bank_t
*p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
463 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
467 if (strcmp(args
[3], "on") == 0)
469 else if (strcmp(args
[3], "off") == 0)
473 command_print(cmd_ctx
, "usage: flash protect <bank> <first> <last> <on|off>");
477 if ((retval
= p
->driver
->protect(p
, set
, first
, last
)) != ERROR_OK
)
481 case ERROR_TARGET_NOT_HALTED
:
482 command_print(cmd_ctx
, "can't work with this flash while target is running");
484 case ERROR_INVALID_ARGUMENTS
:
485 command_print(cmd_ctx
, "usage: flash protect <bank> <first> <last> <on|off>");
487 case ERROR_FLASH_BANK_INVALID
:
488 command_print(cmd_ctx
, "no '%s' flash found at 0x%8.8x", p
->driver
->name
, p
->base
);
490 case ERROR_FLASH_OPERATION_FAILED
:
491 command_print(cmd_ctx
, "flash program error");
493 case ERROR_FLASH_SECTOR_INVALID
:
494 command_print(cmd_ctx
, "sector number(s) invalid");
497 command_print(cmd_ctx
, "protection of flash sectors %i to %i turned %s", first
, last
, args
[3]);
500 command_print(cmd_ctx
, "unknown error");
505 command_print(cmd_ctx
, "%s protection for sectors %i through %i on flash bank %i", (set
) ? "set" : "cleared", first
, last
, strtoul(args
[0], 0, 0));
510 command_print(cmd_ctx
, "usage: flash protect <bank> <first> <last> <on|off>");
516 int handle_flash_write_image_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
518 target_t
*target
= get_current_target(cmd_ctx
);
532 if (!strcmp(cmd
, "write"))
534 command_print(cmd_ctx
, "'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
535 DEBUG("'flash write' has been deprecated in favor of 'flash write_binary' and 'flash write_image'");
540 command_print(cmd_ctx
, "usage: flash write <file> [offset] [type]");
546 ERROR("no target selected");
550 duration_start_measure(&duration
);
554 image
.base_address_set
= 1;
555 image
.base_address
= strtoul(args
[1], NULL
, 0);
559 image
.base_address_set
= 0;
560 image
.base_address
= 0x0;
563 image
.start_address_set
= 0;
565 if (image_open(&image
, args
[0], (argc
== 4) ? args
[2] : NULL
) != ERROR_OK
)
567 command_print(cmd_ctx
, "flash write error: %s", image
.error_str
);
571 failed
= malloc(sizeof(int) * image
.num_sections
);
573 if ((retval
= flash_write(target
, &image
, &written
, &error_str
, failed
, auto_erase
)) != ERROR_OK
)
575 command_print(cmd_ctx
, "failed writing image %s: %s", args
[0], error_str
);
579 for (i
= 0; i
< image
.num_sections
; i
++)
583 command_print(cmd_ctx
, "didn't write section at 0x%8.8x, size 0x%8.8x",
584 image
.sections
[i
].base_address
, image
.sections
[i
].size
);
588 duration_stop_measure(&duration
, &duration_text
);
589 command_print(cmd_ctx
, "wrote %u byte from file %s in %s (%f kb/s)",
590 written
, args
[0], duration_text
,
591 (float)written
/ 1024.0 / ((float)duration
.duration
.tv_sec
+ ((float)duration
.duration
.tv_usec
/ 1000000.0)));
601 int handle_flash_write_binary_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
617 command_print(cmd_ctx
, "usage: flash write <bank> <file> <offset>");
621 duration_start_measure(&duration
);
623 offset
= strtoul(args
[2], NULL
, 0);
624 p
= get_flash_bank_by_num(strtoul(args
[0], NULL
, 0));
627 command_print(cmd_ctx
, "flash bank '#%s' is out of bounds", args
[0]);
631 if (fileio_open(&fileio
, args
[1], FILEIO_READ
, FILEIO_BINARY
) != ERROR_OK
)
633 command_print(cmd_ctx
, "flash write error: %s", fileio
.error_str
);
637 buffer
= malloc(fileio
.size
);
638 if (fileio_read(&fileio
, fileio
.size
, buffer
, &buf_cnt
) != ERROR_OK
)
640 command_print(cmd_ctx
, "flash write error: %s", fileio
.error_str
);
644 if ((retval
= p
->driver
->write(p
, buffer
, offset
, buf_cnt
)) != ERROR_OK
)
646 command_print(cmd_ctx
, "failed writing file %s to flash bank %i at offset 0x%8.8x",
647 args
[1], strtoul(args
[0], NULL
, 0), strtoul(args
[2], NULL
, 0));
650 case ERROR_TARGET_NOT_HALTED
:
651 command_print(cmd_ctx
, "can't work with this flash while target is running");
653 case ERROR_INVALID_ARGUMENTS
:
654 command_print(cmd_ctx
, "usage: flash write <bank> <file> <offset>");
656 case ERROR_FLASH_BANK_INVALID
:
657 command_print(cmd_ctx
, "no '%s' flash found at 0x%8.8x", p
->driver
->name
, p
->base
);
659 case ERROR_FLASH_OPERATION_FAILED
:
660 command_print(cmd_ctx
, "flash program error");
662 case ERROR_FLASH_DST_BREAKS_ALIGNMENT
:
663 command_print(cmd_ctx
, "offset breaks required alignment");
665 case ERROR_FLASH_DST_OUT_OF_BANK
:
666 command_print(cmd_ctx
, "destination is out of flash bank (offset and/or file too large)");
668 case ERROR_FLASH_SECTOR_NOT_ERASED
:
669 command_print(cmd_ctx
, "destination sector(s) not erased");
672 command_print(cmd_ctx
, "unknown error");
678 duration_stop_measure(&duration
, &duration_text
);
679 command_print(cmd_ctx
, "wrote %"PRIi64
" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",
680 fileio
.size
, args
[1], strtoul(args
[0], NULL
, 0), offset
, duration_text
,
681 (float)fileio
.size
/ 1024.0 / ((float)duration
.duration
.tv_sec
+ ((float)duration
.duration
.tv_usec
/ 1000000.0)));
684 fileio_close(&fileio
);
689 /* lookup flash bank by address */
690 flash_bank_t
*get_flash_bank_by_addr(target_t
*target
, u32 addr
)
694 /* cycle through bank list */
695 for (c
= flash_banks
; c
; c
= c
->next
)
697 /* check whether address belongs to this flash bank */
698 if ((addr
>= c
->base
) && (addr
< c
->base
+ c
->size
) && target
== c
->target
)
705 /* erase given flash region, selects proper bank according to target and address */
706 int flash_erase(target_t
*target
, u32 addr
, u32 length
)
713 if ((c
= get_flash_bank_by_addr(target
, addr
)) == NULL
)
714 return ERROR_FLASH_DST_OUT_OF_BANK
; /* no corresponding bank found */
716 if (c
->size
== 0 || c
->num_sectors
== 0)
717 return ERROR_FLASH_BANK_INVALID
;
721 /* special case, erase whole bank when length is zero */
723 return ERROR_FLASH_DST_BREAKS_ALIGNMENT
;
725 return c
->driver
->erase(c
, 0, c
->num_sectors
- 1);
728 /* check whether it fits */
729 if (addr
+ length
> c
->base
+ c
->size
)
730 return ERROR_FLASH_DST_BREAKS_ALIGNMENT
;
734 for (i
= 0; i
< c
->num_sectors
; i
++)
736 /* check whether sector overlaps with the given range and is not yet erased */
737 if (addr
< c
->sectors
[i
].offset
+ c
->sectors
[i
].size
&& addr
+ length
> c
->sectors
[i
].offset
&& c
->sectors
[i
].is_erased
!= 1) {
738 /* if first is not set yet then this is the first sector */
741 last
= i
; /* and it is the last one so far in any case */
745 if( first
== -1 || last
== -1 )
748 return c
->driver
->erase(c
, first
, last
);
751 /* write an image to flash memory of the given target */
752 int flash_write(target_t
*target
, image_t
*image
, u32
*written
, char **error_str
, int *failed
, int erase
)
767 for (i
= 0; i
< image
->num_sections
; i
++)
770 /* loop until we reach end of the image */
771 while (section
< image
->num_sections
)
778 u32 run_address
= image
->sections
[section
].base_address
+section_offset
;
779 u32 run_size
= image
->sections
[section
].size
-section_offset
;
781 if (image
->sections
[section
].size
== 0)
783 WARNING("empty section %d", section
);
789 /* find the corresponding flash bank */
790 if ((c
= get_flash_bank_by_addr(target
, run_address
)) == NULL
)
794 if (error_str
== NULL
)
795 return ERROR_FLASH_DST_OUT_OF_BANK
; /* abort operation */
796 *error_str
= malloc(FLASH_MAX_ERROR_STR
);
797 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "no flash mapped at requested address");
798 return ERROR_FLASH_DST_OUT_OF_BANK
; /* abort operation */
800 failed
[section
] = ERROR_FLASH_DST_OUT_OF_BANK
; /* mark the section as failed */
801 section
++; /* and skip it */
806 /* collect consecutive sections which fall into the same bank */
807 section_first
= section
;
808 section_last
= section
;
809 while ((run_address
+ run_size
< c
->base
+ c
->size
)
810 && (section_last
+ 1 < image
->num_sections
))
812 if (image
->sections
[section_last
+ 1].base_address
< (run_address
+ run_size
))
814 WARNING("section %d out of order", section_last
+ 1);
817 if (image
->sections
[section_last
+ 1].base_address
!= (run_address
+ run_size
))
819 run_size
+= image
->sections
[++section_last
].size
;
822 /* fit the run into bank constraints */
823 if (run_address
+ run_size
> c
->base
+ c
->size
)
824 run_size
= c
->base
+ c
->size
- run_address
;
826 /* allocate buffer */
827 buffer
= malloc(run_size
);
830 /* read sections to the buffer */
831 while (buffer_size
< run_size
)
835 if (buffer_size
- run_size
<= image
->sections
[section
].size
- section_offset
)
836 size_read
= buffer_size
- run_size
;
838 size_read
= image
->sections
[section
].size
- section_offset
;
840 if ((retval
= image_read_section(image
, section
, section_offset
,
841 run_size
, buffer
+ buffer_size
, &size_read
)) != ERROR_OK
|| size_read
== 0)
845 if (error_str
== NULL
)
846 return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE
;
848 *error_str
= malloc(FLASH_MAX_ERROR_STR
);
850 /* if image_read_section returned an error there's an error string we can pass on */
851 if (retval
!= ERROR_OK
)
852 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "error reading from image: %s", image
->error_str
);
854 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "error reading from image");
856 return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE
;
859 buffer_size
+= size_read
;
860 section_offset
+= size_read
;
862 if (section_offset
>= image
->sections
[section
].size
)
873 /* calculate and erase sectors */
874 retval
= flash_erase( target
, run_address
, run_size
);
877 if (retval
== ERROR_OK
)
879 /* write flash sectors */
880 retval
= c
->driver
->write(c
, buffer
, run_address
- c
->base
, run_size
);
885 if (retval
!= ERROR_OK
)
887 if (error_str
== NULL
)
888 return retval
; /* abort operation */
890 *error_str
= malloc(FLASH_MAX_ERROR_STR
);
893 case ERROR_TARGET_NOT_HALTED
:
894 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "can't flash image while target is running");
896 case ERROR_INVALID_ARGUMENTS
:
897 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "flash driver can't fulfill request");
899 case ERROR_FLASH_OPERATION_FAILED
:
900 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "flash program error");
902 case ERROR_FLASH_DST_BREAKS_ALIGNMENT
:
903 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "offset breaks required alignment");
905 case ERROR_FLASH_DST_OUT_OF_BANK
:
906 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "no flash mapped at requested address");
908 case ERROR_FLASH_SECTOR_NOT_ERASED
:
909 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "destination sector(s) not erased");
912 snprintf(*error_str
, FLASH_MAX_ERROR_STR
, "unknown error: %i", retval
);
915 return retval
; /* abort operation */
919 *written
+= run_size
; /* add run size to total written counter */
925 int handle_flash_auto_erase_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
929 command_print(cmd_ctx
, "usage: flash auto_erase <on|off>");
933 if (strcmp(args
[0], "on") == 0)
935 else if (strcmp(args
[0], "off") == 0)
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)