nor: add get_flash_bank_by_name autoprobe
authorSpencer Oliver <ntfreak@users.sourceforge.net>
Mon, 24 May 2010 11:30:29 +0000 (12:30 +0100)
committerSpencer Oliver <ntfreak@users.sourceforge.net>
Wed, 26 May 2010 10:10:16 +0000 (11:10 +0100)
When a flash cmd is called using the flash name the autoprobe
function is not called. autoprobe is called if flash_command_get_bank
falls through to get_flash_bank_by_num.

This makes both get_flash_bank_by_name and get_flash_bank_by_num
behave the same.

Signed-off-by: Spencer Oliver <ntfreak@users.sourceforge.net>
src/flash/nor/core.c
src/flash/nor/core.h
src/flash/nor/tcl.c

index 00f73f214ae0a4a00a392cc1ab48ca7df0c4950f..1bd09b444d9c392d08f6f097937039c9660e8d43 100644 (file)
@@ -178,7 +178,7 @@ int flash_get_bank_count(void)
        return i;
 }
 
-struct flash_bank *get_flash_bank_by_name(const char *name)
+struct flash_bank *get_flash_bank_by_name_noprobe(const char *name)
 {
        unsigned requested = get_flash_name_index(name);
        unsigned found = 0;
@@ -197,6 +197,26 @@ struct flash_bank *get_flash_bank_by_name(const char *name)
        return NULL;
 }
 
+struct flash_bank *get_flash_bank_by_name(const char *name)
+{
+       struct flash_bank *bank;
+       int retval;
+
+       bank = get_flash_bank_by_name_noprobe(name);
+       if (bank != NULL)
+       {
+               retval = bank->driver->auto_probe(bank);
+
+               if (retval != ERROR_OK)
+               {
+                       LOG_ERROR("auto_probe failed %d\n", retval);
+                       return NULL;
+               }
+       }
+
+       return bank;
+}
+
 int get_flash_bank_by_num(int num, struct flash_bank **bank)
 {
        struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
@@ -660,7 +680,7 @@ int flash_write_unlock(struct target *target, struct image *image,
                        intptr_t diff = (intptr_t)sections[section] - (intptr_t)image->sections;
                        int t_section_num = diff / sizeof(struct imageection);
 
-                       LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d", 
+                       LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d",
                                 (int)section,
 (int)t_section_num, (int)section_offset, (int)buffer_size, (int)size_read);
                        if ((retval = image_read_section(image, t_section_num, section_offset,
index a35f64f68fb685a48630884e9367c963677849c1..17f1c53f9276da5ad4d9e6298a8c053a07736856 100644 (file)
@@ -170,7 +170,15 @@ int default_flash_mem_blank_check(struct flash_bank *bank);
  */
 struct flash_bank *get_flash_bank_by_name(const char *name);
 /**
- * Returns a flash bank by the specified flash_bank_s bank_number, @a num.
+ * Returns the flash bank specified by @a name, which matches the
+ * driver name and a suffix (option) specify the driver-specific
+ * bank number. The suffix consists of the '.' and the driver-specific
+ * bank number: when two str9x banks are defined, then 'str9x.1' refers
+ * to the second.
+ */
+struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
+/**
+ * Returns the flash bank like get_flash_bank_by_name(), without probing.
  * @param num The flash bank number.
  * @param bank returned bank if fn returns ERROR_OK
  * @returns ERROR_OK if successful
index 80d9a27c56890a8c5c9c40acb5df125f902b385c..b3dbd7b8e5fcacb1fb82c3f4fe12c3f4d2c24498 100644 (file)
@@ -796,7 +796,7 @@ COMMAND_HANDLER(handle_flash_bank_command)
        }
 
        /* check the flash bank name is unique */
-       if (get_flash_bank_by_name(bank_name) != NULL)
+       if (get_flash_bank_by_name_noprobe(bank_name) != NULL)
        {
                /* flash bank name already exists  */
                LOG_ERROR("flash bank name '%s' already exists", bank_name);