]> git.sur5r.net Git - openocd/commitdiff
add support for naming flash banks
authorZachary T Welch <zw@superlucidity.net>
Tue, 17 Nov 2009 22:04:25 +0000 (14:04 -0800)
committerZachary T Welch <zw@superlucidity.net>
Thu, 19 Nov 2009 21:39:41 +0000 (13:39 -0800)
Requires users to name their flash banks, allowing them to be used
instead of bank numbers in script commands.

src/flash/flash.c
src/flash/flash.h

index e93aa6366ef30adea7eeedcac213127c5f006d77..ef6c6da0f5c14b96b11ec8b0561555df068def09 100644 (file)
@@ -189,6 +189,8 @@ struct flash_bank *get_flash_bank_by_name(const char *name)
        struct flash_bank *bank;
        for (bank = flash_banks; NULL != bank; bank = bank->next)
        {
+               if (strcmp(bank->name, name) == 0)
+                       return bank;
                if (!flash_driver_name_matches(bank->driver->name, name))
                        continue;
                if (++found < requested)
@@ -239,12 +241,15 @@ COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
 
 COMMAND_HANDLER(handle_flash_bank_command)
 {
-       if (CMD_ARGC < 6)
+       if (CMD_ARGC < 7)
        {
-               LOG_ERROR("usage: flash bank <driver> "
+               LOG_ERROR("usage: flash bank <name> <driver> "
                                "<base> <size> <chip_width> <bus_width>");
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
+       // save bank name and advance arguments for compatibility
+       const char *bank_name = *CMD_ARGV++;
+       CMD_ARGC--;
 
        struct target *target;
        if ((target = get_target(CMD_ARGV[5])) == NULL)
@@ -269,6 +274,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
                }
 
                c = malloc(sizeof(struct flash_bank));
+               c->name = strdup(bank_name);
                c->target = target;
                c->driver = flash_drivers[i];
                c->driver_priv = NULL;
index 1235a419ecf016469d4d8668a9833721ce9d22ac..ac1600e4587f535942aa2f633ffae8b1f77129fe 100644 (file)
@@ -240,6 +240,8 @@ struct flash_driver
  */
 struct flash_bank
 {
+       char *name;
+
        struct target *target; /**< Target to which this bank belongs. */
 
        struct flash_driver *driver; /**< Driver for this bank. */