This is an automated email from Gerrit. "Ahmed Haoues <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9530
-- gerrit commit 96c499a4a7caa43ed6ec2c3130073aefdd8972df Author: HAOUES Ahmed <[email protected]> Date: Thu Jul 17 09:00:26 2025 +0100 flash/bluenrg-x: fix working area buffer size calculation Adjust buffer_size to use available working area minus 128 bytes reserved for write_algorithm_stack. Ensure buffer_size is aligned to FLASH_DATA_WIDTH boundary. Add checks to handle insufficient working area (<256 bytes) with a warning and resource cleanup. Cap buffer_size at 16384 bytes to avoid diminishing returns on larger buffers. Change-Id: I428a5de1bb6b1c3af0cba41e9a50278c45a1c54c Signed-off-by: HAOUES Ahmed <[email protected]> diff --git a/src/flash/nor/bluenrg-x.c b/src/flash/nor/bluenrg-x.c index caf659effe..6aebdcb31e 100644 --- a/src/flash/nor/bluenrg-x.c +++ b/src/flash/nor/bluenrg-x.c @@ -273,7 +273,6 @@ static int bluenrgx_write_with_loader(struct flash_bank *bank, const uint8_t *bu { struct bluenrgx_flash_bank *bluenrgx_info = bank->driver_priv; struct target *target = bank->target; - uint32_t buffer_size = 16384 + 8; struct working_area *write_algorithm; struct working_area *write_algorithm_stack; struct working_area *source; @@ -302,6 +301,20 @@ static int bluenrgx_write_with_loader(struct flash_bank *bank, const uint8_t *bu if (retval != ERROR_OK) return retval; + /* write_algorithm_stack area size 128 */ + uint32_t buffer_size = target_get_working_area_avail(target) - 128; + /* buffer size should be multiple of FLASH_DATA_WIDTH*/ + buffer_size &= ~(FLASH_DATA_WIDTH - 1); + + if (buffer_size < 256) { + LOG_WARNING("large enough working area not available, can't do block memory writes"); + target_free_working_area(target, write_algorithm); + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } else if (buffer_size > 16384) { + /* probably won't benefit from more than 16k ... */ + buffer_size = 16384; + } + /* memory buffer */ if (target_alloc_working_area(target, buffer_size, &source)) { LOG_WARNING("no large enough working area available"); --
