- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- /* 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)
- {
- 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;
-}
-
-int handle_flash_protect_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- flash_bank_t *p;
- int retval;
-
- if (argc != 1)
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
- if (p)
- {
- if ((retval = p->driver->protect_check(p)) == ERROR_OK)
- {
- command_print(cmd_ctx, "successfully checked protect state");
- }
- else if (retval == ERROR_FLASH_OPERATION_FAILED)
- {
- command_print(cmd_ctx, "checking protection state failed (possibly unsupported) by flash #%s at 0x%8.8x", args[0], p->base);
- }
- else
- {
- command_print(cmd_ctx, "unknown error when checking protection state of flash bank '#%s' at 0x%8.8x", args[0], p->base);
- }
- }
- else
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- return ERROR_OK;
-}
-
-int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- if (argc > 2)
- {
- int first = strtoul(args[1], NULL, 0);
- int last = strtoul(args[2], NULL, 0);
- int retval;
- flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
- duration_t duration;
- char *duration_text;
-
- duration_start_measure(&duration);
-
- if (!p)
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
- {
- duration_stop_measure(&duration, &duration_text);
-
- command_print(cmd_ctx, "erased sectors %i through %i on flash bank %i in %s", first, last, strtoul(args[0], 0, 0), duration_text);
- free(duration_text);
- }
- }
- else
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- return ERROR_OK;
-}
-
-int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- if (argc > 3)
- {
- int first = strtoul(args[1], NULL, 0);
- int last = strtoul(args[2], NULL, 0);
- int set;
- int retval;
- flash_bank_t *p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
- if (!p)
- {
- command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
- return ERROR_OK;
- }
-
- if (strcmp(args[3], "on") == 0)
- set = 1;
- else if (strcmp(args[3], "off") == 0)
- set = 0;
- else
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- retval = flash_driver_protect(p, set, first, last);
- if (retval == ERROR_OK)
- {
- 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));
- }
- }
- else
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- }
-
- return ERROR_OK;
-}
-
-int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- target_t *target = get_current_target(cmd_ctx);
-
- image_t image;
- u32 written;
-
- duration_t duration;
- char *duration_text;
-
- int retval;
-
- if (argc < 1)
- {
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- }
-
- if (!target)
- {
- ERROR("no target selected");
- return ERROR_OK;
- }
-
- duration_start_measure(&duration);
-
- if (argc >= 2)
- {
- image.base_address_set = 1;
- image.base_address = strtoul(args[1], NULL, 0);
- }
- else
- {
- image.base_address_set = 0;
- image.base_address = 0x0;
- }
-
- image.start_address_set = 0;
-
- retval = image_open(&image, args[0], (argc == 3) ? args[2] : NULL);
- if (retval != ERROR_OK)
- {
- return retval;
- }