+
+COMMAND_HANDLER(stm32x_handle_mass_erase_command)
+{
+ int i;
+
+ if (CMD_ARGC < 1)
+ {
+ command_print(CMD_CTX, "stm32x mass_erase <bank>");
+ return ERROR_OK;
+ }
+
+ struct flash_bank *bank;
+ int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
+ if (ERROR_OK != retval)
+ return retval;
+
+ if (stm32x_mass_erase(bank) == ERROR_OK)
+ {
+ /* set all sectors as erased */
+ for (i = 0; i < bank->num_sectors; i++)
+ {
+ bank->sectors[i].is_erased = 1;
+ }
+
+ command_print(CMD_CTX, "stm32x mass erase complete");
+ }
+ else
+ {
+ command_print(CMD_CTX, "stm32x mass erase failed");
+ }
+
+ return ERROR_OK;
+}
+
+static const struct command_registration stm32x_exec_command_handlers[] = {
+ {
+ .name = "lock",
+ .handler = &stm32x_handle_lock_command,
+ .mode = COMMAND_EXEC,
+ .help = "lock device",
+ },
+ {
+ .name = "unlock",
+ .handler = &stm32x_handle_unlock_command,
+ .mode = COMMAND_EXEC,
+ .help = "unlock protected device",
+ },
+ {
+ .name = "mass_erase",
+ .handler = &stm32x_handle_mass_erase_command,
+ .mode = COMMAND_EXEC,
+ .help = "mass erase device",
+ },
+ {
+ .name = "options_read",
+ .handler = &stm32x_handle_options_read_command,
+ .mode = COMMAND_EXEC,
+ .help = "read device option bytes",
+ },
+ {
+ .name = "options_write",
+ .handler = &stm32x_handle_options_write_command,
+ .mode = COMMAND_EXEC,
+ .help = "write device option bytes",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration stm32x_command_handlers[] = {
+ {
+ .name = "stm32x",
+ .mode = COMMAND_ANY,
+ .help = "stm32x flash command group",
+ .chain = stm32x_exec_command_handlers,
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+static int stm32x_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL, stm32x_command_handlers);
+}
+struct flash_driver stm32x_flash = {
+ .name = "stm32x",
+ .register_commands = &stm32x_register_commands,
+ .flash_bank_command = &stm32x_flash_bank_command,
+ .erase = &stm32x_erase,
+ .protect = &stm32x_protect,
+ .write = &stm32x_write,
+ .probe = &stm32x_probe,
+ .auto_probe = &stm32x_auto_probe,
+ .erase_check = &default_flash_mem_blank_check,
+ .protect_check = &stm32x_protect_check,
+ .info = &stm32x_info,
+ };