|
From: openocd-gerrit <ope...@us...> - 2026-10-21 21:27:00
|
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 5088db4c9154ca833c6d558381074b33672e127a (commit)
from d2f72d49efed744eaa489ce931393b6e69122e66 (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 5088db4c9154ca833c6d558381074b33672e127a
Author: Marc Schink <de...@za...>
Date: Tue Sep 15 17:34:51 2026 +0200
flash/nor/tcl: Do not continue on error in 'erase_check'
Currently, 'flash erase_check' continues after an error occurs, such as
when the target is not halted:
> flash erase_check 0
Target not halted
Error: checking erase state of flash bank #0 at 0x00000000
# 0: 0x00000000 (0x400 1kB) not erased
# 1: 0x00000400 (0x400 1kB) not erased
# 2: 0x00000800 (0x400 1kB) not erased
# 3: 0x00000c00 (0x400 1kB) not erased
...
Return an error immediately when checking the erase state fails. While
at it, remove the success message for the underlying flash driver
operation to reduce verbosity.
Because sectors may not be readable, for example, due to read
protection settings, adapt default_flash_mem_blank_check() so that
when a read fails, the sector is marked as "unknown" rather than
triggering a fatal error.
Change-Id: I857e87bf30558974a1c1058345aa6a3baefac031
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/10002
Tested-by: jenkins
Reviewed-by: Tomas Vanek <tom...@gm...>
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index f6ad97aee..d8c7d5c15 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -329,12 +329,10 @@ int get_flash_bank_by_addr(struct target *target,
static int default_flash_mem_blank_check(struct flash_bank *bank)
{
- struct target *target = bank->target;
const int buffer_size = 1024;
- uint32_t n_bytes;
- int retval = ERROR_OK;
+ struct target *target = bank->target;
- if (bank->target->state != TARGET_HALTED) {
+ if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
@@ -346,36 +344,44 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
}
for (unsigned int i = 0; i < bank->num_sectors; i++) {
- uint32_t j;
bank->sectors[i].is_erased = 1;
- for (j = 0; j < bank->sectors[i].size; j += buffer_size) {
+ for (uint32_t j = 0; j < bank->sectors[i].size; j += buffer_size) {
uint32_t chunk;
chunk = buffer_size;
if (chunk > (bank->sectors[i].size - j))
chunk = (bank->sectors[i].size - j);
- retval = target_read_memory(target,
- bank->base + bank->sectors[i].offset + j,
- 4,
- chunk/4,
- buffer);
- if (retval != ERROR_OK)
- goto done;
+ int retval = target_read_buffer(target,
+ bank->base + bank->sectors[i].offset + j,
+ chunk, buffer);
- for (n_bytes = 0; n_bytes < chunk; n_bytes++) {
+ /* A sector that cannot be read cannot be classified.
+ * Mark it 'unknown' and continue with the next sector
+ * rather than failing the whole check.
+ */
+ if (retval != ERROR_OK) {
+ LOG_WARNING("Failed to check erase state on sector %u, "
+ "continuing on next sector", i);
+ bank->sectors[i].is_erased = -1;
+ break;
+ }
+
+ for (uint32_t n_bytes = 0; n_bytes < chunk; n_bytes++) {
if (buffer[n_bytes] != bank->erased_value) {
bank->sectors[i].is_erased = 0;
break;
}
}
+
+ if (bank->sectors[i].is_erased == 0)
+ break;
}
}
-done:
free(buffer);
- return retval;
+ return ERROR_OK;
}
static int flash_blank_check_no_sectors_fast(struct flash_bank *bank)
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index 365a9e2ab..a66b153bf 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -178,7 +178,6 @@ COMMAND_HANDLER(handle_flash_probe_command)
COMMAND_HANDLER(handle_flash_erase_check_command)
{
- bool blank = true;
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -191,16 +190,17 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
retval = p->driver->erase_check(p);
else
retval = default_flash_blank_check(p);
- if (retval == ERROR_OK) {
- command_print(CMD, "successfully checked erase state");
- } else {
+
+ if (retval != ERROR_OK) {
command_print(CMD,
- "Error: checking erase state of flash bank #%s at "
- TARGET_ADDR_FMT,
+ "checking erase state of flash bank #%s at "
+ TARGET_ADDR_FMT " failed",
CMD_ARGV[0],
p->base);
+ return retval;
}
+ bool blank = true;
for (unsigned int j = 0; j < p->num_sectors; j++) {
char *erase_state;
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/core.c | 38 ++++++++++++++++++++++----------------
src/flash/nor/tcl.c | 12 ++++++------
2 files changed, 28 insertions(+), 22 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|