From 5c2c269336cc49aa3ea7714d0ffcc4b2edf3057e Mon Sep 17 00:00:00 2001 From: Spencer Oliver Date: Mon, 5 Nov 2012 13:04:15 +0000 Subject: [PATCH] target: add async algorithm timeout An issue was observed when using an async algorithm with a target that had not been previously reset beforehand. The target would enter a infinite loop within target_run_flash_async_algorithm. Add a timeout that will at least prevent this issue from happening. and also suggest the user resets the target. Change-Id: I5277e0d64e252d3d353e8d5bc9889a37fdc63060 Signed-off-by: Spencer Oliver Reviewed-on: http://openocd.zylin.com/949 Tested-by: jenkins Reviewed-by: Andreas Fritiofson --- src/target/target.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/target/target.c b/src/target/target.c index b8e4c2ff9e..6d3a99decd 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -822,6 +822,7 @@ int target_run_flash_async_algorithm(struct target *target, uint32_t entry_point, uint32_t exit_point, void *arch_info) { int retval; + int timeout = 0; /* Set up working area. First word is write pointer, second word is read pointer, * rest is fifo data area. */ @@ -893,9 +894,19 @@ int target_run_flash_async_algorithm(struct target *target, * less than buffer size / flash speed. This is very unlikely to * run when using high latency connections such as USB. */ alive_sleep(10); + + /* to stop an infinite loop on some targets check and increment a timeout + * this issue was observed on a stellaris using the new ICDI interface */ + if (timeout++ >= 500) { + LOG_ERROR("timeout waiting for algorithm, a target reset is recommended"); + return ERROR_FLASH_OPERATION_FAILED; + } continue; } + /* reset our timeout */ + timeout = 0; + /* Limit to the amount of data we actually want to write */ if (thisrun_bytes > count * block_size) thisrun_bytes = count * block_size; -- 2.30.2