Hi,
The attached patch makes both get_flash_bank_by_name and
get_flash_bank_by_num behave the same, eg. They both now call autoprobe.
I noticed this issue when calling flash erase stm32.flash 0 last
Because the flash had not been probed the last parameter was filled with
invalid data.
repo is here for people who prefer that method of viewing patches.
http://repo.or.cz/w/openocd/ntfreak.git/shortlog/refs/heads/vbank
Cheers
Spen
>From 25b5e6691425e263fd5ab1c4e4f13f20524f7d06 Mon Sep 17 00:00:00 2001
From: Spencer Oliver <[email protected]>
Date: Mon, 24 May 2010 12:30:29 +0100
Subject: [PATCH 1/2] nor: add get_flash_bank_by_name autoprobe
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 <[email protected]>
---
src/flash/nor/core.c | 24 ++++++++++++++++++++++--
src/flash/nor/core.h | 10 +++++++++-
src/flash/nor/tcl.c | 2 +-
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index 00f73f2..1bd09b4 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -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,
diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h
index a35f64f..17f1c53 100644
--- a/src/flash/nor/core.h
+++ b/src/flash/nor/core.h
@@ -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
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index 80d9a27..b3dbd7b 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -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);
--
1.6.6.1
>From 6fdc5f40158f0bbbf0cb491d7f9b0aa5670fc058 Mon Sep 17 00:00:00 2001
From: Spencer Oliver <[email protected]>
Date: Mon, 24 May 2010 12:32:58 +0100
Subject: [PATCH 2/2] flash: virtual driver update for
get_flash_bank_by_name_noprobe
Make sure we do not probe a flash when getting info.
Signed-off-by: Spencer Oliver <[email protected]>
---
src/flash/nor/virtual.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/flash/nor/virtual.c b/src/flash/nor/virtual.c
index b4cb71c..ac46423 100644
--- a/src/flash/nor/virtual.c
+++ b/src/flash/nor/virtual.c
@@ -27,7 +27,7 @@ static struct flash_bank* virtual_get_parent_bank(struct
flash_bank *bank)
{
struct flash_bank* master_bank;
- master_bank = get_flash_bank_by_name(bank->driver_priv);
+ master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv);
if (master_bank == NULL) {
LOG_ERROR("master flash bank '%s' does not exist",
(char*)bank->driver_priv);
}
@@ -61,7 +61,7 @@ FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command)
/* get the master flash bank */
const char *bank_name = CMD_ARGV[6];
- struct flash_bank *master_bank = get_flash_bank_by_name(bank_name);
+ struct flash_bank *master_bank =
get_flash_bank_by_name_noprobe(bank_name);
if (master_bank == NULL)
{
--
1.6.6.1
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development