|
From: openocd-gerrit <ope...@us...> - 2026-10-16 07:37:18
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via bb5a52da599c3dac61ddc51d2fa8c1166ee795d0 (commit)
from 24651a5fce9eb5c9db6eeea3cd846b18041a5fc9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit bb5a52da599c3dac61ddc51d2fa8c1166ee795d0
Author: Tomas Vanek <va...@fb...>
Date: Wed Sep 9 09:08:25 2026 +0200
flash/nor, gdb_server: allow skipping flash bank without erase
Introduce new parameter to flash_erase_address_range()
allowing to skip banks with not defined erase method
while iterating over the address range.
Request skipping when erase is a preparatory operation
before writing. Missing erase support therefore means the memory
does not need to be erased before write.
Used in command
flash write_image erase
or in gdb load command.
Change-Id: Ide1d5c070418f11a2732e0c77494ca5c485cabf4
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9973
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tar...@gm...>
Reviewed-by: zapb <de...@za...>
Reviewed-by: Tomas Vanek <tom...@gm...>
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 9b7c64d64..323ae4864 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -6168,7 +6168,9 @@ explicitly as @option{bin} (binary), @option{ihex} (Intel hex),
@option{elf} (ELF file), @option{s19} (Motorola s19).
@option{mem}, or @option{builder}.
The relevant flash sectors will be erased prior to programming
-if the @option{erase} parameter is given. If @option{unlock} is
+if the @option{erase} parameter is given. @option{erase}
+is silently ignored for banks without erase support.
+If @option{unlock} is
provided, then the flash banks are unlocked before erase and
program. The flash bank to use is inferred from the address of
each image section.
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index bec542c42..f6ad97aee 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -649,7 +649,7 @@ static int flash_iterate_address_range_inner(struct target *target,
*/
static int flash_iterate_address_range(struct target *target,
char *pad_reason, target_addr_t addr, uint32_t length,
- bool iterate_protect_blocks,
+ bool iterate_protect_blocks, bool skip_banks_without_erase,
int (*callback)(struct flash_bank *bank, unsigned int first,
unsigned int last))
{
@@ -668,12 +668,17 @@ static int flash_iterate_address_range(struct target *target,
LOG_DEBUG("iterating over more than one flash bank.");
cur_length = c->base + c->size - addr;
}
- retval = flash_iterate_address_range_inner(target,
- pad_reason, addr, cur_length,
- iterate_protect_blocks,
- callback);
- if (retval != ERROR_OK)
- break;
+ if (skip_banks_without_erase && !c->driver->erase) {
+ LOG_DEBUG("bank %s does not support erase, skipped",
+ c->name);
+ } else {
+ retval = flash_iterate_address_range_inner(target,
+ pad_reason, addr, cur_length,
+ iterate_protect_blocks,
+ callback);
+ if (retval != ERROR_OK)
+ break;
+ }
length -= cur_length;
addr += cur_length;
@@ -683,10 +688,11 @@ static int flash_iterate_address_range(struct target *target,
}
int flash_erase_address_range(struct target *target,
- bool pad, target_addr_t addr, uint32_t length)
+ bool pad, target_addr_t addr, uint32_t length, bool skip_banks_without_erase)
{
return flash_iterate_address_range(target, pad ? "erase" : NULL,
- addr, length, false, &flash_driver_erase);
+ addr, length, false /* iterate_protect_blocks */,
+ skip_banks_without_erase, &flash_driver_erase);
}
static int flash_driver_unprotect(struct flash_bank *bank, unsigned int first,
@@ -703,7 +709,9 @@ int flash_unlock_address_range(struct target *target, target_addr_t addr,
* and doesn't restore it.
*/
return flash_iterate_address_range(target, "unprotect",
- addr, length, true, &flash_driver_unprotect);
+ addr, length, true /* iterate_protect_blocks */,
+ false /* skip_banks_without_erase */,
+ &flash_driver_unprotect);
}
static int compare_section(const void *a, const void *b)
@@ -1035,7 +1043,9 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
if (erase) {
/* calculate and erase sectors */
retval = flash_erase_address_range(target,
- true, run_address, run_size);
+ true /* pad */,
+ run_address, run_size,
+ true /* skip_banks_without_erase */);
}
}
diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h
index b1bb8ebba..d58dcb80f 100644
--- a/src/flash/nor/core.h
+++ b/src/flash/nor/core.h
@@ -149,10 +149,12 @@ int flash_register_commands(struct command_context *cmd_ctx);
* The range @a addr to @a addr + @a length - 1 must be strictly
* sector aligned, unless @a pad is true. Setting @a pad true extends
* the range, at beginning and/or end, if needed for sector alignment.
+ * @a skip_banks_without_erase silently skip banks which driver has
+ * no erase method defined.
* @returns ERROR_OK if successful; otherwise, an error code.
*/
int flash_erase_address_range(struct target *target,
- bool pad, target_addr_t addr, uint32_t length);
+ bool pad, target_addr_t addr, uint32_t length, bool skip_banks_without_erase);
int flash_unlock_address_range(struct target *target, target_addr_t addr,
uint32_t length);
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index cf2494bda..365a9e2ab 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -279,7 +279,8 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
retval = flash_unlock_address_range(target, address, length);
if (retval == ERROR_OK)
- retval = flash_erase_address_range(target, do_pad, address, length);
+ retval = flash_erase_address_range(target, do_pad, address, length,
+ false /* skip_banks_without_erase */);
if (retval == ERROR_FLASH_OPER_UNSUPPORTED) {
command_print(CMD, "erase operation is not supported");
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 934ba2265..d87164a51 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -3647,8 +3647,8 @@ static int gdb_v_packet(struct connection *connection,
* end to be "block" aligned ... if padding is ever needed,
* GDB will have become dangerously confused.
*/
- result = flash_erase_address_range(target, false, addr,
- length);
+ result = flash_erase_address_range(target, false, /* pad */
+ addr, length, true /* skip_banks_without_erase */);
/* perform any target specific operations after the erase */
target_call_event_callbacks(target,
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 4 +++-
src/flash/nor/core.c | 32 +++++++++++++++++++++-----------
src/flash/nor/core.h | 4 +++-
src/flash/nor/tcl.c | 3 ++-
src/server/gdb_server.c | 4 ++--
5 files changed, 31 insertions(+), 16 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|