This is an automated email from Gerrit.

"Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/7215

-- gerrit

commit 4a92643640df02892138b82f2f748b0147ae2184
Author: Tomas Vanek <van...@fbl.cz>
Date:   Wed Sep 21 07:46:15 2022 +0200

    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 <van...@fbl.cz>

diff --git a/src/flash/nor/rp2040.c b/src/flash/nor/rp2040.c
index 7cc6434ffe..f131a30397 100644
--- a/src/flash/nor/rp2040.c
+++ b/src/flash/nor/rp2040.c
@@ -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.");

-- 

Reply via email to