This is an automated email from Gerrit. "Antonio Borneo <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9658
-- gerrit commit 6bcb41e20db2fcc63462befc945a8e555091ffa4 Author: Antonio Borneo <[email protected]> Date: Fri May 15 12:21:11 2026 +0200 target: riscv: drop use of type time_t This is the only code in OpenOCD that directly uses time_t. This type assumes different size and sign depending on the host OS and should not be used directly. Replace it by using the OpenOCD helper timeval_ms(). Change-Id: I667f5361d8da5fdda96fef295e706136066ea1f8 Signed-off-by: Antonio Borneo <[email protected]> diff --git a/src/target/riscv/riscv-011.c b/src/target/riscv/riscv-011.c index 2bef2228e1..1e913aa658 100644 --- a/src/target/riscv/riscv-011.c +++ b/src/target/riscv/riscv-011.c @@ -7,7 +7,6 @@ #include <assert.h> #include <stdlib.h> -#include <time.h> #ifdef HAVE_CONFIG_H #include "config.h" @@ -724,7 +723,7 @@ static int read_bits(struct target *target, bits_t *result) static int wait_for_debugint_clear(struct target *target, bool ignore_first) { - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); if (ignore_first) { /* Throw away the results of the first read, since they'll contain the * result of the read that happened just before debugint was set. @@ -742,7 +741,7 @@ static int wait_for_debugint_clear(struct target *target, bool ignore_first) if (!bits.interrupt) return ERROR_OK; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_ERROR("Timed out waiting for debug int to clear." "Increase timeout with riscv set_command_timeout_sec."); return ERROR_FAIL; @@ -1022,14 +1021,14 @@ static void dram_write_jump(struct target *target, unsigned int index, static int wait_for_state(struct target *target, enum target_state state) { - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); while (1) { int result = riscv011_poll(target); if (result != ERROR_OK) return result; if (target->state == state) return ERROR_OK; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_ERROR("Timed out waiting for state %d. " "Increase timeout with riscv set_command_timeout_sec.", state); return ERROR_FAIL; @@ -1189,14 +1188,14 @@ static int full_step(struct target *target, bool announce) int result = execute_resume(target, true); if (result != ERROR_OK) return result; - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); while (1) { result = poll_target(target, announce); if (result != ERROR_OK) return result; if (target->state != TARGET_DEBUG_RUNNING) break; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_ERROR("Timed out waiting for step to complete." "Increase timeout with riscv set_command_timeout_sec"); return ERROR_FAIL; @@ -2374,12 +2373,12 @@ static COMMAND_HELPER(riscv011_print_info, struct target *target) static int wait_for_authbusy(struct target *target) { - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); while (1) { uint32_t dminfo = dbus_read(target, DMINFO); if (!get_field(dminfo, DMINFO_AUTHBUSY)) break; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_ERROR("Timed out after %ds waiting for authbusy to go low (dminfo=0x%x). " "Increase the timeout with riscv set_command_timeout_sec.", riscv_get_command_timeout_sec(), diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 50e0f83dd8..b2176e9188 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -8,7 +8,6 @@ #include <assert.h> #include <stdint.h> #include <stdlib.h> -#include <time.h> #ifdef HAVE_CONFIG_H #include "config.h" @@ -624,7 +623,7 @@ static int wait_for_idle(struct target *target, uint32_t *abstractcs) return ERROR_FAIL; } - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); do { if (dm_read(target, abstractcs, DM_ABSTRACTCS) != ERROR_OK) { /* We couldn't read abstractcs. For safety, overwrite the output value to @@ -639,7 +638,7 @@ static int wait_for_idle(struct target *target, uint32_t *abstractcs) dm->abstract_cmd_maybe_busy = false; return ERROR_OK; } - } while ((time(NULL) - start) < riscv_get_command_timeout_sec()); + } while (timeval_ms() < then); LOG_TARGET_ERROR(target, "Timed out after %ds waiting for busy to go low (abstractcs=0x%" PRIx32 "). " @@ -1660,7 +1659,7 @@ static int register_read_direct(struct target *target, riscv_reg_t *value, static int wait_for_authbusy(struct target *target, uint32_t *dmstatus) { - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); while (1) { uint32_t value; if (dmstatus_read(target, &value, false) != ERROR_OK) @@ -1669,7 +1668,7 @@ static int wait_for_authbusy(struct target *target, uint32_t *dmstatus) *dmstatus = value; if (!get_field(value, DM_DMSTATUS_AUTHBUSY)) break; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_TARGET_ERROR(target, "Timed out after %ds waiting for authbusy to go low (dmstatus=0x%x). " "Increase the timeout with riscv set_command_timeout_sec.", riscv_get_command_timeout_sec(), @@ -1859,14 +1858,14 @@ static int reset_dm(struct target *target) if (result != ERROR_OK) return result; - const time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); LOG_TARGET_DEBUG(target, "Waiting for the DM to acknowledge reset."); do { result = dm_read(target, &dmcontrol, DM_DMCONTROL); if (result != ERROR_OK) return result; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_TARGET_ERROR(target, "DM didn't acknowledge reset in %d s. " "Increase the timeout with 'riscv set_command_timeout_sec'.", riscv_get_command_timeout_sec()); @@ -1881,14 +1880,14 @@ static int reset_dm(struct target *target) if (result != ERROR_OK) return result; - const time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); LOG_TARGET_DEBUG(target, "Waiting for the DM to come out of reset."); do { result = dm_read(target, &dmcontrol, DM_DMCONTROL); if (result != ERROR_OK) return result; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_TARGET_ERROR(target, "Debug Module did not become active in %d s. " "Increase the timeout with 'riscv set_command_timeout_sec'.", riscv_get_command_timeout_sec()); @@ -2542,7 +2541,7 @@ static int batch_run_timeout(struct target *target, struct riscv_batch *batch) riscv_batch_add_nop(batch); size_t finished_scans = 0; - const time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); const unsigned int old_base_delay = riscv_scan_get_delay(&info->learned_delays, RISCV_DELAY_BASE); int result; @@ -2565,7 +2564,7 @@ static int batch_run_timeout(struct target *target, struct riscv_batch *batch) result = increase_dmi_busy_delay(target); if (result != ERROR_OK) return result; - } while (time(NULL) - start < riscv_get_command_timeout_sec()); + } while (timeval_ms() < then); assert(result == ERROR_OK); assert(riscv_batch_was_batch_busy(batch)); @@ -2985,14 +2984,14 @@ static int deassert_reset(struct target *target) uint32_t dmstatus; const unsigned int orig_base_delay = riscv_scan_get_delay(&info->learned_delays, RISCV_DELAY_BASE); - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); LOG_TARGET_DEBUG(target, "Waiting for hart to come out of reset."); do { result = dmstatus_read(target, &dmstatus, true); if (result != ERROR_OK) return result; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_TARGET_ERROR(target, "Hart didn't leave reset in %ds; " "dmstatus=0x%x (allunavail=%s, allhavereset=%s); " "Increase the timeout with riscv set_command_timeout_sec.", @@ -3178,13 +3177,13 @@ static target_addr_t sb_read_address(struct target *target) static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs) { - time_t start = time(NULL); + int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec(); while (1) { if (dm_read(target, sbcs, DM_SBCS) != ERROR_OK) return ERROR_FAIL; if (!get_field(*sbcs, DM_SBCS_SBBUSY)) return ERROR_OK; - if (time(NULL) - start > riscv_get_command_timeout_sec()) { + if (timeval_ms() > then) { LOG_TARGET_ERROR(target, "Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). " "Increase the timeout with riscv set_command_timeout_sec.", riscv_get_command_timeout_sec(), *sbcs); --
