flash/nor/psoc5lp: fix bad commit 2d5f2ede55

Change #3432 was merged into git master without adapting it
to #4297 "prepare infrastructure for multi-block blank check".
This is a fast fix of PSoC5LP specific blank check.
Not tested on real PSoC5LP device.

Change-Id: I7dc13ee7bd1f07b2bfe5a93a5030c0c482d30f00
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4557
Tested-by: jenkins
riscv-compliance
Tomas Vanek 2018-06-06 17:53:32 +02:00
parent fb287ec5f5
commit 53376dbbed
1 changed files with 44 additions and 32 deletions

View File

@ -798,47 +798,59 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
{ {
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv; struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
uint32_t blank; int i, retval;
int i, num_sectors, retval;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
num_sectors = bank->num_sectors; struct target_memory_check_block *block_array;
if (!psoc_bank->ecc_enabled) block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block));
num_sectors /= 2; if (block_array == NULL)
return ERROR_FAIL;
for (i = 0; i < num_sectors; i++) { for (i = 0; i < bank->num_sectors; i++) {
uint32_t address = bank->base + bank->sectors[i].offset; block_array[i].address = bank->base + bank->sectors[i].offset;
uint32_t size = bank->sectors[i].size; block_array[i].size = bank->sectors[i].size;
block_array[i].result = UINT32_MAX; /* erase state unknown */
retval = armv7m_blank_check_memory(target, address, size,
&blank, bank->erased_value);
if (retval != ERROR_OK)
return retval;
if (blank == 0x00 && !psoc_bank->ecc_enabled) {
address = bank->base + bank->sectors[num_sectors + i].offset;
size = bank->sectors[num_sectors + i].size;
retval = armv7m_blank_check_memory(target, address, size,
&blank, bank->erased_value);
if (retval != ERROR_OK)
return retval;
}
if (blank == 0x00) {
bank->sectors[i].is_erased = 1;
bank->sectors[num_sectors + i].is_erased = 1;
} else {
bank->sectors[i].is_erased = 0;
bank->sectors[num_sectors + i].is_erased = 0;
}
} }
return ERROR_OK; bool fast_check = true;
for (i = 0; i < bank->num_sectors; ) {
retval = armv7m_blank_check_memory(target,
block_array + i, bank->num_sectors - i,
bank->erased_value);
if (retval < 1) {
/* 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 */
}
if (fast_check) {
if (!psoc_bank->ecc_enabled) {
int half_sectors = bank->num_sectors / 2;
for (i = 0; i < half_sectors / 2; i++)
bank->sectors[i].is_erased =
(block_array[i].result != 1)
? block_array[i + half_sectors].result
: block_array[i].result;
} else {
for (i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = block_array[i].result;
}
retval = ERROR_OK;
} else {
LOG_ERROR("Can't run erase check - add working memory");
retval = ERROR_FAIL;
}
free(block_array);
return retval;
} }
static int psoc5lp_write(struct flash_bank *bank, const uint8_t *buffer, static int psoc5lp_write(struct flash_bank *bank, const uint8_t *buffer,