Skip to content

Commit 7e50833

Browse files
committed
target/riscv: add target_was_examined() checks
If a RISC-V target does not pass initial examination some commands fail by assert() or log lot of hardly understandable errors. Check if target was examined otherwise fail early. Although command_print() is preferred in OpenOCD commands, use LOG_TARGET_ERROR() if the rest of command uses the same. Change-Id: I615e48f348a0f3bdaf71630a2fcd6fc7665115d5 Signed-off-by: Tomas Vanek <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/9275 Tested-by: jenkins Reviewed-by: Antonio Borneo <[email protected]>
1 parent b07521d commit 7e50833

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/target/riscv/riscv.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,6 +5007,11 @@ COMMAND_HANDLER(riscv_itrigger)
50075007
struct target *target = get_current_target(CMD_CTX);
50085008
const int ITRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ITRIGGER;
50095009

5010+
if (!target_was_examined(target)) {
5011+
LOG_TARGET_ERROR(target, "not examined");
5012+
return ERROR_TARGET_NOT_EXAMINED;
5013+
}
5014+
50105015
if (riscv_enumerate_triggers(target) != ERROR_OK)
50115016
return ERROR_FAIL;
50125017

@@ -5072,6 +5077,11 @@ COMMAND_HANDLER(riscv_icount)
50725077
struct target *target = get_current_target(CMD_CTX);
50735078
const int ICOUNT_UNIQUE_ID = -CSR_TDATA1_TYPE_ICOUNT;
50745079

5080+
if (!target_was_examined(target)) {
5081+
LOG_TARGET_ERROR(target, "not examined");
5082+
return ERROR_TARGET_NOT_EXAMINED;
5083+
}
5084+
50755085
if (riscv_enumerate_triggers(target) != ERROR_OK)
50765086
return ERROR_FAIL;
50775087

@@ -5137,6 +5147,11 @@ COMMAND_HANDLER(riscv_etrigger)
51375147
struct target *target = get_current_target(CMD_CTX);
51385148
const int ETRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ETRIGGER;
51395149

5150+
if (!target_was_examined(target)) {
5151+
LOG_TARGET_ERROR(target, "not examined");
5152+
return ERROR_TARGET_NOT_EXAMINED;
5153+
}
5154+
51405155
if (riscv_enumerate_triggers(target) != ERROR_OK)
51415156
return ERROR_FAIL;
51425157

@@ -5194,6 +5209,11 @@ COMMAND_HANDLER(riscv_etrigger)
51945209
COMMAND_HANDLER(handle_repeat_read)
51955210
{
51965211
struct target *target = get_current_target(CMD_CTX);
5212+
if (!target_was_examined(target)) {
5213+
LOG_TARGET_ERROR(target, "not examined");
5214+
return ERROR_TARGET_NOT_EXAMINED;
5215+
}
5216+
51975217
RISCV_INFO(r);
51985218

51995219
if (CMD_ARGC < 2 || CMD_ARGC > 3)
@@ -5408,6 +5428,11 @@ COMMAND_HANDLER(riscv_exec_progbuf)
54085428

54095429
struct target *target = get_current_target(CMD_CTX);
54105430

5431+
if (!target_was_examined(target)) {
5432+
LOG_TARGET_ERROR(target, "not examined");
5433+
return ERROR_TARGET_NOT_EXAMINED;
5434+
}
5435+
54115436
RISCV_INFO(r);
54125437
if (r->dtm_version != DTM_DTMCS_VERSION_1_0) {
54135438
LOG_TARGET_ERROR(target, "exec_progbuf: Program buffer is "
@@ -5514,6 +5539,11 @@ static COMMAND_HELPER(report_reserved_triggers, struct target *target)
55145539
COMMAND_HANDLER(handle_reserve_trigger)
55155540
{
55165541
struct target *target = get_current_target(CMD_CTX);
5542+
if (!target_was_examined(target)) {
5543+
command_print(CMD, "Error: Target not examined");
5544+
return ERROR_TARGET_NOT_EXAMINED;
5545+
}
5546+
55175547
if (CMD_ARGC == 0)
55185548
return CALL_COMMAND_HANDLER(report_reserved_triggers, target);
55195549

0 commit comments

Comments
 (0)