@@ -19617,6 +19617,16 @@ load programs into flash memory.
@code{load} does not repeat if you press @key{RET} again after using it.
@end table
+@table @code
+
+@kindex flash-erase
+@item flash-erase
+@anchor{flash-erase}
+
+Erases all known flash memory regions on the target.
+
+@end table
+
@node Byte Order
@section Choosing Target Byte Order
@@ -31854,6 +31864,28 @@ No equivalent.
@subsubheading Example
N.A.
+@subheading The @code{-target-flash-erase} Command
+@findex -target-flash-erase
+
+@subsubheading Synopsis
+
+@smallexample
+ -target-flash-erase
+@end smallexample
+
+Erases all known flash memory regions on the target.
+
+The corresponding @value{GDBN} command is @samp{flash-erase}.
+
+The output is a list of flash regions that have been erased, sorted by
+address/size.
+
+@smallexample
+(gdb)
+-target-flash-erase
+^done,erased-regions=@{address="0x0",size="262144"@}
+(gdb)
+@end smallexample
@subheading The @code{-target-select} Command
@findex -target-select
@@ -147,6 +147,7 @@ static struct mi_cmd mi_cmds[] =
DEF_MI_CMD_MI ("target-file-delete", mi_cmd_target_file_delete),
DEF_MI_CMD_MI ("target-file-get", mi_cmd_target_file_get),
DEF_MI_CMD_MI ("target-file-put", mi_cmd_target_file_put),
+ DEF_MI_CMD_MI ("target-flash-erase", mi_cmd_target_flash_erase),
DEF_MI_CMD_CLI ("target-select", "target", 1),
DEF_MI_CMD_MI ("thread-info", mi_cmd_thread_info),
DEF_MI_CMD_MI ("thread-list-ids", mi_cmd_thread_list_ids),
@@ -93,6 +93,7 @@ extern mi_cmd_argv_ftype mi_cmd_target_detach;
extern mi_cmd_argv_ftype mi_cmd_target_file_get;
extern mi_cmd_argv_ftype mi_cmd_target_file_put;
extern mi_cmd_argv_ftype mi_cmd_target_file_delete;
+extern mi_cmd_argv_ftype mi_cmd_target_flash_erase;
extern mi_cmd_argv_ftype mi_cmd_thread_info;
extern mi_cmd_argv_ftype mi_cmd_thread_list_ids;
extern mi_cmd_argv_ftype mi_cmd_thread_select;
@@ -552,6 +552,11 @@ mi_cmd_target_detach (char *command, char **argv, int argc)
detach_command (NULL, 0);
}
+void mi_cmd_target_flash_erase (char *command, char **argv, int argc)
+{
+ flash_erase_all_command (NULL, 0);
+}
+
void
mi_cmd_thread_select (char *command, char **argv, int argc)
{
@@ -3943,6 +3943,43 @@ do_monitor_command (char *cmd,
target_rcmd (cmd, gdb_stdtarg);
}
+void
+flash_erase_all_command (char *cmd, int from_tty)
+{
+ int i;
+ int found_flash_region = 0;
+ struct mem_region *m;
+ struct mem_attrib *attrib;
+ struct cleanup *cleanup_tuple;
+
+ VEC(mem_region_s) * mem_regions = target_memory_map ();
+
+ /* Iterate over all memory regions. */
+ for (i = 0; VEC_iterate (mem_region_s, mem_regions, i, m); i++)
+ {
+ attrib = &m->attrib;
+
+ /* Is this a flash memory region? */
+ if (attrib->mode == MEM_FLASH)
+ {
+ found_flash_region = 1;
+ target_flash_erase (m->lo, m->hi - m->lo);
+ cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (current_uiout, "erasing-regions");
+ current_uiout->message ("Erasing flash memory region at address ");
+ current_uiout->field_fmt ("address", "0x%x", (unsigned int) m->lo);
+ current_uiout->message (", size = ");
+ current_uiout->field_fmt ("size", "%lu", (unsigned long) (m->hi - m->lo));
+ current_uiout->message ("\n");
+ do_cleanups (cleanup_tuple);
+ }
+ }
+
+ if (found_flash_region)
+ target_flash_done ();
+ else
+ current_uiout->message ("No flash memory regions found.\n");
+}
+
/* Print the name of each layers of our target stack. */
static void
@@ -4233,6 +4270,9 @@ Otherwise, any attempt to interrupt or stop will be ignored."),
set_target_permissions, NULL,
&setlist, &showlist);
+ add_com ("flash-erase", no_class, flash_erase_all_command,
+ _("Erase all flash memory regions."));
+
add_setshow_boolean_cmd ("auto-connect-native-target", class_support,
&auto_connect_native_target, _("\
Set whether GDB may automatically connect to the native target."), _("\
@@ -1451,6 +1451,9 @@ extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
is returned. */
VEC(mem_region_s) *target_memory_map (void);
+/* Erases all flash memory regions on the target. */
+void flash_erase_all_command (char *cmd, int from_tty);
+
/* Erase the specified flash region. */
void target_flash_erase (ULONGEST address, LONGEST length);