diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/flash/nor/cc26xx.c | 7 | ||||
-rw-r--r-- | src/flash/nor/cfi.c | 4 | ||||
-rw-r--r-- | src/flash/nor/fespi.c | 6 | ||||
-rw-r--r-- | src/flash/nor/msp432.c | 5 | ||||
-rw-r--r-- | src/flash/nor/npcx.c | 6 | ||||
-rw-r--r-- | src/flash/nor/psoc6.c | 6 | ||||
-rw-r--r-- | src/flash/nor/sh_qspi.c | 11 | ||||
-rw-r--r-- | src/target/riscv/riscv-013.c | 5 | ||||
-rw-r--r-- | src/target/target.c | 13 | ||||
-rw-r--r-- | src/target/target.h | 7 |
10 files changed, 35 insertions, 35 deletions
diff --git a/src/flash/nor/cc26xx.c b/src/flash/nor/cc26xx.c index f6b5632..7e52649 100644 --- a/src/flash/nor/cc26xx.c +++ b/src/flash/nor/cc26xx.c @@ -140,8 +140,9 @@ static int cc26xx_init(struct flash_bank *bank) return retval; /* Check for working area to use for flash helper algorithm */ - if (cc26xx_bank->working_area) - target_free_working_area(target, cc26xx_bank->working_area); + target_free_working_area(target, cc26xx_bank->working_area); + cc26xx_bank->working_area = NULL; + retval = target_alloc_working_area(target, cc26xx_bank->algo_working_size, &cc26xx_bank->working_area); if (retval != ERROR_OK) @@ -158,6 +159,7 @@ static int cc26xx_init(struct flash_bank *bank) LOG_ERROR("%s: Failed to load flash helper algorithm", cc26xx_bank->family_name); target_free_working_area(target, cc26xx_bank->working_area); + cc26xx_bank->working_area = NULL; return retval; } @@ -172,6 +174,7 @@ static int cc26xx_init(struct flash_bank *bank) LOG_ERROR("%s: Failed to start flash helper algorithm", cc26xx_bank->family_name); target_free_working_area(target, cc26xx_bank->working_area); + cc26xx_bank->working_area = NULL; return retval; } diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index e3fb6c8..8511586 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -1359,9 +1359,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer, /* free up resources */ cleanup: - if (source) - target_free_working_area(target, source); - + target_free_working_area(target, source); target_free_working_area(target, write_algorithm); destroy_reg_param(®_params[0]); diff --git a/src/flash/nor/fespi.c b/src/flash/nor/fespi.c index 11da818..5474ffa 100644 --- a/src/flash/nor/fespi.c +++ b/src/flash/nor/fespi.c @@ -661,10 +661,8 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer, return ERROR_OK; err: - if (algorithm_wa) { - target_free_working_area(target, data_wa); - target_free_working_area(target, algorithm_wa); - } + target_free_working_area(target, data_wa); + target_free_working_area(target, algorithm_wa); /* Switch to HW mode before return to prompt */ if (fespi_enable_hw_mode(bank) != ERROR_OK) diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c index 667349f..61741c8 100644 --- a/src/flash/nor/msp432.c +++ b/src/flash/nor/msp432.c @@ -335,8 +335,9 @@ static int msp432_init(struct flash_bank *bank) } /* Check for working area to use for flash helper algorithm */ - if (msp432_bank->working_area) - target_free_working_area(target, msp432_bank->working_area); + target_free_working_area(target, msp432_bank->working_area); + msp432_bank->working_area = NULL; + retval = target_alloc_working_area(target, ALGO_WORKING_SIZE, &msp432_bank->working_area); if (retval != ERROR_OK) diff --git a/src/flash/nor/npcx.c b/src/flash/nor/npcx.c index af623e5..a4d6395 100644 --- a/src/flash/nor/npcx.c +++ b/src/flash/nor/npcx.c @@ -80,10 +80,8 @@ static int npcx_init(struct flash_bank *bank) struct npcx_flash_bank *npcx_bank = bank->driver_priv; /* Check for working area to use for flash helper algorithm */ - if (npcx_bank->working_area) { - target_free_working_area(target, npcx_bank->working_area); - npcx_bank->working_area = NULL; - } + target_free_working_area(target, npcx_bank->working_area); + npcx_bank->working_area = NULL; int retval = target_alloc_working_area(target, npcx_bank->algo_working_size, &npcx_bank->working_area); diff --git a/src/flash/nor/psoc6.c b/src/flash/nor/psoc6.c index 198dff5..c6166af 100644 --- a/src/flash/nor/psoc6.c +++ b/src/flash/nor/psoc6.c @@ -182,10 +182,8 @@ destroy_rp_free_wa: /* Something went wrong, do some cleanup */ destroy_reg_param(®_params); - if (g_stack_area) { - target_free_working_area(target, g_stack_area); - g_stack_area = NULL; - } + target_free_working_area(target, g_stack_area); + g_stack_area = NULL; return hr; } diff --git a/src/flash/nor/sh_qspi.c b/src/flash/nor/sh_qspi.c index a159844..02af17a 100644 --- a/src/flash/nor/sh_qspi.c +++ b/src/flash/nor/sh_qspi.c @@ -703,11 +703,14 @@ static int sh_qspi_upload_helper(struct flash_bank *bank) }; int ret; - if (info->source) - target_free_working_area(target, info->source); - if (info->io_algorithm) - target_free_working_area(target, info->io_algorithm); + target_free_working_area(target, info->source); + target_free_working_area(target, info->io_algorithm); + /* FIXME: Working areas are allocated during flash probe + * and eventual target_free_all_working_areas() called in case + * of target reset or run is not handled at all. + * Not a big problem if area backp is off. + */ /* flash write code */ if (target_alloc_working_area(target, sizeof(sh_qspi_io_code), &info->io_algorithm) != ERROR_OK) { diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 006266a..7af4602 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1199,10 +1199,7 @@ static int scratch_reserve(struct target *target, static int scratch_release(struct target *target, scratch_mem_t *scratch) { - if (scratch->area) - return target_free_working_area(target, scratch->area); - - return ERROR_OK; + return target_free_working_area(target, scratch->area); } static int scratch_read64(struct target *target, scratch_mem_t *scratch, diff --git a/src/target/target.c b/src/target/target.c index ed6f655..27888a8 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2148,11 +2148,10 @@ static int target_restore_working_area(struct target *target, struct working_are /* Restore the area's backup memory, if any, and return the area to the allocation pool */ static int target_free_working_area_restore(struct target *target, struct working_area *area, int restore) { - int retval = ERROR_OK; - - if (area->free) - return retval; + if (!area || area->free) + return ERROR_OK; + int retval = ERROR_OK; if (restore) { retval = target_restore_working_area(target, area); /* REVISIT: Perhaps the area should be freed even if restoring fails. */ @@ -6401,8 +6400,7 @@ next: out: free(test_pattern); - if (wa) - target_free_working_area(target, wa); + target_free_working_area(target, wa); /* Test writes */ num_bytes = test_size + 4 + 4 + 4; @@ -6486,8 +6484,7 @@ nextw: free(test_pattern); - if (wa) - target_free_working_area(target, wa); + target_free_working_area(target, wa); return retval; } diff --git a/src/target/target.h b/src/target/target.h index 99ec2be..6ef8f10 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -726,6 +726,13 @@ int target_alloc_working_area(struct target *target, */ int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area); +/** + * Free a working area. + * Restore target data if area backup is configured. + * @param target + * @param area Pointer to the area to be freed or NULL + * @returns ERROR_OK if successful; error code if restore failed + */ int target_free_working_area(struct target *target, struct working_area *area); void target_free_all_working_areas(struct target *target); uint32_t target_get_working_area_avail(struct target *target); |