Skip to content

Commit e024f11

Browse files
committed
[NFC] target/riscv: remove LOG_ERROR when COMMAND check ARGC fail
Per current OpenOCD conventions, LOG_ERROR should not be printed when ERROR_COMMAND_SYNTAX_ERROR is returned. OpenOCD will print the command syntax to the user on its own.
1 parent 9ff272e commit e024f11

File tree

1 file changed

+30
-68
lines changed

1 file changed

+30
-68
lines changed

src/target/riscv/riscv.c

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,10 +3927,9 @@ int riscv_openocd_step(struct target *target, int current,
39273927
/* Command Handlers */
39283928
COMMAND_HANDLER(riscv_set_command_timeout_sec)
39293929
{
3930-
if (CMD_ARGC != 1) {
3931-
LOG_ERROR("Command takes exactly 1 parameter.");
3930+
if (CMD_ARGC != 1)
39323931
return ERROR_COMMAND_SYNTAX_ERROR;
3933-
}
3932+
39343933
int timeout = atoi(CMD_ARGV[0]);
39353934
if (timeout <= 0) {
39363935
LOG_ERROR("%s is not a valid integer argument for command.", CMD_ARGV[0]);
@@ -3945,10 +3944,9 @@ COMMAND_HANDLER(riscv_set_command_timeout_sec)
39453944
COMMAND_HANDLER(riscv_set_reset_timeout_sec)
39463945
{
39473946
LOG_WARNING("The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
3948-
if (CMD_ARGC != 1) {
3949-
LOG_ERROR("Command takes exactly 1 parameter.");
3947+
if (CMD_ARGC != 1)
39503948
return ERROR_COMMAND_SYNTAX_ERROR;
3951-
}
3949+
39523950
int timeout = atoi(CMD_ARGV[0]);
39533951
if (timeout <= 0) {
39543952
LOG_ERROR("%s is not a valid integer argument for command.", CMD_ARGV[0]);
@@ -4137,10 +4135,8 @@ static int parse_ranges(struct list_head *ranges, const char *tcl_arg, const cha
41374135

41384136
COMMAND_HANDLER(riscv_set_expose_csrs)
41394137
{
4140-
if (CMD_ARGC == 0) {
4141-
LOG_ERROR("Command expects parameters.");
4138+
if (CMD_ARGC == 0)
41424139
return ERROR_COMMAND_SYNTAX_ERROR;
4143-
}
41444140

41454141
struct target *target = get_current_target(CMD_CTX);
41464142
RISCV_INFO(info);
@@ -4157,10 +4153,8 @@ COMMAND_HANDLER(riscv_set_expose_csrs)
41574153

41584154
COMMAND_HANDLER(riscv_set_expose_custom)
41594155
{
4160-
if (CMD_ARGC == 0) {
4161-
LOG_ERROR("Command expects parameters.");
4156+
if (CMD_ARGC == 0)
41624157
return ERROR_COMMAND_SYNTAX_ERROR;
4163-
}
41644158

41654159
struct target *target = get_current_target(CMD_CTX);
41664160
RISCV_INFO(info);
@@ -4177,10 +4171,8 @@ COMMAND_HANDLER(riscv_set_expose_custom)
41774171

41784172
COMMAND_HANDLER(riscv_hide_csrs)
41794173
{
4180-
if (CMD_ARGC == 0) {
4181-
LOG_ERROR("Command expects parameters");
4174+
if (CMD_ARGC == 0)
41824175
return ERROR_COMMAND_SYNTAX_ERROR;
4183-
}
41844176

41854177
struct target *target = get_current_target(CMD_CTX);
41864178
RISCV_INFO(info);
@@ -4198,14 +4190,10 @@ COMMAND_HANDLER(riscv_hide_csrs)
41984190
COMMAND_HANDLER(riscv_authdata_read)
41994191
{
42004192
unsigned int index = 0;
4201-
if (CMD_ARGC == 0) {
4202-
/* nop */
4203-
} else if (CMD_ARGC == 1) {
4193+
if (CMD_ARGC == 1)
42044194
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], index);
4205-
} else {
4206-
LOG_ERROR("Command takes at most one parameter.");
4195+
else if (CMD_ARGC != 0)
42074196
return ERROR_COMMAND_SYNTAX_ERROR;
4208-
}
42094197

42104198
struct target *target = get_current_target(CMD_CTX);
42114199
if (!target) {
@@ -4409,10 +4397,8 @@ COMMAND_HANDLER(riscv_reset_delays)
44094397

44104398
COMMAND_HANDLER(riscv_set_ir)
44114399
{
4412-
if (CMD_ARGC != 2) {
4413-
LOG_ERROR("Command takes exactly 2 arguments");
4400+
if (CMD_ARGC != 2)
44144401
return ERROR_COMMAND_SYNTAX_ERROR;
4415-
}
44164402

44174403
uint32_t value;
44184404
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
@@ -4431,10 +4417,8 @@ COMMAND_HANDLER(riscv_set_ir)
44314417

44324418
COMMAND_HANDLER(riscv_resume_order)
44334419
{
4434-
if (CMD_ARGC > 1) {
4435-
LOG_ERROR("Command takes at most one argument");
4420+
if (CMD_ARGC > 1)
44364421
return ERROR_COMMAND_SYNTAX_ERROR;
4437-
}
44384422

44394423
if (!strcmp(CMD_ARGV[0], "normal")) {
44404424
resume_order = RO_NORMAL;
@@ -4483,12 +4467,11 @@ COMMAND_HANDLER(riscv_set_bscan_tunnel_ir)
44834467
{
44844468
int ir_id = 0;
44854469

4486-
if (CMD_ARGC > 1) {
4487-
LOG_ERROR("Command takes at most one arguments");
4470+
if (CMD_ARGC > 1)
44884471
return ERROR_COMMAND_SYNTAX_ERROR;
4489-
} else if (CMD_ARGC == 1) {
4472+
4473+
if (CMD_ARGC == 1)
44904474
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], ir_id);
4491-
}
44924475

44934476
LOG_INFO("Bscan tunnel IR 0x%x selected", ir_id);
44944477

@@ -4534,7 +4517,6 @@ COMMAND_HANDLER(riscv_set_ebreakm)
45344517
return ERROR_OK;
45354518
}
45364519

4537-
LOG_ERROR("Command takes 0 or 1 parameters");
45384520
return ERROR_COMMAND_SYNTAX_ERROR;
45394521
}
45404522

@@ -4551,7 +4533,6 @@ COMMAND_HANDLER(riscv_set_ebreaks)
45514533
return ERROR_OK;
45524534
}
45534535

4554-
LOG_ERROR("Command takes 0 or 1 parameters");
45554536
return ERROR_COMMAND_SYNTAX_ERROR;
45564537
}
45574538

@@ -4568,17 +4549,15 @@ COMMAND_HANDLER(riscv_set_ebreaku)
45684549
return ERROR_OK;
45694550
}
45704551

4571-
LOG_ERROR("Command takes 0 or 1 parameters");
45724552
return ERROR_COMMAND_SYNTAX_ERROR;
45734553
}
45744554

45754555
COMMAND_HELPER(riscv_clear_trigger, int trigger_id, const char *name)
45764556
{
45774557
struct target *target = get_current_target(CMD_CTX);
4578-
if (CMD_ARGC != 1) {
4579-
LOG_ERROR("clear command takes no extra arguments.");
4558+
if (CMD_ARGC != 1)
45804559
return ERROR_COMMAND_SYNTAX_ERROR;
4581-
}
4560+
45824561
if (find_first_trigger_by_id(target, trigger_id) < 0) {
45834562
LOG_TARGET_ERROR(target, "No %s is set. Nothing to clear.", name);
45844563
return ERROR_FAIL;
@@ -4588,10 +4567,8 @@ COMMAND_HELPER(riscv_clear_trigger, int trigger_id, const char *name)
45884567

45894568
COMMAND_HANDLER(riscv_itrigger)
45904569
{
4591-
if (CMD_ARGC < 1) {
4592-
LOG_ERROR("Command takes at least 1 parameter");
4570+
if (CMD_ARGC < 1)
45934571
return ERROR_COMMAND_SYNTAX_ERROR;
4594-
}
45954572

45964573
struct target *target = get_current_target(CMD_CTX);
45974574
const int ITRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ITRIGGER;
@@ -4655,10 +4632,8 @@ COMMAND_HANDLER(riscv_itrigger)
46554632

46564633
COMMAND_HANDLER(riscv_icount)
46574634
{
4658-
if (CMD_ARGC < 1) {
4659-
LOG_ERROR("Command takes at least 1 parameter");
4635+
if (CMD_ARGC < 1)
46604636
return ERROR_COMMAND_SYNTAX_ERROR;
4661-
}
46624637

46634638
struct target *target = get_current_target(CMD_CTX);
46644639
const int ICOUNT_UNIQUE_ID = -CSR_TDATA1_TYPE_ICOUNT;
@@ -4722,10 +4697,8 @@ COMMAND_HANDLER(riscv_icount)
47224697

47234698
COMMAND_HANDLER(riscv_etrigger)
47244699
{
4725-
if (CMD_ARGC < 1) {
4726-
LOG_ERROR("Command takes at least 1 parameter");
4700+
if (CMD_ARGC < 1)
47274701
return ERROR_COMMAND_SYNTAX_ERROR;
4728-
}
47294702

47304703
struct target *target = get_current_target(CMD_CTX);
47314704
const int ETRIGGER_UNIQUE_ID = -CSR_TDATA1_TYPE_ETRIGGER;
@@ -4789,14 +4762,8 @@ COMMAND_HANDLER(handle_repeat_read)
47894762
struct target *target = get_current_target(CMD_CTX);
47904763
RISCV_INFO(r);
47914764

4792-
if (CMD_ARGC < 2) {
4793-
LOG_ERROR("Command requires at least count and address arguments.");
4765+
if (CMD_ARGC < 2 || CMD_ARGC > 3)
47944766
return ERROR_COMMAND_SYNTAX_ERROR;
4795-
}
4796-
if (CMD_ARGC > 3) {
4797-
LOG_ERROR("Command takes at most 3 arguments.");
4798-
return ERROR_COMMAND_SYNTAX_ERROR;
4799-
}
48004767

48014768
uint32_t count;
48024769
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], count);
@@ -4842,10 +4809,8 @@ COMMAND_HANDLER(handle_memory_sample_command)
48424809
return ERROR_OK;
48434810
}
48444811

4845-
if (CMD_ARGC < 2) {
4846-
LOG_ERROR("Command requires at least bucket and address arguments.");
4812+
if (CMD_ARGC < 2)
48474813
return ERROR_COMMAND_SYNTAX_ERROR;
4848-
}
48494814

48504815
uint32_t bucket;
48514816
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bucket);
@@ -4891,10 +4856,9 @@ COMMAND_HANDLER(handle_dump_sample_buf_command)
48914856
struct target *target = get_current_target(CMD_CTX);
48924857
RISCV_INFO(r);
48934858

4894-
if (CMD_ARGC > 1) {
4895-
LOG_ERROR("Command takes at most 1 arguments.");
4859+
if (CMD_ARGC > 1)
48964860
return ERROR_COMMAND_SYNTAX_ERROR;
4897-
}
4861+
48984862
bool base64 = false;
48994863
if (CMD_ARGC > 0) {
49004864
if (!strcmp(CMD_ARGV[0], "base64")) {
@@ -5000,10 +4964,8 @@ COMMAND_HANDLER(handle_info)
50004964

50014965
COMMAND_HANDLER(riscv_exec_progbuf)
50024966
{
5003-
if (CMD_ARGC < 1 || CMD_ARGC > 16) {
5004-
LOG_ERROR("Command 'exec_progbuf' takes 1 to 16 arguments.");
4967+
if (CMD_ARGC < 1 || CMD_ARGC > 16)
50054968
return ERROR_COMMAND_SYNTAX_ERROR;
5006-
}
50074969

50084970
struct target *target = get_current_target(CMD_CTX);
50094971

@@ -5208,14 +5170,14 @@ static const struct command_registration riscv_exec_command_handlers[] = {
52085170
.name = "set_command_timeout_sec",
52095171
.handler = riscv_set_command_timeout_sec,
52105172
.mode = COMMAND_ANY,
5211-
.usage = "[sec]",
5173+
.usage = "sec",
52125174
.help = "Set the wall-clock timeout (in seconds) for individual commands"
52135175
},
52145176
{
52155177
.name = "set_reset_timeout_sec",
52165178
.handler = riscv_set_reset_timeout_sec,
52175179
.mode = COMMAND_ANY,
5218-
.usage = "[sec]",
5180+
.usage = "sec",
52195181
.help = "DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
52205182
},
52215183
{
@@ -5230,7 +5192,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
52305192
.name = "expose_csrs",
52315193
.handler = riscv_set_expose_csrs,
52325194
.mode = COMMAND_CONFIG,
5233-
.usage = "n0[-m0|=name0][,n1[-m1|=name1]]...",
5195+
.usage = "n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
52345196
.help = "Configure a list of inclusive ranges for CSRs to expose in "
52355197
"addition to the standard ones. This must be executed before "
52365198
"`init`."
@@ -5239,7 +5201,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
52395201
.name = "expose_custom",
52405202
.handler = riscv_set_expose_custom,
52415203
.mode = COMMAND_CONFIG,
5242-
.usage = "n0[-m0|=name0][,n1[-m1|=name1]]...",
5204+
.usage = "n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
52435205
.help = "Configure a list of inclusive ranges for custom registers to "
52445206
"expose. custom0 is accessed as abstract register number 0xc000, "
52455207
"etc. This must be executed before `init`."
@@ -5324,7 +5286,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
53245286
.name = "set_ir",
53255287
.handler = riscv_set_ir,
53265288
.mode = COMMAND_ANY,
5327-
.usage = "[idcode|dtmcs|dmi] value",
5289+
.usage = "idcode|dtmcs|dmi value",
53285290
.help = "Set IR value for specified JTAG register."
53295291
},
53305292
{
@@ -5338,7 +5300,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
53385300
.name = "set_bscan_tunnel_ir",
53395301
.handler = riscv_set_bscan_tunnel_ir,
53405302
.mode = COMMAND_CONFIG,
5341-
.usage = "value",
5303+
.usage = "[value]",
53425304
.help = "Specify the JTAG TAP IR used to access the bscan tunnel. "
53435305
"By default it is 0x23 << (ir_length - 6), which map some "
53445306
"Xilinx FPGA (IR USER4)"

0 commit comments

Comments
 (0)