|
From: openocd-gerrit <ope...@us...> - 2026-07-04 17:45:06
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 9cf28dcab9a1b91606db6061ab6b4152f761e173 (commit)
from ef5ac7aef3d11dfe806b9bdd88a2770febdaefa3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9cf28dcab9a1b91606db6061ab6b4152f761e173
Author: liangzhen <zhe...@sp...>
Date: Tue May 6 14:15:56 2025 +0800
target/riscv: activate dm before get nextdm
when Debug Module is inactive, accesses to the nextdm may fail.
Specifically, nextdm might not return correct data.
Change-Id: Ib19ece315af6e0c4a066f79c0270c119398c3606
Signed-off-by: liangzhen <zhe...@sp...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9221
Reviewed-by: Evgeniy Naydanov <eu...@gm...>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index a87e3f97b..b4664d2a7 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -531,7 +531,32 @@ static int dm_write(struct target *target, uint32_t address, uint32_t value)
return dmi_write(target, riscv013_get_dmi_address(target, address), value);
}
-static bool check_dbgbase_exists(struct target *target)
+static int activate_dm(struct target *target, uint32_t dm_base_addr)
+{
+ LOG_TARGET_DEBUG(target, "Activating the DM with DMI base address (dbgbase) = 0x%x", dm_base_addr);
+ if (dmi_write(target, DM_DMCONTROL + dm_base_addr, DM_DMCONTROL_DMACTIVE) != ERROR_OK)
+ return ERROR_FAIL;
+
+ int64_t then = timeval_ms() + 1000 * riscv_get_command_timeout_sec();
+ LOG_TARGET_DEBUG(target, "Waiting for the DM to become active");
+ while (1) {
+ uint32_t dmcontrol;
+ if (dmi_read(target, &dmcontrol, DM_DMCONTROL + dm_base_addr) != ERROR_OK)
+ return ERROR_FAIL;
+ if (get_field32(dmcontrol, DM_DMCONTROL_DMACTIVE))
+ break;
+ if (timeval_ms() > then) {
+ LOG_TARGET_ERROR(target, "Debug Module (at address dbgbase=0x%" PRIx32 ") did not become active in %d s. "
+ "Increase the timeout with 'riscv set_command_timeout_sec'",
+ dm_base_addr, riscv_get_command_timeout_sec());
+ return ERROR_TIMEOUT_REACHED;
+ }
+ }
+ LOG_TARGET_DEBUG(target, "DM has become active");
+ return ERROR_OK;
+}
+
+static int check_dbgbase_exists(struct target *target)
{
uint32_t next_dm = 0;
unsigned int count = 1;
@@ -541,7 +566,14 @@ static bool check_dbgbase_exists(struct target *target)
while (1) {
uint32_t current_dm = next_dm;
if (current_dm == target->dbgbase)
- return true;
+ return ERROR_OK;
+
+ uint32_t dmcontrol;
+ if (dmi_read(target, &dmcontrol, DM_DMCONTROL + current_dm) != ERROR_OK)
+ break;
+ if (!get_field32(dmcontrol, DM_DMCONTROL_DMACTIVE) && activate_dm(target, current_dm) != ERROR_OK)
+ break;
+
if (dmi_read(target, &next_dm, DM_NEXTDM + current_dm) != ERROR_OK)
break;
LOG_TARGET_DEBUG(target, "dm @ 0x%x --> nextdm=0x%x", current_dm, next_dm);
@@ -562,7 +594,7 @@ static bool check_dbgbase_exists(struct target *target)
break;
}
}
- return false;
+ return ERROR_FAIL;
}
static int dmstatus_read(struct target *target, uint32_t *dmstatus,
@@ -1890,27 +1922,13 @@ static int reset_dm(struct target *target)
} while (get_field32(dmcontrol, DM_DMCONTROL_DMACTIVE));
LOG_TARGET_DEBUG(target, "DM reset initiated.");
}
+ /* TODO: Move the code above into `deactivate_dm()` function
+ * (a logical counterpart to activate_dm()). */
- LOG_TARGET_DEBUG(target, "Activating the DM.");
- result = dm_write(target, DM_DMCONTROL, DM_DMCONTROL_DMACTIVE);
+ result = activate_dm(target, dm->base);
if (result != ERROR_OK)
return result;
- 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 (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());
- return ERROR_TIMEOUT_REACHED;
- }
- } while (!get_field32(dmcontrol, DM_DMCONTROL_DMACTIVE));
-
LOG_TARGET_DEBUG(target, "DM successfully reset.");
dm->was_reset = true;
return ERROR_OK;
@@ -2065,7 +2083,7 @@ static int examine(struct target *target)
info->abits, RISCV013_DTMCS_ABITS_MIN);
}
- if (!check_dbgbase_exists(target)) {
+ if (check_dbgbase_exists(target) != ERROR_OK) {
LOG_TARGET_ERROR(target, "Could not find debug module with DMI base address (dbgbase) = 0x%x", target->dbgbase);
return ERROR_FAIL;
}
-----------------------------------------------------------------------
Summary of changes:
src/target/riscv/riscv-013.c | 60 ++++++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 21 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|