This is an automated email from Gerrit. "Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8032
-- gerrit commit c707117ae08dbd02e88553b60cbb2fd580838ff8 Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com> Date: Wed Nov 22 18:10:27 2023 +0300 check if shutdown is requested on keep_alive() This allows to respond to a signal requesting a shutdown during some loops which do not return controll to main OpenOCD loop. Change-Id: Iace0b58eddde1237832d0f9333a7c7b930565674 Signed-off-by: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com> diff --git a/src/server/server.c b/src/server/server.c index 2be90451f7..76bd2767cf 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -752,6 +752,11 @@ bool openocd_is_shutdown_pending(void) return shutdown_openocd != CONTINUE_MAIN_LOOP; } +bool openocd_shutdown_by_signal(void) +{ + return shutdown_openocd == SHUTDOWN_WITH_SIGNAL_CODE; +} + /* tell the server we want to shut down */ COMMAND_HANDLER(handle_shutdown_command) { diff --git a/src/server/server.h b/src/server/server.h index c9d4698af8..bf38c73f1c 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -106,6 +106,8 @@ int connection_read(struct connection *connection, void *data, int len); bool openocd_is_shutdown_pending(void); +bool openocd_shutdown_by_signal(void); + /** * Defines an extended command handler function declaration to enable * access to (and manipulation of) the server port number. diff --git a/src/target/image.c b/src/target/image.c index 9175c200af..4c066811a4 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -24,6 +24,7 @@ #include "image.h" #include "target.h" #include <helper/log.h> +#include <server/server.h> /* convert ELF header field to host endianness */ #define field16(elf, field) \ @@ -1295,6 +1296,8 @@ int image_calculate_checksum(const uint8_t *buffer, uint32_t nbytes, uint32_t *c crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buffer++) & 255]; } keep_alive(); + if (openocd_shutdown_by_signal()) + return ERROR_FAIL; } LOG_DEBUG("Calculating checksum done; checksum=0x%" PRIx32, crc); diff --git a/src/target/target.c b/src/target/target.c index 4a4c62613f..26b8eff3c1 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1049,6 +1049,10 @@ int target_run_flash_async_algorithm(struct target *target, /* Avoid GDB timeouts */ keep_alive(); + if (openocd_shutdown_by_signal()) { + retval = ERROR_FAIL; + break; + } } if (retval != ERROR_OK) { @@ -1198,6 +1202,10 @@ int target_run_read_async_algorithm(struct target *target, /* Avoid GDB timeouts */ keep_alive(); + if (openocd_shutdown_by_signal()) { + retval = ERROR_FAIL; + break; + } } @@ -1833,6 +1841,8 @@ static int target_call_timer_callbacks_check_time(int checktime) callback_processing = true; keep_alive(); + if (openocd_shutdown_by_signal()) + return ERROR_FAIL; int64_t now = timeval_ms(); @@ -3219,8 +3229,11 @@ int target_wait_state(struct target *target, enum target_state state, unsigned i nvp_value2name(nvp_target_state, state)->name); } - if (cur-then > 500) + if (cur-then > 500) { keep_alive(); + if (openocd_shutdown_by_signal()) + return ERROR_FAIL; + } if ((cur-then) > ms) { LOG_ERROR("timed out while waiting for target %s", @@ -3502,6 +3515,10 @@ static int target_fill_mem(struct target *target, break; /* avoid GDB timeouts */ keep_alive(); + if (openocd_shutdown_by_signal()) { + retval = ERROR_FAIL; + break; + } } free(target_buf); @@ -3844,6 +3861,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver } } keep_alive(); + if (openocd_shutdown_by_signal()) { + retval = ERROR_FAIL; + free(data); + free(buffer); + goto done; + } } } free(data); --