flash/nor: Add erased_value to drivers and pass it to targets

struct flash_driver has a default_padded_value field that is similar,
but it can be changed by the user for the specific purpose of padding.

Add a new erased_value field and initialize it for all targets,
particularly stm32lx, xmc4xxx and virtual.

Use this value in core.c:default_flash_mem_blank_check(), the slow path.

Extend the target API to pass erased_value down to target code.
Adding an argument ensures that we catch all callers.

This allows us to merge xmc4xxx.c:xmc4xxx_blank_check_memory() into
armv7m:armv7m_blank_check_memory().

It further allows us to use default_flash_blank_check() in place of
xmc4xxx.c:xmc4xxx_flash_blank_check(), adding a potential slow path
fallback, as well as stm32lx:stm32lx_erase_check(), adding the potential
armv7m fast path with fallback to default_flash_mem_blank_check().

Fix a mips32 code comment while at it (zeroed -> erased).

The armv4_5 and mips32 target implementations will now error out if an
erase value other than 0xff is used, causing default_flash_blank_check()
to fall back to the default_flank_mem_blank_check() slow path.

Change-Id: I39323fbbc4b71c256cd567e439896d0245d4745f
Signed-off-by: Andreas Färber <afaerber@suse.de>
Reviewed-on: http://openocd.zylin.com/3497
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
Andreas Färber
2016-05-08 23:49:07 +02:00
committed by Andreas Fritiofson
parent b9ee6dd465
commit eaacb900dd
16 changed files with 61 additions and 171 deletions

View File

@@ -726,26 +726,42 @@ cleanup:
return retval;
}
/** Checks whether a memory region is zeroed. */
/** Checks whether a memory region is erased. */
int armv7m_blank_check_memory(struct target *target,
uint32_t address, uint32_t count, uint32_t *blank)
uint32_t address, uint32_t count, uint32_t *blank, uint8_t erased_value)
{
struct working_area *erase_check_algorithm;
struct reg_param reg_params[3];
struct armv7m_algorithm armv7m_info;
const uint8_t *code;
uint32_t code_size;
int retval;
static const uint8_t erase_check_code[] = {
#include "../../contrib/loaders/erase_check/armv7m_erase_check.inc"
};
static const uint8_t zero_erase_check_code[] = {
#include "../../contrib/loaders/erase_check/armv7m_0_erase_check.inc"
};
switch (erased_value) {
case 0x00:
code = zero_erase_check_code;
code_size = sizeof(zero_erase_check_code);
break;
case 0xff:
default:
code = erase_check_code;
code_size = sizeof(erase_check_code);
}
/* make sure we have a working area */
if (target_alloc_working_area(target, sizeof(erase_check_code),
if (target_alloc_working_area(target, code_size,
&erase_check_algorithm) != ERROR_OK)
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
retval = target_write_buffer(target, erase_check_algorithm->address,
sizeof(erase_check_code), (uint8_t *)erase_check_code);
code_size, code);
if (retval != ERROR_OK)
goto cleanup;
@@ -759,7 +775,7 @@ int armv7m_blank_check_memory(struct target *target,
buf_set_u32(reg_params[1].value, 0, 32, count);
init_reg_param(&reg_params[2], "r2", 32, PARAM_IN_OUT);
buf_set_u32(reg_params[2].value, 0, 32, 0xff);
buf_set_u32(reg_params[2].value, 0, 32, erased_value);
retval = target_run_algorithm(target,
0,
@@ -767,7 +783,7 @@ int armv7m_blank_check_memory(struct target *target,
3,
reg_params,
erase_check_algorithm->address,
erase_check_algorithm->address + (sizeof(erase_check_code) - 2),
erase_check_algorithm->address + (code_size - 2),
10000,
&armv7m_info);