+int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+ flash_bank_t *p;
+ int retval;
+ int address;
+ int length;
+ duration_t duration;
+ char *duration_text;
+
+ target_t *target = get_current_target(cmd_ctx);
+
+ if (argc != 2)
+ {
+ command_print(cmd_ctx, "usage: flash erase_address <address> <length>");
+ return ERROR_OK;
+ }
+
+ address = strtoul(args[0], NULL, 0);
+ length = strtoul(args[1], NULL, 0);
+ if (length <= 0)
+ {
+ command_print(cmd_ctx, "Length must be >0");
+ return ERROR_INVALID_ARGUMENTS;
+ }
+
+ p = get_flash_bank_by_addr(target, address);
+ if (p == NULL)
+ {
+ command_print(cmd_ctx, "No flash at that address");
+ return ERROR_INVALID_ARGUMENTS;
+ }
+
+ /* We can't know if we did a resume + halt, in which case we no longer know the erased state */
+ flash_set_dirty();
+
+ duration_start_measure(&duration);
+
+ if ((retval = flash_erase_address_range(target, address, length)) != ERROR_OK)
+ {
+ switch (retval)
+ {
+ case ERROR_TARGET_NOT_HALTED:
+ command_print(cmd_ctx, "can't work with this flash while target is running");
+ break;
+ case ERROR_INVALID_ARGUMENTS:
+ command_print(cmd_ctx, "usage: flash erase_address <address> <length>");
+ break;
+ case ERROR_FLASH_BANK_INVALID:
+ command_print(cmd_ctx, "no '%s' flash found at 0x%8.8x", p->driver->name, p->base);
+ break;
+ case ERROR_FLASH_OPERATION_FAILED:
+ command_print(cmd_ctx, "flash erase error");
+ break;
+ case ERROR_FLASH_SECTOR_INVALID:
+ command_print(cmd_ctx, "sector number(s) invalid");
+ break;
+ default:
+ command_print(cmd_ctx, "unknown error");
+ }
+ }
+ else
+ {
+ duration_stop_measure(&duration, &duration_text);
+ command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
+ free(duration_text);
+ }
+
+ return retval;
+}
+