Replace flash_driver callback with pointer to command_registration.
Eliminates all related routines and allows drivers to omit commands.
COMMAND_REGISTRATION_DONE
};
-static int sam3_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, at91sam3_command_handlers);
-}
-
struct flash_driver at91sam3_flash = {
.name = "at91sam3",
- .register_commands = &sam3_register_commands,
+ .commands = at91sam3_command_handlers,
.flash_bank_command = &sam3_flash_bank_command,
.erase = &sam3_erase,
.protect = &sam3_protect,
COMMAND_REGISTRATION_DONE
};
-static int at91sam7_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, at91sam7_command_handlers);
-}
-
struct flash_driver at91sam7_flash = {
.name = "at91sam7",
- .register_commands = &at91sam7_register_commands,
+ .commands = at91sam7_command_handlers,
.flash_bank_command = &at91sam7_flash_bank_command,
.erase = &at91sam7_erase,
.protect = &at91sam7_protect,
COMMAND_REGISTRATION_DONE
};
-static int avrf_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, avrf_command_handlers);
-}
-
struct flash_driver avr_flash = {
.name = "avr",
- .register_commands = &avrf_register_commands,
+ .commands = avrf_command_handlers,
.flash_bank_command = &avrf_flash_bank_command,
.erase = &avrf_erase,
.protect = &avrf_protect,
return ERROR_OK;
}
-static int cfi_register_commands(struct command_context *cmd_ctx)
-{
- return ERROR_OK;
-}
-
/* flash_bank cfi <base> <size> <chip_width> <bus_width> <target#> [options]
*/
FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
struct flash_driver cfi_flash = {
.name = "cfi",
- .register_commands = &cfi_register_commands,
.flash_bank_command = &cfi_flash_bank_command,
.erase = &cfi_erase,
.protect = &cfi_protect,
return ERROR_OK;
}
-static int ecosflash_register_commands(struct command_context *cmd_ctx)
-{
- return ERROR_OK;
-}
-
#if 0
static void command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf)
{
struct flash_driver ecosflash_flash = {
.name = "ecosflash",
- .register_commands = &ecosflash_register_commands,
.flash_bank_command = &ecosflash_flash_bank_command,
.erase = &ecosflash_erase,
.protect = &ecosflash_protect,
return ERROR_OK;
}
-static int faux_register_commands(struct command_context *cmd_ctx)
-{
- return ERROR_OK;
-}
-
static int faux_erase(struct flash_bank *bank, int first, int last)
{
struct faux_flash_bank *info = bank->driver_priv;
struct flash_driver faux_flash = {
.name = "faux",
- .register_commands = &faux_register_commands,
.flash_bank_command = &faux_flash_bank_command,
.erase = &faux_erase,
.protect = &faux_protect,
if (strcmp(driver_name, flash_drivers[i]->name) != 0)
continue;
- struct flash_bank *p, *c;
-
/* register flash specific commands */
- if (flash_drivers[i]->register_commands(CMD_CTX) != ERROR_OK)
+ if (NULL != flash_drivers[i]->commands)
{
- LOG_ERROR("couldn't register '%s' commands", driver_name);
- return ERROR_FAIL;
+ int retval = register_commands(CMD_CTX, NULL,
+ flash_drivers[i]->commands);
+ if (ERROR_OK != retval)
+ {
+ LOG_ERROR("couldn't register '%s' commands",
+ driver_name);
+ return ERROR_FAIL;
+ }
}
+ struct flash_bank *p, *c;
c = malloc(sizeof(struct flash_bank));
c->name = strdup(bank_name);
c->target = target;
char *name;
/**
- * Registers driver-specific commands. When called (during the
- * "flash bank" command), the driver may register addition
+ * An array of driver-specific commands to register. When called
+ * during the "flash bank" command, the driver can register addition
* commands to support new flash chip functions.
- *
- * @returns ERROR_OK if successful; otherwise, an error code.
*/
- int (*register_commands)(struct command_context *cmd_ctx);
+ const struct command_registration *commands;
/**
* Finish the "flash bank" command for @a bank. The
COMMAND_REGISTRATION_DONE
};
-static int lpc2000_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, lpc2000_command_handlers);
-}
-
struct flash_driver lpc2000_flash = {
.name = "lpc2000",
- .register_commands = &lpc2000_register_commands,
+ .commands = lpc2000_command_handlers,
.flash_bank_command = &lpc2000_flash_bank_command,
.erase = &lpc2000_erase,
.protect = &lpc2000_protect,
COMMAND_REGISTRATION_DONE
};
-/**
- * Register private command handlers.
- */
-static int lpc2900_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, lpc2900_command_handlers);
-}
-
-
/// Evaluate flash bank command.
FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command)
{
struct flash_driver lpc2900_flash =
{
.name = "lpc2900",
- .register_commands = lpc2900_register_commands,
+ .commands = lpc2900_command_handlers,
.flash_bank_command = lpc2900_flash_bank_command,
.erase = lpc2900_erase,
.protect = lpc2900_protect,
COMMAND_REGISTRATION_DONE
};
-static int pic32mx_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, pic32mx_command_handlers);
-}
-
struct flash_driver pic32mx_flash = {
.name = "pic32mx",
- .register_commands = &pic32mx_register_commands,
+ .commands = pic32mx_command_handlers,
.flash_bank_command = &pic32mx_flash_bank_command,
.erase = &pic32mx_erase,
.protect = &pic32mx_protect,
COMMAND_REGISTRATION_DONE
};
-static int stellaris_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, stellaris_command_handlers);
-}
-
-
struct flash_driver stellaris_flash = {
.name = "stellaris",
- .register_commands = &stellaris_register_commands,
+ .commands = stellaris_command_handlers,
.flash_bank_command = &stellaris_flash_bank_command,
.erase = &stellaris_erase,
.protect = &stellaris_protect,
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,
+ .commands = stm32x_command_handlers,
.flash_bank_command = &stm32x_flash_bank_command,
.erase = &stm32x_erase,
.protect = &stm32x_protect,
COMMAND_REGISTRATION_DONE
};
-static int str7x_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, str7x_command_handlers);
-}
-
struct flash_driver str7x_flash = {
.name = "str7x",
- .register_commands = &str7x_register_commands,
+ .commands = str7x_command_handlers,
.flash_bank_command = &str7x_flash_bank_command,
.erase = &str7x_erase,
.protect = &str7x_protect,
COMMAND_REGISTRATION_DONE
};
-static int str9x_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, str9x_command_handlers);
-}
-
struct flash_driver str9x_flash = {
.name = "str9x",
- .register_commands = &str9x_register_commands,
+ .commands = str9x_command_handlers,
.flash_bank_command = &str9x_flash_bank_command,
.erase = &str9x_erase,
.protect = &str9x_protect,
COMMAND_REGISTRATION_DONE
};
-static int str9xpec_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, str9xpec_command_handlers);
-}
-
-
struct flash_driver str9xpec_flash = {
.name = "str9xpec",
- .register_commands = &str9xpec_register_commands,
+ .commands = str9xpec_command_handlers,
.flash_bank_command = &str9xpec_flash_bank_command,
.erase = &str9xpec_erase,
.protect = &str9xpec_protect,
COMMAND_REGISTRATION_DONE
};
-static int tms470_register_commands(struct command_context *cmd_ctx)
-{
- return register_commands(cmd_ctx, NULL, tms470_command_handlers);
-}
-
/* ---------------------------------------------------------------------- */
static int tms470_erase(struct flash_bank *bank, int first, int last)
struct flash_driver tms470_flash = {
.name = "tms470",
- .register_commands = &tms470_register_commands,
+ .commands = tms470_command_handlers,
.flash_bank_command = &tms470_flash_bank_command,
.erase = &tms470_erase,
.protect = &tms470_protect,