remove flash_driver->register_callbacks
authorZachary T Welch <zw@superlucidity.net>
Sun, 22 Nov 2009 14:12:04 +0000 (06:12 -0800)
committerZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 05:37:35 +0000 (21:37 -0800)
Replace flash_driver callback with pointer to command_registration.
Eliminates all related routines and allows drivers to omit commands.

17 files changed:
src/flash/at91sam3.c
src/flash/at91sam7.c
src/flash/avrf.c
src/flash/cfi.c
src/flash/ecos.c
src/flash/faux.c
src/flash/flash.c
src/flash/flash.h
src/flash/lpc2000.c
src/flash/lpc2900.c
src/flash/pic32mx.c
src/flash/stellaris.c
src/flash/stm32x.c
src/flash/str7x.c
src/flash/str9x.c
src/flash/str9xpec.c
src/flash/tms470.c

index 75e8495..be17a5f 100644 (file)
@@ -2501,14 +2501,9 @@ static const struct command_registration at91sam3_command_handlers[] = {
        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,
index 0204660..f9b87ba 100644 (file)
@@ -1198,14 +1198,9 @@ static const struct command_registration at91sam7_command_handlers[] = {
        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,
index 9aea47d..1c48464 100644 (file)
@@ -468,14 +468,9 @@ static const struct command_registration avrf_command_handlers[] = {
        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,
index b92ecbd..6dbffb9 100644 (file)
@@ -589,11 +589,6 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size)
        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)
@@ -2623,7 +2618,6 @@ static int cfi_info(struct flash_bank *bank, char *buf, int buf_size)
 
 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,
index f6f3307..7a0b26f 100644 (file)
@@ -336,11 +336,6 @@ static int ecosflash_probe(struct flash_bank *bank)
        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)
 {
@@ -437,7 +432,6 @@ static int ecosflash_handle_gpnvm_command(struct command_context *cmd_ctx, char
 
 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,
index 558d7b0..adfc7bd 100644 (file)
@@ -87,11 +87,6 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
        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;
@@ -130,7 +125,6 @@ static int faux_probe(struct flash_bank *bank)
 
 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,
index de95b62..4584c5d 100644 (file)
@@ -263,15 +263,20 @@ COMMAND_HANDLER(handle_flash_bank_command)
                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;
index ac1600e..92727bf 100644 (file)
@@ -91,13 +91,11 @@ struct flash_driver
        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
index 896b794..418b5b0 100644 (file)
@@ -795,14 +795,9 @@ static const struct command_registration lpc2000_command_handlers[] = {
        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,
index 0d961e4..81e2def 100644 (file)
@@ -1003,15 +1003,6 @@ static const struct command_registration lpc2900_command_handlers[] = {
        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)
 {
@@ -1830,7 +1821,7 @@ static int lpc2900_info(struct flash_bank *bank, char *buf, int buf_size)
 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,
index 1950e05..9bb6c97 100644 (file)
@@ -907,14 +907,9 @@ static const struct command_registration pic32mx_command_handlers[] = {
        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,
index 1cff486..771f0a7 100644 (file)
@@ -1180,15 +1180,9 @@ static const struct command_registration stellaris_command_handlers[] = {
        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,
index 808e32c..2f51aa5 100644 (file)
@@ -1225,13 +1225,9 @@ static const struct command_registration stm32x_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,
+               .commands = stm32x_command_handlers,
                .flash_bank_command = &stm32x_flash_bank_command,
                .erase = &stm32x_erase,
                .protect = &stm32x_protect,
index e72946f..7edffac 100644 (file)
@@ -691,14 +691,9 @@ static const struct command_registration str7x_command_handlers[] = {
        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,
index f6ad51a..98f15e7 100644 (file)
@@ -696,14 +696,9 @@ static const struct command_registration str9x_command_handlers[] = {
        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,
index 7f6a29a..96e1259 100644 (file)
@@ -1242,15 +1242,9 @@ static const struct command_registration str9xpec_command_handlers[] = {
        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,
index 3f32b51..682013e 100644 (file)
@@ -848,11 +848,6 @@ static const struct command_registration tms470_command_handlers[] = {
        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)
@@ -1263,7 +1258,7 @@ FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command)
 
 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,