flash/nor/rp2040: check target halted before flash operation

Flash read_id/erase/write operation on running target failed
in target_run_algorithm() anyway. It generated lot of error messages.

Check the target state and bail out early if target is running.

Change-Id: I903f5f38c8e61016e5002b235e5f07803bd2ec4e
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/7215
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Jonathan Bell <jonathan@raspberrypi.com>
This commit is contained in:
Tomas Vanek 2022-09-21 07:46:15 +02:00
parent 53611d8055
commit 931b357466
1 changed files with 19 additions and 1 deletions

View File

@ -211,6 +211,12 @@ static int rp2040_flash_write(struct flash_bank *bank, const uint8_t *buffer, ui
struct rp2040_flash_bank *priv = bank->driver_priv;
struct target *target = bank->target;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
struct working_area *bounce = NULL;
int err = rp2040_stack_grab_and_prep(bank);
@ -266,6 +272,13 @@ cleanup:
static int rp2040_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
{
struct rp2040_flash_bank *priv = bank->driver_priv;
struct target *target = bank->target;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
uint32_t start_addr = bank->sectors[first].offset;
uint32_t length = bank->sectors[last].offset + bank->sectors[last].size - start_addr;
LOG_DEBUG("RP2040 erase %d bytes starting at 0x%" PRIx32, length, start_addr);
@ -294,7 +307,7 @@ static int rp2040_flash_erase(struct flash_bank *bank, unsigned int first, unsig
*/
int timeout_ms = 2000 * (last - first) + 1000;
err = rp2040_call_rom_func(bank->target, priv, priv->jump_flash_range_erase,
err = rp2040_call_rom_func(target, priv, priv->jump_flash_range_erase,
args, ARRAY_SIZE(args), timeout_ms);
cleanup:
@ -362,6 +375,11 @@ static int rp2040_flash_probe(struct flash_bank *bank)
struct rp2040_flash_bank *priv = bank->driver_priv;
struct target *target = bank->target;
if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}
int err = rp2040_lookup_symbol(target, FUNC_DEBUG_TRAMPOLINE, &priv->jump_debug_trampoline);
if (err != ERROR_OK) {
LOG_ERROR("Debug trampoline not found in RP2040 ROM.");