- flash_bank_t *p;
- int retval;
-
- if (argc != 1)
- {
- command_print(cmd_ctx, "usage: flash probe <num>");
- return ERROR_OK;
- }
-
- p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
- if (p)
- {
- if ((retval = p->driver->probe(p)) == ERROR_OK)
- {
- command_print(cmd_ctx, "flash '%s' found at 0x%8.8x", p->driver->name, p->base);
- }
- else if (retval == ERROR_FLASH_BANK_INVALID)
- {
- command_print(cmd_ctx, "probing failed for flash bank '#%s' at 0x%8.8x",
- args[0], p->base);
- }
- else
- {
- command_print(cmd_ctx, "unknown error when probing flash bank '#%s' at 0x%8.8x",
- args[0], p->base);
- }
- }
- else
- {
- command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
- }
-
- return ERROR_OK;
-}
-
-int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
-{
- flash_bank_t *p;
- int retval;
-
- if (argc != 1)
- {
- command_print(cmd_ctx, "usage: flash erase_check <num>");
- return ERROR_OK;
- }
-
- p = get_flash_bank_by_num(strtoul(args[0], NULL, 0));
- if (p)
- {
- if ((retval = p->driver->erase_check(p)) == ERROR_OK)
- {
- command_print(cmd_ctx, "successfully checked erase state", p->driver->name, p->base);
- }
- else
- {
- command_print(cmd_ctx, "unknown error when checking erase state of flash bank #%s at 0x%8.8x",
- args[0], p->base);
- }
- }
- else
- {
- command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
- }
-
- return ERROR_OK;
-}
-
-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)
- {
- command_print(cmd_ctx, "usage: flash protect_check <num>");
- return ERROR_OK;
- }
-
- 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
- {
- command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
- }
-
- 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)
- {
- command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]);
- return ERROR_OK;
- }
-
- if ((retval = p->driver->erase(p, first, last)) != 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 <bank> <first> <last>");
- 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;
- case ERROR_OK:
- command_print(cmd_ctx, "erased flash sectors %i to %i", first, last);
- break;
- default:
- command_print(cmd_ctx, "unknown error");
- }
- }
- else
- {
- 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
- {
- command_print(cmd_ctx, "usage: flash erase <bank> <first> <last>");
- }