diff --git a/src/target/target.c b/src/target/target.c index 1ff7ca6..0a430fb 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -20,6 +20,7 @@ #include "general.h" #include "target_internal.h" +#include "gdb_packet.h" #include #include @@ -31,6 +32,12 @@ target *target_list = NULL; static int target_flash_write_buffered(struct target_flash *f, target_addr dest, const void *src, size_t len); static int target_flash_done_buffered(struct target_flash *f); +static bool target_cmd_mass_erase(target *t, int argc, const char **argv); + +const struct command_s target_cmd_list[] = { + {"erase_mass", (cmd_handler)target_cmd_mass_erase, "Erase whole device Flash"}, + {NULL, NULL, NULL} +}; static bool nop_function(void) { @@ -75,6 +82,7 @@ target *target_new(void) t->target_storage = NULL; + target_add_commands(t, target_cmd_list, "Target"); return t; } @@ -510,6 +518,21 @@ int target_breakwatch_clear(target *t, return ret; } +/* Target-specific commands */ +static bool target_cmd_mass_erase(target *const t, const int argc, const char **const argv) +{ + (void)argc; + (void)argv; + if (!t || !t->mass_erase) { + gdb_out("Mass erase not implemented for target"); + return true; + } + gdb_out("Erasing device Flash: "); + const bool result = t->mass_erase(t); + gdb_out("done\n"); + return result; +} + /* Accessor functions */ size_t target_regs_size(target *t) { diff --git a/src/target/target_internal.h b/src/target/target_internal.h index 90233fe..93662c3 100644 --- a/src/target/target_internal.h +++ b/src/target/target_internal.h @@ -109,6 +109,9 @@ struct target_s { int (*breakwatch_clear)(target *t, struct breakwatch*); struct breakwatch *bw_list; + /* Recovery functions */ + bool (*mass_erase)(target *t); + /* target-defined options */ unsigned target_options; uint16_t t_designer;