target: clean up return value of target_type::blank_check_memory()

The functions in struct target_type::blank_check_memory() return
either an OpenOCD error or a positive value that indicates the
number of blocks checked.

To prevent the mix of error codes and returned values, return the
value through an additional parameter 'checked' and then return
ERROR_OK.

While there:
- change to unsigned int the parameter 'num_blocks';
- in armv7m_blank_check_memory() verify that the working area can
  contain at least two 'algo_block'.

Change-Id: Ie22f5816819bc77ec611c3f251373d026ed9f784
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9386
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
Antonio Borneo
2025-12-25 15:53:07 +01:00
parent 5151c98455
commit 3c1bd50217
12 changed files with 51 additions and 39 deletions

View File

@@ -400,17 +400,18 @@ int default_flash_blank_check(struct flash_bank *bank)
bool fast_check = true;
for (unsigned int i = 0; i < bank->num_sectors; ) {
unsigned int checked;
retval = target_blank_check_memory(target,
block_array + i, bank->num_sectors - i,
bank->erased_value);
if (retval < 1) {
bank->erased_value, &checked);
if (retval != ERROR_OK) {
/* Run slow fallback if the first run gives no result
* otherwise use possibly incomplete results */
if (i == 0)
fast_check = false;
break;
}
i += retval; /* add number of blocks done this round */
i += checked; /* add number of blocks done this round */
}
if (fast_check) {

View File

@@ -1081,17 +1081,18 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
bool fast_check = true;
for (unsigned int i = 0; i < num_sectors; ) {
unsigned int checked;
retval = armv7m_blank_check_memory(target,
block_array + i, num_sectors - i,
bank->erased_value);
if (retval < 1) {
bank->erased_value, &checked);
if (retval != ERROR_OK) {
/* Run slow fallback if the first run gives no result
* otherwise use possibly incomplete results */
if (i == 0)
fast_check = false;
break;
}
i += retval; /* add number of blocks done this round */
i += checked; /* add number of blocks done this round */
}
if (fast_check) {