+
+static const struct command_registration flash_exec_command_handlers[] = {
+ {
+ .name = "probe",
+ .handler = &handle_flash_probe_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank>",
+ .help = "identify flash bank",
+ },
+ {
+ .name = "info",
+ .handler = &handle_flash_info_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank>",
+ .help = "print bank information",
+ },
+ {
+ .name = "erase_check",
+ .handler = &handle_flash_erase_check_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank>",
+ .help = "check erase state of sectors",
+ },
+ {
+ .name = "protect_check",
+ .handler = &handle_flash_protect_check_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank>",
+ .help = "check protection state of sectors",
+ },
+ {
+ .name = "erase_sector",
+ .handler = &handle_flash_erase_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <first> <last>",
+ .help = "erase sectors",
+ },
+ {
+ .name = "erase_address",
+ .handler = &handle_flash_erase_address_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<address> <length>",
+ .help = "erase address range",
+
+ },
+ {
+ .name = "fillw",
+ .handler = &handle_flash_fill_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <address> <word_pattern> <count>",
+ .help = "fill with pattern (no autoerase)",
+ },
+ {
+ .name = "fillh",
+ .handler = &handle_flash_fill_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <address> <halfword_pattern> <count>",
+ .help = "fill with pattern",
+ },
+ {
+ .name = "fillb",
+ .handler = &handle_flash_fill_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <address> <byte_pattern> <count>",
+ .help = "fill with pattern",
+
+ },
+ {
+ .name = "write_bank",
+ .handler = &handle_flash_write_bank_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <file> <offset>",
+ .help = "write binary data",
+ },
+ {
+ .name = "write_image",
+ .handler = &handle_flash_write_image_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> [erase] [unlock] <file> [offset] [type]",
+ .help = "write an image to flash"
+ },
+ {
+ .name = "protect",
+ .handler = &handle_flash_protect_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<bank> <first> <last> <on | off>",
+ .help = "set protection of sectors",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+int flash_init_drivers(struct command_context *cmd_ctx)
+{
+ if (!flash_banks)
+ return ERROR_OK;
+
+ struct command *parent = command_find_in_context(cmd_ctx, "flash");
+ return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
+}
+
+COMMAND_HANDLER(handle_flash_init_command)
+{
+ if (CMD_ARGC != 0)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ static bool flash_initialized = false;
+ if (flash_initialized)
+ {
+ LOG_INFO("'flash init' has already been called");
+ return ERROR_OK;
+ }
+ flash_initialized = true;
+
+ LOG_DEBUG("Initializing flash devices...");
+ return flash_init_drivers(CMD_CTX);
+}
+
+static const struct command_registration flash_config_command_handlers[] = {
+ {
+ .name = "bank",
+ .handler = &handle_flash_bank_command,
+ .mode = COMMAND_CONFIG,
+ .usage = "<name> <driver> <base> <size> "
+ "<chip_width> <bus_width> <target> "
+ "[driver_options ...]",
+ .help = "Define a new bank with the given name, "
+ "using the specified NOR flash driver.",
+ },
+ {
+ .name = "init",
+ .mode = COMMAND_CONFIG,
+ .handler = &handle_flash_init_command,
+ .help = "initialize flash devices",
+ },
+ {
+ .name = "banks",
+ .mode = COMMAND_ANY,
+ .jim_handler = &jim_flash_banks,
+ .help = "return information about the flash banks",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration flash_command_handlers[] = {
+ {
+ .name = "flash",
+ .mode = COMMAND_ANY,
+ .help = "NOR flash command group",
+ .chain = flash_config_command_handlers,
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+int flash_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL, flash_command_handlers);
+}