forked from auracaster/openocd
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:
@@ -400,17 +400,18 @@ int default_flash_blank_check(struct flash_bank *bank)
|
|||||||
|
|
||||||
bool fast_check = true;
|
bool fast_check = true;
|
||||||
for (unsigned int i = 0; i < bank->num_sectors; ) {
|
for (unsigned int i = 0; i < bank->num_sectors; ) {
|
||||||
|
unsigned int checked;
|
||||||
retval = target_blank_check_memory(target,
|
retval = target_blank_check_memory(target,
|
||||||
block_array + i, bank->num_sectors - i,
|
block_array + i, bank->num_sectors - i,
|
||||||
bank->erased_value);
|
bank->erased_value, &checked);
|
||||||
if (retval < 1) {
|
if (retval != ERROR_OK) {
|
||||||
/* Run slow fallback if the first run gives no result
|
/* Run slow fallback if the first run gives no result
|
||||||
* otherwise use possibly incomplete results */
|
* otherwise use possibly incomplete results */
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
fast_check = false;
|
fast_check = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i += retval; /* add number of blocks done this round */
|
i += checked; /* add number of blocks done this round */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fast_check) {
|
if (fast_check) {
|
||||||
|
|||||||
@@ -1081,17 +1081,18 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
|
|||||||
|
|
||||||
bool fast_check = true;
|
bool fast_check = true;
|
||||||
for (unsigned int i = 0; i < num_sectors; ) {
|
for (unsigned int i = 0; i < num_sectors; ) {
|
||||||
|
unsigned int checked;
|
||||||
retval = armv7m_blank_check_memory(target,
|
retval = armv7m_blank_check_memory(target,
|
||||||
block_array + i, num_sectors - i,
|
block_array + i, num_sectors - i,
|
||||||
bank->erased_value);
|
bank->erased_value, &checked);
|
||||||
if (retval < 1) {
|
if (retval != ERROR_OK) {
|
||||||
/* Run slow fallback if the first run gives no result
|
/* Run slow fallback if the first run gives no result
|
||||||
* otherwise use possibly incomplete results */
|
* otherwise use possibly incomplete results */
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
fast_check = false;
|
fast_check = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i += retval; /* add number of blocks done this round */
|
i += checked; /* add number of blocks done this round */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fast_check) {
|
if (fast_check) {
|
||||||
|
|||||||
@@ -323,7 +323,8 @@ int armv4_5_run_algorithm_inner(struct target *target,
|
|||||||
int arm_checksum_memory(struct target *target,
|
int arm_checksum_memory(struct target *target,
|
||||||
target_addr_t address, uint32_t count, uint32_t *checksum);
|
target_addr_t address, uint32_t count, uint32_t *checksum);
|
||||||
int arm_blank_check_memory(struct target *target,
|
int arm_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked);
|
||||||
|
|
||||||
void arm_set_cpsr(struct arm *arm, uint32_t cpsr);
|
void arm_set_cpsr(struct arm *arm, uint32_t cpsr);
|
||||||
struct reg *arm_reg_current(struct arm *arm, unsigned int regnum);
|
struct reg *arm_reg_current(struct arm *arm, unsigned int regnum);
|
||||||
|
|||||||
@@ -1686,7 +1686,8 @@ int arm_checksum_memory(struct target *target,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int arm_blank_check_memory(struct target *target,
|
int arm_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked)
|
||||||
{
|
{
|
||||||
struct working_area *check_algorithm;
|
struct working_area *check_algorithm;
|
||||||
struct reg_param reg_params[3];
|
struct reg_param reg_params[3];
|
||||||
@@ -1748,8 +1749,10 @@ int arm_blank_check_memory(struct target *target,
|
|||||||
exit_var,
|
exit_var,
|
||||||
10000, &arm_algo);
|
10000, &arm_algo);
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
if (retval == ERROR_OK) {
|
||||||
blocks[0].result = buf_get_u32(reg_params[2].value, 0, 32);
|
blocks[0].result = buf_get_u32(reg_params[2].value, 0, 32);
|
||||||
|
*checked = 1; /* only one block has been checked */
|
||||||
|
}
|
||||||
|
|
||||||
destroy_reg_param(®_params[0]);
|
destroy_reg_param(®_params[0]);
|
||||||
destroy_reg_param(®_params[1]);
|
destroy_reg_param(®_params[1]);
|
||||||
@@ -1757,10 +1760,7 @@ int arm_blank_check_memory(struct target *target,
|
|||||||
|
|
||||||
target_free_working_area(target, check_algorithm);
|
target_free_working_area(target, check_algorithm);
|
||||||
|
|
||||||
if (retval != ERROR_OK)
|
return retval;
|
||||||
return retval;
|
|
||||||
|
|
||||||
return 1; /* only one block has been checked */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arm_full_context(struct target *target)
|
static int arm_full_context(struct target *target)
|
||||||
|
|||||||
@@ -973,7 +973,8 @@ cleanup:
|
|||||||
|
|
||||||
/** Checks an array of memory regions whether they are erased. */
|
/** Checks an array of memory regions whether they are erased. */
|
||||||
int armv7m_blank_check_memory(struct target *target,
|
int armv7m_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked)
|
||||||
{
|
{
|
||||||
struct working_area *erase_check_algorithm;
|
struct working_area *erase_check_algorithm;
|
||||||
struct working_area *erase_check_params;
|
struct working_area *erase_check_params;
|
||||||
@@ -1009,7 +1010,13 @@ int armv7m_blank_check_memory(struct target *target,
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint32_t avail = target_get_working_area_avail(target);
|
uint32_t avail = target_get_working_area_avail(target);
|
||||||
int blocks_to_check = avail / sizeof(struct algo_block) - 1;
|
unsigned int avail_blocks = avail / sizeof(struct algo_block);
|
||||||
|
if (avail_blocks < 2) {
|
||||||
|
retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
||||||
|
goto cleanup1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int blocks_to_check = avail_blocks - 1;
|
||||||
if (num_blocks < blocks_to_check)
|
if (num_blocks < blocks_to_check)
|
||||||
blocks_to_check = num_blocks;
|
blocks_to_check = num_blocks;
|
||||||
|
|
||||||
@@ -1019,7 +1026,7 @@ int armv7m_blank_check_memory(struct target *target,
|
|||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
unsigned int i;
|
||||||
uint32_t total_size = 0;
|
uint32_t total_size = 0;
|
||||||
for (i = 0; i < blocks_to_check; i++) {
|
for (i = 0; i < blocks_to_check; i++) {
|
||||||
total_size += blocks[i].size;
|
total_size += blocks[i].size;
|
||||||
@@ -1089,7 +1096,7 @@ int armv7m_blank_check_memory(struct target *target,
|
|||||||
LOG_TARGET_INFO(target, "Slow CPU clock: %d blocks checked, %d remain. Continuing...",
|
LOG_TARGET_INFO(target, "Slow CPU clock: %d blocks checked, %d remain. Continuing...",
|
||||||
i, num_blocks - i);
|
i, num_blocks - i);
|
||||||
|
|
||||||
retval = i; /* return number of blocks really checked */
|
*checked = i; /* return number of blocks really checked */
|
||||||
|
|
||||||
cleanup4:
|
cleanup4:
|
||||||
destroy_reg_param(®_params[0]);
|
destroy_reg_param(®_params[0]);
|
||||||
|
|||||||
@@ -353,7 +353,8 @@ bool armv7m_map_reg_packing(unsigned int arm_reg_id,
|
|||||||
int armv7m_checksum_memory(struct target *target,
|
int armv7m_checksum_memory(struct target *target,
|
||||||
target_addr_t address, uint32_t count, uint32_t *checksum);
|
target_addr_t address, uint32_t count, uint32_t *checksum);
|
||||||
int armv7m_blank_check_memory(struct target *target,
|
int armv7m_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked);
|
||||||
|
|
||||||
int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found);
|
int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found);
|
||||||
|
|
||||||
|
|||||||
@@ -1310,8 +1310,8 @@ int mips32_checksum_memory(struct target *target, target_addr_t address,
|
|||||||
|
|
||||||
/** Checks whether a memory region is erased. */
|
/** Checks whether a memory region is erased. */
|
||||||
int mips32_blank_check_memory(struct target *target,
|
int mips32_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks,
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
uint8_t erased_value)
|
uint8_t erased_value, unsigned int *checked)
|
||||||
{
|
{
|
||||||
struct working_area *erase_check_algorithm;
|
struct working_area *erase_check_algorithm;
|
||||||
struct reg_param reg_params[3];
|
struct reg_param reg_params[3];
|
||||||
@@ -1367,8 +1367,10 @@ int mips32_blank_check_memory(struct target *target,
|
|||||||
retval = target_run_algorithm(target, 0, NULL, 3, reg_params, erase_check_algorithm->address,
|
retval = target_run_algorithm(target, 0, NULL, 3, reg_params, erase_check_algorithm->address,
|
||||||
erase_check_algorithm->address + (sizeof(erase_check_code) - 4), 10000, &mips32_info);
|
erase_check_algorithm->address + (sizeof(erase_check_code) - 4), 10000, &mips32_info);
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
if (retval == ERROR_OK) {
|
||||||
blocks[0].result = buf_get_u32(reg_params[2].value, 0, 32);
|
blocks[0].result = buf_get_u32(reg_params[2].value, 0, 32);
|
||||||
|
*checked = 1; /* only one block has been checked */
|
||||||
|
}
|
||||||
|
|
||||||
destroy_reg_param(®_params[0]);
|
destroy_reg_param(®_params[0]);
|
||||||
destroy_reg_param(®_params[1]);
|
destroy_reg_param(®_params[1]);
|
||||||
@@ -1377,10 +1379,7 @@ int mips32_blank_check_memory(struct target *target,
|
|||||||
cleanup:
|
cleanup:
|
||||||
target_free_working_area(target, erase_check_algorithm);
|
target_free_working_area(target, erase_check_algorithm);
|
||||||
|
|
||||||
if (retval != ERROR_OK)
|
return retval;
|
||||||
return retval;
|
|
||||||
|
|
||||||
return 1; /* only one block has been checked */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mips32_verify_pointer(struct command_invocation *cmd,
|
static int mips32_verify_pointer(struct command_invocation *cmd,
|
||||||
|
|||||||
@@ -933,7 +933,8 @@ int mips32_get_gdb_reg_list(struct target *target,
|
|||||||
int mips32_checksum_memory(struct target *target, target_addr_t address,
|
int mips32_checksum_memory(struct target *target, target_addr_t address,
|
||||||
uint32_t count, uint32_t *checksum);
|
uint32_t count, uint32_t *checksum);
|
||||||
int mips32_blank_check_memory(struct target *target,
|
int mips32_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked);
|
||||||
|
|
||||||
bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info);
|
bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info);
|
||||||
bool mips32_cpu_support_hazard_barrier(struct mips_ejtag *ejtag_info);
|
bool mips32_cpu_support_hazard_barrier(struct mips_ejtag *ejtag_info);
|
||||||
|
|||||||
@@ -1757,7 +1757,8 @@ static int stm8_examine(struct target *target)
|
|||||||
|
|
||||||
/** Checks whether a memory region is erased. */
|
/** Checks whether a memory region is erased. */
|
||||||
static int stm8_blank_check_memory(struct target *target,
|
static int stm8_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
|
uint8_t erased_value, unsigned int *checked)
|
||||||
{
|
{
|
||||||
struct working_area *erase_check_algorithm;
|
struct working_area *erase_check_algorithm;
|
||||||
struct reg_param reg_params[2];
|
struct reg_param reg_params[2];
|
||||||
@@ -1801,8 +1802,10 @@ static int stm8_blank_check_memory(struct target *target,
|
|||||||
erase_check_algorithm->address + (sizeof(stm8_erase_check_code) - 1),
|
erase_check_algorithm->address + (sizeof(stm8_erase_check_code) - 1),
|
||||||
10000, &stm8_info);
|
10000, &stm8_info);
|
||||||
|
|
||||||
if (retval == ERROR_OK)
|
if (retval == ERROR_OK) {
|
||||||
blocks[0].result = (*(reg_params[0].value) == 0xff);
|
blocks[0].result = (*(reg_params[0].value) == 0xff);
|
||||||
|
*checked = 1; /* only one block has been checked */
|
||||||
|
}
|
||||||
|
|
||||||
destroy_mem_param(&mem_params[0]);
|
destroy_mem_param(&mem_params[0]);
|
||||||
destroy_mem_param(&mem_params[1]);
|
destroy_mem_param(&mem_params[1]);
|
||||||
@@ -1811,10 +1814,7 @@ static int stm8_blank_check_memory(struct target *target,
|
|||||||
|
|
||||||
target_free_working_area(target, erase_check_algorithm);
|
target_free_working_area(target, erase_check_algorithm);
|
||||||
|
|
||||||
if (retval != ERROR_OK)
|
return retval;
|
||||||
return retval;
|
|
||||||
|
|
||||||
return 1; /* only one block has been checked */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stm8_checksum_memory(struct target *target, target_addr_t address,
|
static int stm8_checksum_memory(struct target *target, target_addr_t address,
|
||||||
|
|||||||
@@ -2513,8 +2513,8 @@ int target_checksum_memory(struct target *target, target_addr_t address, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
int target_blank_check_memory(struct target *target,
|
int target_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks,
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
uint8_t erased_value)
|
uint8_t erased_value, unsigned int *checked)
|
||||||
{
|
{
|
||||||
if (!target_was_examined(target)) {
|
if (!target_was_examined(target)) {
|
||||||
LOG_ERROR("Target not examined yet");
|
LOG_ERROR("Target not examined yet");
|
||||||
@@ -2524,7 +2524,8 @@ int target_blank_check_memory(struct target *target,
|
|||||||
if (!target->type->blank_check_memory)
|
if (!target->type->blank_check_memory)
|
||||||
return ERROR_NOT_IMPLEMENTED;
|
return ERROR_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
return target->type->blank_check_memory(target, blocks, num_blocks, erased_value);
|
return target->type->blank_check_memory(target, blocks, num_blocks,
|
||||||
|
erased_value, checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
int target_read_u64(struct target *target, target_addr_t address, uint64_t *value)
|
int target_read_u64(struct target *target, target_addr_t address, uint64_t *value)
|
||||||
|
|||||||
@@ -662,8 +662,8 @@ int target_read_buffer(struct target *target,
|
|||||||
int target_checksum_memory(struct target *target,
|
int target_checksum_memory(struct target *target,
|
||||||
target_addr_t address, uint32_t size, uint32_t *crc);
|
target_addr_t address, uint32_t size, uint32_t *crc);
|
||||||
int target_blank_check_memory(struct target *target,
|
int target_blank_check_memory(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks,
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
uint8_t erased_value);
|
uint8_t erased_value, unsigned int *checked);
|
||||||
int target_wait_state(struct target *target, enum target_state state, unsigned int ms);
|
int target_wait_state(struct target *target, enum target_state state, unsigned int ms);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ struct target_type {
|
|||||||
int (*checksum_memory)(struct target *target, target_addr_t address,
|
int (*checksum_memory)(struct target *target, target_addr_t address,
|
||||||
uint32_t count, uint32_t *checksum);
|
uint32_t count, uint32_t *checksum);
|
||||||
int (*blank_check_memory)(struct target *target,
|
int (*blank_check_memory)(struct target *target,
|
||||||
struct target_memory_check_block *blocks, int num_blocks,
|
struct target_memory_check_block *blocks, unsigned int num_blocks,
|
||||||
uint8_t erased_value);
|
uint8_t erased_value, unsigned int *checked);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* target break-/watchpoint control
|
* target break-/watchpoint control
|
||||||
|
|||||||
Reference in New Issue
Block a user