From: Zach W. <zw...@us...> - 2009-11-19 00:52:11
|
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 f382ebae1050fe26f25d13fd558277d8a032c778 (commit) via c0d14dc7f19d785702eee5f69de5b1a63902554b (commit) via 20218b8de61dea545c7575f36e1b74b9599c9848 (commit) via 4d8d1d32d0f0e0b8866a06cb1d3f304563fa6796 (commit) via 7e4adfe1c53aa18d4feba1e58ceb5c5aaa470775 (commit) via 410fab9ea8c6632da2e4967d960f66eecc7821ec (commit) via 75a37eb5b37386768327e9670acfedc7811d529f (commit) via bd5a1799ea63c2a863eae4aca2b55e41373d7528 (commit) from bd9d05e14bd08352811561e2d59a7ef2d9f3ed25 (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 f382ebae1050fe26f25d13fd558277d8a032c778 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 06:00:26 2009 -0800 fix zy1000 command handler Rewrite ZY1000 power command handler to use new macros, simplify logic. Remove unused port command handler declaration. diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index 206b362..28515c7 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -46,9 +46,6 @@ int zy1000_register_commands(struct command_context *cmd_ctx); int zy1000_init(void); int zy1000_quit(void); -/* interface commands */ -int zy1000_handle_zy1000_port_command(struct command_context *cmd_ctx, char *cmd, char **args, int argc); - static int zy1000_khz(int khz, int *jtag_speed) { if (khz == 0) @@ -227,21 +224,22 @@ static void setPower(bool power) } } -int handle_power_command(struct command_context *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_power_command) { - if (argc > 1) - { - return ERROR_INVALID_ARGUMENTS; - } - - if (argc == 1) + switch (CMD_ARGC) { + case 1: { bool enable; - COMMAND_PARSE_ON_OFF(args[0], enable); + COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable); setPower(enable); + // fall through + } + case 0: + command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off"); + break; + default: + return ERROR_INVALID_ARGUMENTS; } - - command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off"); return ERROR_OK; } commit c0d14dc7f19d785702eee5f69de5b1a63902554b Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 05:02:08 2009 -0800 remove fast command and jim_global_long Removing the fast command eliminates the fast_and_dangerous global, which was used only by arm7_9_common as an initializer. The command is not called in the tree; instead, more explicit commands are used. The jim_global_long function was not used anywhere in the tree. diff --git a/src/helper/command.c b/src/helper/command.c index b7c44ef..ba689b0 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -44,7 +44,6 @@ #include "jim-eventloop.h" -int fast_and_dangerous = 0; Jim_Interp *interp = NULL; static int run_command(struct command_context *context, @@ -141,7 +140,6 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) log_add_callback(tcl_output, tclOutput); - // turn words[0] into CMD_ARGV[-1] with this cast retval = run_command(context, c, (const char **)words, nwords); log_remove_callback(tcl_output, tclOutput); @@ -755,17 +753,6 @@ COMMAND_HANDLER(handle_sleep_command) return ERROR_OK; } -COMMAND_HANDLER(handle_fast_command) -{ - if (CMD_ARGC != 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - fast_and_dangerous = strcmp("enable", CMD_ARGV[0]) == 0; - - return ERROR_OK; -} - - struct command_context* command_init(const char *startup_tcl) { struct command_context* context = malloc(sizeof(struct command_context)); @@ -839,10 +826,6 @@ struct command_context* command_init(const char *startup_tcl) handle_sleep_command, COMMAND_ANY, "<n> [busy] - sleep for n milliseconds. " "\"busy\" means busy wait"); - register_command(context, NULL, "fast", - handle_fast_command, COMMAND_ANY, - "fast <enable/disable> - place at beginning of " - "config files. Sets defaults to fast and dangerous."); return context; } @@ -882,18 +865,6 @@ void register_jim(struct command_context *cmd_ctx, const char *name, command_helptext_add(cmd_list, help); } -/* return global variable long value or 0 upon failure */ -long jim_global_long(const char *variable) -{ - Jim_Obj *objPtr = Jim_GetGlobalVariableStr(interp, variable, JIM_ERRMSG); - long t; - if (Jim_GetLong(interp, objPtr, &t) == JIM_OK) - { - return t; - } - return 0; -} - #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \ int parse##name(const char *str, type *ul) \ { \ diff --git a/src/helper/command.h b/src/helper/command.h index a2e9797..def0935 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -214,15 +214,11 @@ void process_jim_events(void); #define ERROR_COMMAND_ARGUMENT_OVERFLOW (-604) #define ERROR_COMMAND_ARGUMENT_UNDERFLOW (-605) -extern int fast_and_dangerous; - extern Jim_Interp *interp; void register_jim(struct command_context *context, const char *name, Jim_CmdProc cmd, const char *help); -long jim_global_long(const char *variable); - int parse_ulong(const char *str, unsigned long *ul); int parse_ullong(const char *str, unsigned long long *ul); diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 16c8a92..eb4b038 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2929,8 +2929,8 @@ int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9) arm7_9->wp_available_max = 2; - arm7_9->fast_memory_access = fast_and_dangerous; - arm7_9->dcc_downloads = fast_and_dangerous; + arm7_9->fast_memory_access = false; + arm7_9->dcc_downloads = false; armv4_5->arch_info = arm7_9; armv4_5->read_core_reg = arm7_9_read_core_reg; commit 20218b8de61dea545c7575f36e1b74b9599c9848 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 15:20:58 2009 -0800 update src/hello.c with parsing examples Adds the foo/bar commands to provide more working examples of command argument parsing, including the new handle_command_parse_bool helper. Updates hello command help text to provide useful information. diff --git a/src/hello.c b/src/hello.c index dd33650..2ab7eb5 100644 --- a/src/hello.c +++ b/src/hello.c @@ -22,6 +22,57 @@ #endif #include "log.h" +COMMAND_HANDLER(handle_foo_command) +{ + if (CMD_ARGC < 1 || CMD_ARGC > 2) + { + LOG_ERROR("%s: incorrect number of arguments", CMD_NAME); + return ERROR_COMMAND_SYNTAX_ERROR; + } + + uint32_t address; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); + + const char *msg = "<unchanged>"; + if (CMD_ARGC == 2) + { + bool enable; + COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable); + msg = enable ? "enable" : "disable"; + } + + LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg); + return ERROR_OK; +} + +static bool foo_flag; + +COMMAND_HANDLER(handle_flag_command) +{ + return CALL_COMMAND_HANDLER(handle_command_parse_bool, + &foo_flag, "foo flag"); +} + +int foo_register_commands(struct command_context *cmd_ctx) +{ + // register several commands under the foo command + struct command *cmd = register_command(cmd_ctx, NULL, "foo", + NULL, COMMAND_ANY, "foo: command handler skeleton"); + + register_command(cmd_ctx, cmd, "bar", + &handle_foo_command, COMMAND_ANY, + "<address> [enable|disable] - an example command"); + register_command(cmd_ctx, cmd, "baz", + &handle_foo_command, COMMAND_ANY, + "<address> [enable|disable] - a sample command"); + + register_command(cmd_ctx, cmd, "flag", + &handle_flag_command, COMMAND_ANY, + "[on|off] - set a flag"); + + return ERROR_OK; +} + static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name) { if (CMD_ARGC > 1) @@ -50,8 +101,10 @@ COMMAND_HANDLER(handle_hello_command) int hello_register_commands(struct command_context *cmd_ctx) { + foo_register_commands(cmd_ctx); + struct command *cmd = register_command(cmd_ctx, NULL, "hello", &handle_hello_command, COMMAND_ANY, - "option"); + "[<name>] - prints a warm welcome"); return cmd ? ERROR_OK : -ENOMEM; } commit 4d8d1d32d0f0e0b8866a06cb1d3f304563fa6796 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 12:41:20 2009 -0800 change all bool parsers to accept any value This patch changes the behavior of all boolean parsing callers to accept any one of "true/enable/on/yes/1" or "false/disable/off/no/0". Since one particular pair will be most appropriate in any given situation, the specific macros should continue to be used in order to display the most informative error messages possible. diff --git a/src/helper/command.c b/src/helper/command.c index 5f3fae5..b7c44ef 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -955,7 +955,7 @@ DEFINE_PARSE_LONG(_s32, int32_t, n < INT32_MIN, INT32_MAX) DEFINE_PARSE_LONG(_s16, int16_t, n < INT16_MIN, INT16_MAX) DEFINE_PARSE_LONG(_s8, int8_t, n < INT8_MIN, INT8_MAX) -int command_parse_bool(const char *in, bool *out, +static int command_parse_bool(const char *in, bool *out, const char *on, const char *off) { if (strcasecmp(in, on) == 0) @@ -967,7 +967,7 @@ int command_parse_bool(const char *in, bool *out, return ERROR_OK; } -int command_parse_bool_any(const char *in, bool *out) +int command_parse_bool_arg(const char *in, bool *out) { if (command_parse_bool(in, out, "on", "off") == ERROR_OK) return ERROR_OK; @@ -987,7 +987,7 @@ COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label) switch (CMD_ARGC) { case 1: { const char *in = CMD_ARGV[0]; - if (command_parse_bool_any(in, out) != ERROR_OK) + if (command_parse_bool_arg(in, out) != ERROR_OK) { LOG_ERROR("%s: argument '%s' is not valid", CMD_NAME, in); return ERROR_INVALID_ARGUMENTS; diff --git a/src/helper/command.h b/src/helper/command.h index 06403ef..a2e9797 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -272,7 +272,7 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t); #define COMMAND_PARSE_BOOL(in, out, on, off) \ do { \ bool value; \ - int retval = command_parse_bool(in, &value, on, off); \ + int retval = command_parse_bool_arg(in, &value); \ if (ERROR_OK != retval) { \ command_print(CMD_CTX, stringify(out) \ " option value ('%s') is not valid", in); \ @@ -283,8 +283,7 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t); out = value; \ } while (0) -int command_parse_bool(const char *in, bool *out, - const char *on, const char *off); +int command_parse_bool_arg(const char *in, bool *out); COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label); /// parses an on/off command argument commit 7e4adfe1c53aa18d4feba1e58ceb5c5aaa470775 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 06:58:27 2009 -0800 add handle_command_parse_bool command helper Rewrite arm11_handle_bool to provide a generic on/off command helper. Refactors COMMAND_PARSE_BOOL to use new command_parse_bool helper, which gets reused by the new command_parse_bool_any helper. This later helper is called by the new command helper function to accepts any on/off, enable/disable, true/false, yes/no, or 0/1 parameter. diff --git a/src/helper/command.c b/src/helper/command.c index 708a802..5f3fae5 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -954,3 +954,53 @@ DEFINE_PARSE_LONG(_int, int, n < INT_MIN, INT_MAX) DEFINE_PARSE_LONG(_s32, int32_t, n < INT32_MIN, INT32_MAX) DEFINE_PARSE_LONG(_s16, int16_t, n < INT16_MIN, INT16_MAX) DEFINE_PARSE_LONG(_s8, int8_t, n < INT8_MIN, INT8_MAX) + +int command_parse_bool(const char *in, bool *out, + const char *on, const char *off) +{ + if (strcasecmp(in, on) == 0) + *out = true; + else if (strcasecmp(in, off) == 0) + *out = false; + else + return ERROR_COMMAND_SYNTAX_ERROR; + return ERROR_OK; +} + +int command_parse_bool_any(const char *in, bool *out) +{ + if (command_parse_bool(in, out, "on", "off") == ERROR_OK) + return ERROR_OK; + if (command_parse_bool(in, out, "enable", "disable") == ERROR_OK) + return ERROR_OK; + if (command_parse_bool(in, out, "true", "false") == ERROR_OK) + return ERROR_OK; + if (command_parse_bool(in, out, "yes", "no") == ERROR_OK) + return ERROR_OK; + if (command_parse_bool(in, out, "1", "0") == ERROR_OK) + return ERROR_OK; + return ERROR_INVALID_ARGUMENTS; +} + +COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label) +{ + switch (CMD_ARGC) { + case 1: { + const char *in = CMD_ARGV[0]; + if (command_parse_bool_any(in, out) != ERROR_OK) + { + LOG_ERROR("%s: argument '%s' is not valid", CMD_NAME, in); + return ERROR_INVALID_ARGUMENTS; + } + // fall through + } + case 0: + LOG_INFO("%s is %s", label, *out ? "enabled" : "disabled"); + break; + default: + return ERROR_INVALID_ARGUMENTS; + } + return ERROR_OK; +} + + diff --git a/src/helper/command.h b/src/helper/command.h index 9f2d971..06403ef 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -271,19 +271,22 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t); */ #define COMMAND_PARSE_BOOL(in, out, on, off) \ do { \ - if (strcmp(in, on) == 0) \ - out = true; \ - else if (strcmp(in, off) == 0) \ - out = false; \ - else { \ + bool value; \ + int retval = command_parse_bool(in, &value, on, off); \ + if (ERROR_OK != retval) { \ command_print(CMD_CTX, stringify(out) \ " option value ('%s') is not valid", in); \ command_print(CMD_CTX, " choices are '%s' or '%s'", \ on, off); \ - return ERROR_COMMAND_SYNTAX_ERROR; \ + return retval; \ } \ + out = value; \ } while (0) +int command_parse_bool(const char *in, bool *out, + const char *on, const char *off); +COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label); + /// parses an on/off command argument #define COMMAND_PARSE_ON_OFF(in, out) \ COMMAND_PARSE_BOOL(in, out, "on", "off") diff --git a/src/target/arm11.c b/src/target/arm11.c index 6e007cf..58b5d54 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -1981,52 +1981,17 @@ static int arm11_build_reg_cache(struct target *target) return ERROR_OK; } -static COMMAND_HELPER(arm11_handle_bool, bool *var, char *name) -{ - if (CMD_ARGC == 0) - { - LOG_INFO("%s is %s.", name, *var ? "enabled" : "disabled"); - return ERROR_OK; - } - - if (CMD_ARGC != 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - switch (CMD_ARGV[0][0]) - { - case '0': /* 0 */ - case 'f': /* false */ - case 'F': - case 'd': /* disable */ - case 'D': - *var = false; - break; - - case '1': /* 1 */ - case 't': /* true */ - case 'T': - case 'e': /* enable */ - case 'E': - *var = true; - break; - } - - LOG_INFO("%s %s.", *var ? "Enabled" : "Disabled", name); - - return ERROR_OK; -} - -#define BOOL_WRAPPER(name, print_name) \ -COMMAND_HANDLER(arm11_handle_bool_##name) \ -{ \ - return CALL_COMMAND_HANDLER(arm11_handle_bool, \ - &arm11_config_##name, print_name); \ -} +#define ARM11_BOOL_WRAPPER(name, print_name) \ + COMMAND_HANDLER(arm11_handle_bool_##name) \ + { \ + return CALL_COMMAND_HANDLER(handle_command_parse_bool, \ + &arm11_config_##name, print_name); \ + } -BOOL_WRAPPER(memwrite_burst, "memory write burst mode") -BOOL_WRAPPER(memwrite_error_fatal, "fatal error mode for memory writes") -BOOL_WRAPPER(step_irq_enable, "IRQs while stepping") -BOOL_WRAPPER(hardware_step, "hardware single step") +ARM11_BOOL_WRAPPER(memwrite_burst, "memory write burst mode") +ARM11_BOOL_WRAPPER(memwrite_error_fatal, "fatal error mode for memory writes") +ARM11_BOOL_WRAPPER(step_irq_enable, "IRQs while stepping") +ARM11_BOOL_WRAPPER(hardware_step, "hardware single step") COMMAND_HANDLER(arm11_handle_vcr) { commit 410fab9ea8c6632da2e4967d960f66eecc7821ec Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 05:36:18 2009 -0800 use COMMAND_PARSE_ENABLE macro where appropriate Updates all command parsing of simple "enable" and "disable" arguments. A few case in the tree use a tri-state or extended arguments, which cannot use this simple macro. Simlifies the xscale icache/dcache command handler logic. diff --git a/src/flash/nand.c b/src/flash/nand.c index c96354a..23caed0 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -1663,14 +1663,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command) } if (CMD_ARGC == 2) - { - if (strcmp("enable", CMD_ARGV[1]) == 0) - p->use_raw = 1; - else if (strcmp("disable", CMD_ARGV[1]) == 0) - p->use_raw = 0; - else - return ERROR_COMMAND_SYNTAX_ERROR; - } + COMMAND_PARSE_ENABLE(CMD_ARGV[1], p->use_raw); const char *msg = p->use_raw ? "enabled" : "disabled"; command_print(CMD_CTX, "raw access is %s", msg); diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 96018b5..1266cd7 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -1357,12 +1357,9 @@ COMMAND_HANDLER(handle_verify_ircapture_command) if (CMD_ARGC == 1) { - if (strcmp(CMD_ARGV[0], "enable") == 0) - jtag_set_verify_capture_ir(true); - else if (strcmp(CMD_ARGV[0], "disable") == 0) - jtag_set_verify_capture_ir(false); - else - return ERROR_COMMAND_SYNTAX_ERROR; + bool enable; + COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable); + jtag_set_verify_capture_ir(enable); } const char *status = jtag_will_verify_capture_ir() ? "enabled": "disabled"; @@ -1378,12 +1375,9 @@ COMMAND_HANDLER(handle_verify_jtag_command) if (CMD_ARGC == 1) { - if (strcmp(CMD_ARGV[0], "enable") == 0) - jtag_set_verify(true); - else if (strcmp(CMD_ARGV[0], "disable") == 0) - jtag_set_verify(false); - else - return ERROR_COMMAND_SYNTAX_ERROR; + bool enable; + COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable); + jtag_set_verify(enable); } const char *status = jtag_will_verify() ? "enabled": "disabled"; diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 9605f81..21dc24c 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2271,20 +2271,7 @@ COMMAND_HANDLER(handle_gdb_port_command) COMMAND_HANDLER(handle_gdb_memory_map_command) { if (CMD_ARGC == 1) - { - if (strcmp(CMD_ARGV[0], "enable") == 0) - { - gdb_use_memory_map = 1; - return ERROR_OK; - } - else if (strcmp(CMD_ARGV[0], "disable") == 0) - { - gdb_use_memory_map = 0; - return ERROR_OK; - } - else - LOG_WARNING("invalid gdb_memory_map configuration directive %s", CMD_ARGV[0]); - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0], gdb_use_memory_map); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -2292,20 +2279,7 @@ COMMAND_HANDLER(handle_gdb_memory_map_command) COMMAND_HANDLER(handle_gdb_flash_program_command) { if (CMD_ARGC == 1) - { - if (strcmp(CMD_ARGV[0], "enable") == 0) - { - gdb_flash_program = 1; - return ERROR_OK; - } - else if (strcmp(CMD_ARGV[0], "disable") == 0) - { - gdb_flash_program = 0; - return ERROR_OK; - } - else - LOG_WARNING("invalid gdb_flash_program configuration directive: %s", CMD_ARGV[0]); - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0], gdb_flash_program); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -2313,20 +2287,7 @@ COMMAND_HANDLER(handle_gdb_flash_program_command) COMMAND_HANDLER(handle_gdb_report_data_abort_command) { if (CMD_ARGC == 1) - { - if (strcmp(CMD_ARGV[0], "enable") == 0) - { - gdb_report_data_abort = 1; - return ERROR_OK; - } - else if (strcmp(CMD_ARGV[0], "disable") == 0) - { - gdb_report_data_abort = 0; - return ERROR_OK; - } - else - LOG_WARNING("invalid gdb_report_data_abort configuration directive: %s", CMD_ARGV[0]); - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0], gdb_report_data_abort); return ERROR_COMMAND_SYNTAX_ERROR; } diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 37aa066..16c8a92 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2870,20 +2870,7 @@ COMMAND_HANDLER(handle_arm7_9_dbgrq_command) } if (CMD_ARGC > 0) - { - if (strcmp("enable", CMD_ARGV[0]) == 0) - { - arm7_9->use_dbgrq = 1; - } - else if (strcmp("disable", CMD_ARGV[0]) == 0) - { - arm7_9->use_dbgrq = 0; - } - else - { - command_print(CMD_CTX, "usage: arm7_9 dbgrq <enable | disable>"); - } - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0],arm7_9->use_dbgrq); command_print(CMD_CTX, "use of EmbeddedICE dbgrq instead of breakpoint for target halt %s", (arm7_9->use_dbgrq) ? "enabled" : "disabled"); @@ -2902,20 +2889,7 @@ COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command) } if (CMD_ARGC > 0) - { - if (strcmp("enable", CMD_ARGV[0]) == 0) - { - arm7_9->fast_memory_access = 1; - } - else if (strcmp("disable", CMD_ARGV[0]) == 0) - { - arm7_9->fast_memory_access = 0; - } - else - { - command_print(CMD_CTX, "usage: arm7_9 fast_memory_access <enable | disable>"); - } - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->fast_memory_access); command_print(CMD_CTX, "fast memory access is %s", (arm7_9->fast_memory_access) ? "enabled" : "disabled"); @@ -2934,20 +2908,7 @@ COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command) } if (CMD_ARGC > 0) - { - if (strcmp("enable", CMD_ARGV[0]) == 0) - { - arm7_9->dcc_downloads = 1; - } - else if (strcmp("disable", CMD_ARGV[0]) == 0) - { - arm7_9->dcc_downloads = 0; - } - else - { - command_print(CMD_CTX, "usage: arm7_9 dcc_downloads <enable | disable>"); - } - } + COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->dcc_downloads); command_print(CMD_CTX, "dcc downloads are %s", (arm7_9->dcc_downloads) ? "enabled" : "disabled"); diff --git a/src/target/etm.c b/src/target/etm.c index 3b5fa61..85cc6eb 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -1214,25 +1214,14 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update, return ERROR_INVALID_ARGUMENTS; } - if (strcmp(CMD_ARGV[2], "enable") == 0) + bool etmv1_cycle_accurate; + COMMAND_PARSE_ENABLE(CMD_ARGV[2], etmv1_cycle_accurate); + if (etmv1_cycle_accurate) tracemode |= ETMV1_CYCLE_ACCURATE; - else if (strcmp(CMD_ARGV[2], "disable") == 0) - tracemode |= 0; - else - { - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[2]); - return ERROR_INVALID_ARGUMENTS; - } - if (strcmp(CMD_ARGV[3], "enable") == 0) + bool etmv1_branch_output; + COMMAND_PARSE_ENABLE(CMD_ARGV[3], etmv1_branch_output); tracemode |= ETMV1_BRANCH_OUTPUT; - else if (strcmp(CMD_ARGV[3], "disable") == 0) - tracemode |= 0; - else - { - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[3]); - return ERROR_INVALID_ARGUMENTS; - } /* IGNORED: * - CPRT tracing (coprocessor register transfers) diff --git a/src/target/xscale.c b/src/target/xscale.c index 09e6825..28f89f1 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3130,16 +3130,13 @@ COMMAND_HANDLER(xscale_handle_mmu_command) if (CMD_ARGC >= 1) { - if (strcmp("enable", CMD_ARGV[0]) == 0) - { + bool enable; + COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable); + if (enable) xscale_enable_mmu_caches(target, 1, 0, 0); - xscale->armv4_5_mmu.mmu_enabled = 1; - } - else if (strcmp("disable", CMD_ARGV[0]) == 0) - { + else xscale_disable_mmu_caches(target, 1, 0, 0); - xscale->armv4_5_mmu.mmu_enabled = 0; - } + xscale->armv4_5_mmu.mmu_enabled = enable; } command_print(CMD_CTX, "mmu %s", (xscale->armv4_5_mmu.mmu_enabled) ? "enabled" : "disabled"); @@ -3151,10 +3148,8 @@ COMMAND_HANDLER(xscale_handle_idcache_command) { struct target *target = get_current_target(CMD_CTX); struct xscale_common *xscale = target_to_xscale(target); - int icache = 0, dcache = 0; - int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + int retval = xscale_verify_pointer(CMD_CTX, xscale); if (retval != ERROR_OK) return retval; @@ -3164,38 +3159,28 @@ COMMAND_HANDLER(xscale_handle_idcache_command) return ERROR_OK; } - if (strcmp(CMD_NAME, "icache") == 0) - icache = 1; - else if (strcmp(CMD_NAME, "dcache") == 0) - dcache = 1; + bool icache; + COMMAND_PARSE_BOOL(CMD_NAME, icache, "icache", "dcache"); if (CMD_ARGC >= 1) { - if (strcmp("enable", CMD_ARGV[0]) == 0) - { - xscale_enable_mmu_caches(target, 0, dcache, icache); - - if (icache) - xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled = 1; - else if (dcache) - xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = 1; - } - else if (strcmp("disable", CMD_ARGV[0]) == 0) - { - xscale_disable_mmu_caches(target, 0, dcache, icache); - - if (icache) - xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled = 0; - else if (dcache) - xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = 0; - } + bool enable; + COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable); + if (enable) + xscale_enable_mmu_caches(target, 1, 0, 0); + else + xscale_disable_mmu_caches(target, 1, 0, 0); + if (icache) + xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled = enable; + else + xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = enable; } - if (icache) - command_print(CMD_CTX, "icache %s", (xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled) ? "enabled" : "disabled"); - - if (dcache) - command_print(CMD_CTX, "dcache %s", (xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled) ? "enabled" : "disabled"); + bool enabled = icache ? + xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled : + xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled; + const char *msg = enabled ? "enabled" : "disabled"; + command_print(CMD_CTX, "%s %s", CMD_NAME, msg); return ERROR_OK; } commit 75a37eb5b37386768327e9670acfedc7811d529f Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 05:22:44 2009 -0800 use COMMAND_PARSE_ON_OFF where appropriate Updates all command parsing of "on" and "off" arguments. diff --git a/src/flash/flash.c b/src/flash/flash.c index 2c63b82..98e5ee0 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -577,7 +577,6 @@ COMMAND_HANDLER(handle_flash_protect_command) uint32_t bank_nr; uint32_t first; uint32_t last; - int set; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bank_nr); struct flash_bank *p = get_flash_bank_by_num(bank_nr); @@ -590,12 +589,8 @@ COMMAND_HANDLER(handle_flash_protect_command) else COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], last); - if (strcmp(CMD_ARGV[3], "on") == 0) - set = 1; - else if (strcmp(CMD_ARGV[3], "off") == 0) - set = 0; - else - return ERROR_COMMAND_SYNTAX_ERROR; + bool set; + COMMAND_PARSE_ON_OFF(CMD_ARGV[3], set); int retval; if ((retval = flash_check_sector_parameters(CMD_CTX, diff --git a/src/jtag/parport.c b/src/jtag/parport.c index 97f6458..b80626f 100644 --- a/src/jtag/parport.c +++ b/src/jtag/parport.c @@ -103,7 +103,7 @@ static struct cable cables[] = /* configuration */ static char* parport_cable = NULL; static uint16_t parport_port; -static int parport_exit = 0; +static bool parport_exit = 0; static uint32_t parport_toggling_time_ns = 1000; static int wait_states; @@ -453,10 +453,7 @@ COMMAND_HANDLER(parport_handle_write_on_exit_command) return ERROR_OK; } - if (strcmp(CMD_ARGV[0], "on") == 0) - parport_exit = 1; - else if (strcmp(CMD_ARGV[0], "off") == 0) - parport_exit = 0; + COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit); return ERROR_OK; } diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index a509aee..206b362 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -236,18 +236,9 @@ int handle_power_command(struct command_context *cmd_ctx, char *cmd, char **args if (argc == 1) { - if (strcmp(args[0], "on") == 0) - { - setPower(1); - } - else if (strcmp(args[0], "off") == 0) - { - setPower(0); - } else - { - command_print(cmd_ctx, "arg is \"on\" or \"off\""); - return ERROR_INVALID_ARGUMENTS; - } + bool enable; + COMMAND_PARSE_ON_OFF(args[0], enable); + setPower(enable); } command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off"); diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index 42f8ee0..e7b5110 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -1898,18 +1898,11 @@ COMMAND_HANDLER(handle_cortex_m3_mask_interrupts_command) if (CMD_ARGC > 0) { - if (!strcmp(CMD_ARGV[0], "on")) - { - cortex_m3_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); - } - else if (!strcmp(CMD_ARGV[0], "off")) - { - cortex_m3_write_debug_halt_mask(target, C_HALT, C_MASKINTS); - } - else - { - command_print(CMD_CTX, "usage: cortex_m3 maskisr ['on'|'off']"); - } + bool enable; + COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable); + uint32_t mask_on = C_HALT | (enable ? C_MASKINTS : 0); + uint32_t mask_off = enable ? 0 : C_MASKINTS; + cortex_m3_write_debug_halt_mask(target, mask_on, mask_off); } command_print(CMD_CTX, "cortex_m3 interrupt mask %s", diff --git a/src/target/target.c b/src/target/target.c index 98e7a40..f203913 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2003,23 +2003,14 @@ COMMAND_HANDLER(handle_poll_command) return retval; if ((retval = target_arch_state(target)) != ERROR_OK) return retval; - } else if (CMD_ARGC == 1) { - if (strcmp(CMD_ARGV[0], "on") == 0) - { - jtag_poll_set_enabled(true); - } - else if (strcmp(CMD_ARGV[0], "off") == 0) - { - jtag_poll_set_enabled(false); - } - else - { - command_print(CMD_CTX, "arg is \"on\" or \"off\""); - } - } else + bool enable; + COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable); + jtag_poll_set_enabled(enable); + } + else { return ERROR_COMMAND_SYNTAX_ERROR; } commit bd5a1799ea63c2a863eae4aca2b55e41373d7528 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 18 05:19:34 2009 -0800 add COMMAND_PARSE_BOOL macro and friends Adds several macros similar to COMMAND_PARSE_NUMBER, but for parsing boolean command arguments. Two flavors are provided to provide drop-in compatibility with existing code, allow for the elimination of a lot of code bloat while improving the error checking and reporting. COMMAND_PARSE_ON_OFF parses "on"/"off" command parameters. COMMAND_PARSE_ENABLE parses "enable"/"disable" command parameters. Both print the error and return an error out of the calling function. diff --git a/src/helper/command.h b/src/helper/command.h index 05088b5..9f2d971 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -263,6 +263,34 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t); } \ } while (0) +/** + * Parse the string @c as a binary parameter, storing the boolean value + * in @c out. The strings @c on and @c off are used to match different + * strings for true and false options (e.g. "on" and "off" or + * "enable" and "disable"). + */ +#define COMMAND_PARSE_BOOL(in, out, on, off) \ + do { \ + if (strcmp(in, on) == 0) \ + out = true; \ + else if (strcmp(in, off) == 0) \ + out = false; \ + else { \ + command_print(CMD_CTX, stringify(out) \ + " option value ('%s') is not valid", in); \ + command_print(CMD_CTX, " choices are '%s' or '%s'", \ + on, off); \ + return ERROR_COMMAND_SYNTAX_ERROR; \ + } \ + } while (0) + +/// parses an on/off command argument +#define COMMAND_PARSE_ON_OFF(in, out) \ + COMMAND_PARSE_BOOL(in, out, "on", "off") +/// parses an enable/disable command argument +#define COMMAND_PARSE_ENABLE(in, out) \ + COMMAND_PARSE_BOOL(in, out, "enable", "disable") + void script_debug(Jim_Interp *interp, const char *cmd, unsigned argc, Jim_Obj *const *argv); ----------------------------------------------------------------------- Summary of changes: src/flash/flash.c | 9 +---- src/flash/nand.c | 9 +---- src/hello.c | 55 ++++++++++++++++++++++++++++++- src/helper/command.c | 79 ++++++++++++++++++++++++++++---------------- src/helper/command.h | 34 ++++++++++++++++-- src/jtag/parport.c | 7 +--- src/jtag/tcl.c | 18 +++------- src/jtag/zy1000/zy1000.c | 35 +++++++------------- src/server/gdb_server.c | 45 ++----------------------- src/target/arm11.c | 55 +++++------------------------- src/target/arm7_9_common.c | 49 +++------------------------ src/target/cortex_m3.c | 17 +++------- src/target/etm.c | 21 +++--------- src/target/target.c | 19 +++-------- src/target/xscale.c | 61 +++++++++++++--------------------- 15 files changed, 213 insertions(+), 300 deletions(-) hooks/post-receive -- Main OpenOCD repository |