From: Zach W. <zw...@us...> - 2009-11-25 19:56:16
|
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 62e56496009796497665c1d06819c163589a3877 (commit) via 769fbfa058946e1581d5f9ad75d17947d1ee9ff1 (commit) via 4c54c27da774f8035a04f3b091fcfc5661253a0e (commit) via 60ba4641d61ba65943ac7a8c800e82d6665ee11f (commit) via 607634f967cf25630860794847dea770eb17a8f4 (commit) via 25a7ac2c756c78603c9c99d06f55717440409a23 (commit) via d107f71c5079dbe2a023276367b805397d1245c4 (commit) via 2461855494cd045567c15c502ba215caffb37ce3 (commit) via 69076057dde9f4336b54fb4da677da8fe5da66bd (commit) via 833e7f5248778bcb31b4db1a1b91160995415203 (commit) via f7e1f2df74b599903a6fb2d2ace94c3f1ef06097 (commit) via 47cb10217a7bc4b97fa169a821db05f40bc2e51d (commit) from b6210907ea584095cdede663f695eb8afeecef14 (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 62e56496009796497665c1d06819c163589a3877 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 19:55:50 2009 -0800 rewrite 'unknown' command dispatching in C Rewrite the magical 'unknown' command in C as a Jim handler, allowing it to dispatch commands to any level in the tree. diff --git a/src/helper/command.c b/src/helper/command.c index 54bfb96..dd10965 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -853,6 +853,70 @@ COMMAND_HANDLER(handle_usage_command) return CALL_COMMAND_HANDLER(command_help_show, c, 0, false); } +static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, + struct command *head, struct command **out) +{ + if (0 == argc) + return argc; + struct command *c = command_find(head, Jim_GetString(argv[0], NULL)); + if (NULL == c) + return argc; + *out = c; + return command_unknown_find(--argc, ++argv, (*out)->children, out); +} + +static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + const char *cmd_name = Jim_GetString(argv[0], NULL); + script_debug(interp, cmd_name, argc - 1, argv + 1); + + struct command_context *cmd_ctx = current_command_context(); + struct command *c = cmd_ctx->commands; + int remaining = command_unknown_find(argc - 1, argv + 1, c, &c); + // if nothing could be consumed, then it's really an unknown command + if (remaining == argc - 1) + { + const char *cmd = Jim_GetString(argv[1], NULL); + LOG_ERROR("Unknown command:\n %s", cmd); + return JIM_OK; + } + + bool found = true; + Jim_Obj *const *start; + unsigned count; + if (c->handler) + { + // include the command name in the list + count = remaining + 1; + start = argv + (argc - remaining - 1); + } + else + { + c = command_find(cmd_ctx->commands, "help"); + if (NULL == c) + { + LOG_ERROR("unknown command, but help is missing too"); + return JIM_ERR; + } + count = argc - remaining; + start = argv; + found = false; + } + + unsigned nwords; + const char **words = script_command_args_alloc(count, start, &nwords); + if (NULL == words) + return JIM_ERR; + + int retval = run_command(cmd_ctx, c, words, nwords); + + script_command_args_free(words, nwords); + + if (!found && ERROR_OK == retval) + retval = ERROR_FAIL; + + return retval; +} int help_add_command(struct command_context *cmd_ctx, struct command *parent, const char *cmd_name, const char *help_text, const char *usage) @@ -1032,6 +1096,7 @@ struct command_context* command_init(const char *startup_tcl) Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS", Jim_NewStringObj(interp, HostOs , strlen(HostOs))); + Jim_CreateCommand(interp, "unknown", &command_unknown, NULL, NULL); Jim_CreateCommand(interp, "ocd_find", jim_find, NULL, NULL); Jim_CreateCommand(interp, "echo", jim_echo, NULL, NULL); Jim_CreateCommand(interp, "capture", jim_capture, NULL, NULL); diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 845198a..ede8cdb 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -44,23 +44,6 @@ proc cmd_help {cmdname h indent} { } } -# If a fn is unknown to Tcl, we try to execute it as an OpenOCD command -# -# We also support two level commands. "flash banks" is translated to -# flash_banks -proc unknown {args} { - # do the name mangling from "flash banks" to "flash_banks" - if {[llength $args]>=2} { - set cmd_name "[lindex $args 0]_[lindex $args 1]" - if {[catch {info body $cmd_name}]==0} { - # the command exists, try it... - return [eval "$cmd_name [lrange $args 2 end]"] - } - } - # This really is an unknown command. - return -code error "Unknown command: $args" -} - # Try flipping / and \ to find file if the filename does not # match the precise spelling proc find {filename} { commit 769fbfa058946e1581d5f9ad75d17947d1ee9ff1 Author: Zachary T Welch <zw...@su...> Date: Sun Nov 22 01:48:55 2009 -0800 add public API for locating commands Allow other modules to find a command, primarily for the purpose of registering and unregistering subcommands. diff --git a/src/helper/command.c b/src/helper/command.c index af481cd..54bfb96 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -193,6 +193,16 @@ static struct command *command_find(struct command *head, const char *name) } return NULL; } +struct command *command_find_in_context(struct command_context *cmd_ctx, + const char *name) +{ + return command_find(cmd_ctx->commands, name); +} +struct command *command_find_in_parent(struct command *parent, + const char *name) +{ + return command_find(parent->children, name); +} /** * Add the command into the linked list, sorted by name. diff --git a/src/helper/command.h b/src/helper/command.h index 6e3e93a..2edeca9 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -281,6 +281,11 @@ int unregister_command(struct command_context *cmd_ctx, int unregister_all_commands(struct command_context *cmd_ctx, struct command *parent); +struct command *command_find_in_context(struct command_context *cmd_ctx, + const char *name); +struct command *command_find_in_parent(struct command *parent, + const char *name); + void command_set_output_handler(struct command_context* context, command_output_handler_t output_handler, void *priv); commit 4c54c27da774f8035a04f3b091fcfc5661253a0e Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 20:00:37 2009 -0800 refactor script_command context grabbing Move command context acquisition to current_command_context() for re-use. diff --git a/src/helper/command.c b/src/helper/command.c index b81d2d1..af481cd 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -108,11 +108,24 @@ static const char **script_command_args_alloc( return words; } +static struct command_context *current_command_context(void) +{ + /* grab the command context from the associated data */ + struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); + if (NULL == cmd_ctx) + { + /* Tcl can invoke commands directly instead of via command_run_line(). This would + * happen when the Jim Tcl interpreter is provided by eCos. + */ + cmd_ctx = global_cmd_ctx; + } + return cmd_ctx; +} + static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { /* the private data is stashed in the interp structure */ struct command *c; - struct command_context *context; int retval; /* DANGER!!!! be careful what we invoke here, since interp->cmdPrivData might @@ -136,16 +149,6 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (NULL == words) return JIM_ERR; - /* grab the command context from the associated data */ - context = Jim_GetAssocData(interp, "context"); - if (context == NULL) - { - /* Tcl can invoke commands directly instead of via command_run_line(). This would - * happen when the Jim Tcl interpreter is provided by eCos. - */ - context = global_cmd_ctx; - } - /* capture log output and return it */ Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); /* a garbage collect can happen, so we need a reference count to this object */ @@ -153,7 +156,8 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) log_add_callback(tcl_output, tclOutput); - retval = run_command(context, c, (const char **)words, nwords); + struct command_context *cmd_ctx = current_command_context(); + retval = run_command(cmd_ctx, c, (const char **)words, nwords); log_remove_callback(tcl_output, tclOutput); commit 60ba4641d61ba65943ac7a8c800e82d6665ee11f Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 13:59:51 2009 -0800 add command registration chaining Adds the ability to chain registration structures. Modules can define a command with the 'chain' and 'num_chain' fields defined in their registration table, and the register_commands() function will initialize these commands. If the registration record creates a new command, then the chained commands are created under it; otherwise, they are created in the same context as the other commands (i.e. the parent argument). diff --git a/src/helper/command.c b/src/helper/command.c index 9cc996c..b81d2d1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -331,18 +331,36 @@ struct command* register_command(struct command_context *context, int register_commands(struct command_context *cmd_ctx, struct command *parent, const struct command_registration *cmds) { + int retval = ERROR_OK; unsigned i; - for (i = 0; cmds[i].name; i++) + for (i = 0; cmds[i].name || cmds[i].chain; i++) { - struct command *c = register_command(cmd_ctx, parent, cmds + i); - if (NULL != c) - continue; + const struct command_registration *cr = cmds + i; + struct command *c = NULL; + if (NULL != cr->name) + { + c = register_command(cmd_ctx, parent, cr); + if (NULL == c) + { + retval = ERROR_FAIL; + break; + } + } + if (NULL != cr->chain) + { + struct command *p = c ? : parent; + retval = register_commands(cmd_ctx, p, cr->chain); + if (ERROR_OK != retval) + break; + } + } + if (ERROR_OK != retval) + { for (unsigned j = 0; j < i; j++) unregister_command(cmd_ctx, parent, cmds[j].name); - return ERROR_FAIL; } - return ERROR_OK; + return retval; } int unregister_all_commands(struct command_context *context, diff --git a/src/helper/command.h b/src/helper/command.h index 7baa92d..6e3e93a 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -202,10 +202,18 @@ struct command_registration { const char *help; /// a string listing the options and arguments, required or optional const char *usage; + + /** + * If non-NULL, the commands in @c chain will be registered in + * the same context and scope of this registration record. + * This allows modules to inherit lists commands from other + * modules. + */ + const struct command_registration *chain; }; /// Use this as the last entry in an array of command_registration records. -#define COMMAND_REGISTRATION_DONE { .name = NULL } +#define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL } /** * Register a command @c handler that can be called from scripts during @@ -238,7 +246,10 @@ struct command* register_command(struct command_context *cmd_ctx, /** * Register one or more commands in the specified context, as children - * of @c parent (or top-level commends, if NULL). + * of @c parent (or top-level commends, if NULL). In a registration's + * record contains a non-NULL @c chain member and name is NULL, the + * commands on the chain will be registered in the same context. + * Otherwise, the chained commands are added as children of the command. * * @param cmd_ctx The command_context in which to register the command. * @param parent Register this command as a child of this, or NULL to commit 607634f967cf25630860794847dea770eb17a8f4 Author: Zachary T Welch <zw...@su...> Date: Sat Nov 21 13:33:32 2009 -0800 more command registration refactoring Split out the handler registration into its own function, and add a few obviously missing NULL pointer error checking. diff --git a/src/helper/command.c b/src/helper/command.c index 28952fd..9cc996c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -266,6 +266,38 @@ static void command_free(struct command *c) free(c); } +static int register_command_handler(struct command *c) +{ + int retval = -ENOMEM; + const char *full_name = command_name(c, '_'); + if (NULL == full_name) + return retval; + + const char *ocd_name = alloc_printf("ocd_%s", full_name); + if (NULL == full_name) + goto free_full_name; + + Jim_CreateCommand(interp, ocd_name, script_command, c, NULL); + free((void *)ocd_name); + + /* we now need to add an overrideable proc */ + const char *override_name = alloc_printf("proc %s {args} {" + "if {[catch {eval ocd_%s $args}] == 0} " + "{return \"\"} else {return -code error}}", + full_name, full_name); + if (NULL == full_name) + goto free_full_name; + + Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__); + free((void *)override_name); + + retval = ERROR_OK; + +free_full_name: + free((void *)full_name); + return retval; +} + struct command* register_command(struct command_context *context, struct command *parent, const struct command_registration *cr) { @@ -287,22 +319,12 @@ struct command* register_command(struct command_context *context, if (NULL == c || NULL == c->handler) return c; - const char *full_name = command_name(c, '_'); - - const char *ocd_name = alloc_printf("ocd_%s", full_name); - Jim_CreateCommand(interp, ocd_name, script_command, c, NULL); - free((void *)ocd_name); - - /* we now need to add an overrideable proc */ - const char *override_name = alloc_printf("proc %s {args} {" - "if {[catch {eval ocd_%s $args}] == 0} " - "{return \"\"} else {return -code error}}", - full_name, full_name); - Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__); - free((void *)override_name); - - free((void *)full_name); - + int retval = register_command_handler(c); + if (ERROR_OK != retval) + { + unregister_command(context, parent, name); + c = NULL; + } return c; } commit 25a7ac2c756c78603c9c99d06f55717440409a23 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 13:36:07 2009 -0800 command: use register_commands for handlers Use register_commands() to register low-level command handlers, adding a builtin_command_handlers declaration that is easy to understand. Splits help and usage information into their appropriate fields. diff --git a/src/helper/command.c b/src/helper/command.c index df4667b..28952fd 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -900,6 +900,39 @@ COMMAND_HANDLER(handle_sleep_command) return ERROR_OK; } +static const struct command_registration command_builtin_handlers[] = { + { + .name = "add_help_text", + .handler = &handle_help_add_command, + .mode = COMMAND_ANY, + .help = "add new command help text", + .usage = "<command> [...] <help_text>]", + }, + { + .name = "sleep", + .handler = &handle_sleep_command, + .mode = COMMAND_ANY, + .help = "sleep for n milliseconds. " + "\"busy\" will busy wait", + .usage = "<n> [busy]", + }, + { + .name = "help", + .handler = &handle_help_command, + .mode = COMMAND_ANY, + .help = "show built-in command help", + .usage = "[<command_name> ...]", + }, + { + .name = "usage", + .handler = &handle_usage_command, + .mode = COMMAND_ANY, + .help = "show command usage", + .usage = "[<command_name> ...]", + }, + COMMAND_REGISTRATION_DONE +}; + struct command_context* command_init(const char *startup_tcl) { struct command_context* context = malloc(sizeof(struct command_context)); @@ -959,10 +992,7 @@ struct command_context* command_init(const char *startup_tcl) interp->cb_fflush = openocd_jim_fflush; interp->cb_fgets = openocd_jim_fgets; - COMMAND_REGISTER(context, NULL, "add_help_text", - handle_help_add_command, COMMAND_ANY, - "<command> [...] <help_text>] - " - "add new command help text"); + register_commands(context, NULL, command_builtin_handlers); #if !BUILD_ECOSBOARD Jim_EventLoopOnLoad(interp); @@ -976,19 +1006,6 @@ struct command_context* command_init(const char *startup_tcl) } Jim_DeleteAssocData(interp, "context"); - COMMAND_REGISTER(context, NULL, "sleep", - handle_sleep_command, COMMAND_ANY, - "<n> [busy] - sleep for n milliseconds. " - "\"busy\" means busy wait"); - - COMMAND_REGISTER(context, NULL, "help", - &handle_help_command, COMMAND_ANY, - "[<command_name> ...] - show built-in command help"); - COMMAND_REGISTER(context, NULL, "usage", - &handle_usage_command, COMMAND_ANY, - "[<command_name> ...] | " - "show command usage"); - return context; } commit d107f71c5079dbe2a023276367b805397d1245c4 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 14:07:28 2009 -0800 add command usage, separate from help Adds the usage command, to display usage information for commands. The output for this command will remain erronenously empty until commands are updated to use these new coventions. diff --git a/src/helper/command.c b/src/helper/command.c index 51b3f9f..df4667b 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -226,7 +226,7 @@ static struct command **command_list_for_parent( static struct command *command_new(struct command_context *cmd_ctx, struct command *parent, const char *name, command_handler_t handler, enum command_mode mode, - const char *help) + const char *help, const char *usage) { assert(name); @@ -236,6 +236,8 @@ static struct command *command_new(struct command_context *cmd_ctx, c->name = strdup(name); if (help) c->help = strdup(help); + if (usage) + c->usage = strdup(usage); c->parent = parent; c->handler = handler; c->mode = mode; @@ -259,6 +261,8 @@ static void command_free(struct command *c) free(c->name); if (c->help) free((void*)c->help); + if (c->usage) + free((void*)c->usage); free(c); } @@ -278,7 +282,7 @@ struct command* register_command(struct command_context *context, return c; } - c = command_new(context, parent, name, cr->handler, cr->mode, cr->help); + c = command_new(context, parent, name, cr->handler, cr->mode, cr->help, cr->usage); /* if allocation failed or it is a placeholder (no handler), we're done */ if (NULL == c || NULL == c->handler) return c; @@ -737,41 +741,67 @@ static COMMAND_HELPER(command_help_find, struct command *head, return CALL_COMMAND_HANDLER(command_help_find, (*out)->children, out); } -static COMMAND_HELPER(command_help_show, struct command *c, unsigned n); +static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, + bool show_help); -static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n) +static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n, + bool show_help) { for (struct command *c = head; NULL != c; c = c->next) - CALL_COMMAND_HANDLER(command_help_show, c, n); + CALL_COMMAND_HANDLER(command_help_show, c, n, show_help); return ERROR_OK; } -static COMMAND_HELPER(command_help_show, struct command *c, unsigned n) +static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, + bool show_help) { - command_run_linef(CMD_CTX, "cmd_help {%s} {%s} %d", command_name(c, ' '), - c->help ? : "no help available", n); + const char *usage = c->usage ? : ""; + const char *help = ""; + const char *sep = ""; + if (show_help && c->help) + { + help = c->help ? : ""; + sep = c->usage ? " | " : ""; + } + command_run_linef(CMD_CTX, "cmd_help {%s} {%s%s%s} %d", + command_name(c, ' '), usage, sep, help, n); if (++n >= 2) return ERROR_OK; - return CALL_COMMAND_HANDLER(command_help_show_list, c->children, n); + return CALL_COMMAND_HANDLER(command_help_show_list, + c->children, n, show_help); } COMMAND_HANDLER(handle_help_command) { struct command *c = CMD_CTX->commands; if (0 == CMD_ARGC) - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0); + return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, true); + + int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); + if (ERROR_OK != retval) + return retval; + + return CALL_COMMAND_HANDLER(command_help_show, c, 0, true); +} + +COMMAND_HANDLER(handle_usage_command) +{ + struct command *c = CMD_CTX->commands; + + if (0 == CMD_ARGC) + return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, false); int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c); if (ERROR_OK != retval) return retval; - return CALL_COMMAND_HANDLER(command_help_show, c, 0); + return CALL_COMMAND_HANDLER(command_help_show, c, 0, false); } int help_add_command(struct command_context *cmd_ctx, struct command *parent, - const char *cmd_name, const char *help_text) + const char *cmd_name, const char *help_text, const char *usage) { struct command **head = command_list_for_parent(cmd_ctx, parent); struct command *nc = command_find(*head, cmd_name); @@ -782,6 +812,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, .name = cmd_name, .mode = COMMAND_ANY, .help = help_text, + .usage = usage, }; nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) @@ -830,7 +861,7 @@ COMMAND_HANDLER(handle_help_add_command) if (ERROR_OK != retval) return retval; } - return help_add_command(CMD_CTX, c, cmd_name, help_text); + return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL); } /* sleep command sleeps for <n> miliseconds @@ -953,6 +984,10 @@ struct command_context* command_init(const char *startup_tcl) COMMAND_REGISTER(context, NULL, "help", &handle_help_command, COMMAND_ANY, "[<command_name> ...] - show built-in command help"); + COMMAND_REGISTER(context, NULL, "usage", + &handle_usage_command, COMMAND_ANY, + "[<command_name> ...] | " + "show command usage"); return context; } @@ -989,7 +1024,7 @@ void register_jim(struct command_context *cmd_ctx, const char *name, Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, name, -1)); - help_add_command(cmd_ctx, NULL, name, help); + help_add_command(cmd_ctx, NULL, name, help, NULL); } #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \ diff --git a/src/helper/command.h b/src/helper/command.h index 1afaeea..7baa92d 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -160,6 +160,7 @@ struct command { char *name; const char *help; + const char *usage; struct command *parent; struct command *children; command_handler_t handler; @@ -199,6 +200,8 @@ struct command_registration { command_handler_t handler; enum command_mode mode; const char *help; + /// a string listing the options and arguments, required or optional + const char *usage; }; /// Use this as the last entry in an array of command_registration records. commit 2461855494cd045567c15c502ba215caffb37ce3 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 12:46:06 2009 -0800 add register_commands for batch registration The register_commands API takes multiple commands in one call, allowing modules to declare and pass a much simpler (and more explicit) array of command_registration records. diff --git a/src/helper/command.c b/src/helper/command.c index 3df60b6..51b3f9f 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -302,6 +302,23 @@ struct command* register_command(struct command_context *context, return c; } +int register_commands(struct command_context *cmd_ctx, struct command *parent, + const struct command_registration *cmds) +{ + unsigned i; + for (i = 0; cmds[i].name; i++) + { + struct command *c = register_command(cmd_ctx, parent, cmds + i); + if (NULL != c) + continue; + + for (unsigned j = 0; j < i; j++) + unregister_command(cmd_ctx, parent, cmds[j].name); + return ERROR_FAIL; + } + return ERROR_OK; +} + int unregister_all_commands(struct command_context *context, struct command *parent) { diff --git a/src/helper/command.h b/src/helper/command.h index b57ca75..1afaeea 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -201,6 +201,9 @@ struct command_registration { const char *help; }; +/// Use this as the last entry in an array of command_registration records. +#define COMMAND_REGISTRATION_DONE { .name = NULL } + /** * Register a command @c handler that can be called from scripts during * the execution @c mode specified. @@ -231,6 +234,22 @@ struct command* register_command(struct command_context *cmd_ctx, }) /** + * Register one or more commands in the specified context, as children + * of @c parent (or top-level commends, if NULL). + * + * @param cmd_ctx The command_context in which to register the command. + * @param parent Register this command as a child of this, or NULL to + * register a top-level command. + * @param cmds Pointer to an array of command_registration records that + * contains the desired command parameters. The last record must have + * NULL for all fields. + * @returns ERROR_OK on success; ERROR_FAIL if any registration fails. + */ +int register_commands(struct command_context *cmd_ctx, struct command *parent, + const struct command_registration *cmds); + + +/** * Unregisters command @c name from the given context, @c cmd_ctx. * @param cmd_ctx The context of the registered command. * @param parent The parent of the given command, or NULL. commit 69076057dde9f4336b54fb4da677da8fe5da66bd Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 11:23:34 2009 -0800 add struct command_registration Add a structure to encapsulate command registration information, rather than passing them all as parameters. Enables further API changes that require additional required or optional parameters. Updates the register_command API and COMMAND_REGISTER macro to use it, along with their documentation. diff --git a/src/helper/command.c b/src/helper/command.c index 0561c6c..3df60b6 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -263,13 +263,12 @@ static void command_free(struct command *c) } struct command* register_command(struct command_context *context, - struct command *parent, const char *name, - command_handler_t handler, enum command_mode mode, - const char *help) + struct command *parent, const struct command_registration *cr) { - if (!context || !name) + if (!context || !cr->name) return NULL; + const char *name = cr->name; struct command **head = command_list_for_parent(context, parent); struct command *c = command_find(*head, name); if (NULL != c) @@ -279,7 +278,7 @@ struct command* register_command(struct command_context *context, return c; } - c = command_new(context, parent, name, handler, mode, help); + c = command_new(context, parent, name, cr->handler, cr->mode, cr->help); /* if allocation failed or it is a placeholder (no handler), we're done */ if (NULL == c || NULL == c->handler) return c; @@ -762,8 +761,12 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (NULL == nc) { // add a new command with help text - nc = register_command(cmd_ctx, parent, cmd_name, - NULL, COMMAND_ANY, help_text); + struct command_registration cr = { + .name = cmd_name, + .mode = COMMAND_ANY, + .help = help_text, + }; + nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) { LOG_ERROR("failed to add '%s' help text", cmd_name); diff --git a/src/helper/command.h b/src/helper/command.h index 25c0501..b57ca75 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -177,13 +177,9 @@ struct command */ char *command_name(struct command *c, char delim); -/** - * Register a command @c handler that can be called from scripts during - * the execution @c mode specified. - * - * If @c parent is non-NULL, the new command will be registered as a - * sub-command under it; otherwise, it will be available as a top-level - * command. +/* + * Commands should be registered by filling in one or more of these + * structures and passing them to register_command(). * * A conventioal format should be used for help strings, to provide both * usage and basic information: @@ -191,25 +187,48 @@ char *command_name(struct command *c, char delim); * "@<options@> ... - some explanation text" * @endcode * - * @param cmd_ctx The command_context in which to register the command. - * @param parent Register this command as a child of this, or NULL to - * register a top-level command. * @param name The name of the command to register, which must not have - * been registered previously. + * been registered previously in the intended context. * @param handler The callback function that will be called. If NULL, * then the command serves as a placeholder for its children or a script. * @param mode The command mode(s) in which this command may be run. * @param help The help text that will be displayed to the user. + */ +struct command_registration { + const char *name; + command_handler_t handler; + enum command_mode mode; + const char *help; +}; + +/** + * Register a command @c handler that can be called from scripts during + * the execution @c mode specified. + * + * If @c parent is non-NULL, the new command will be registered as a + * sub-command under it; otherwise, it will be available as a top-level + * command. + * + * @param cmd_ctx The command_context in which to register the command. + * @param parent Register this command as a child of this, or NULL to + * register a top-level command. + * @param rec A command_registration record that contains the desired + * command parameters. * @returns The new command, if successful; otherwise, NULL. */ struct command* register_command(struct command_context *cmd_ctx, - struct command *parent, const char *name, - command_handler_t handler, enum command_mode mode, - const char *help); + struct command *parent, const struct command_registration *rec); -// provide a simple shim, for now; allows parameters to be migrated #define COMMAND_REGISTER(_cmd_ctx, _parent, _name, _handler, _mode, _help) \ - register_command(_cmd_ctx, _parent, _name, _handler, _mode, _help) + ({ \ + struct command_registration cr = { \ + .name = _name, \ + .handler = _handler, \ + .mode = _mode, \ + .help = _help, \ + }; \ + register_command(_cmd_ctx, _parent, &cr); \ + }) /** * Unregisters command @c name from the given context, @c cmd_ctx. commit 833e7f5248778bcb31b4db1a1b91160995415203 Author: Zachary T Welch <zw...@su...> Date: Fri Nov 20 11:26:35 2009 -0800 use COMMAND_REGISTER macro Replaces direct calls to register_command() with a macro, to allow its parameters to be changed and callers updated in phases. diff --git a/src/ecosboard.c b/src/ecosboard.c index 58520c3..2789464 100644 --- a/src/ecosboard.c +++ b/src/ecosboard.c @@ -1091,7 +1091,7 @@ int main(int argc, char *argv[]) #ifdef CYGPKG_PROFILE_GPROF - register_command(cmd_ctx, NULL, "ecosboard_profile", eCosBoard_handle_eCosBoard_profile_command, + COMMAND_REGISTER(cmd_ctx, NULL, "ecosboard_profile", eCosBoard_handle_eCosBoard_profile_command, COMMAND_ANY, NULL); #endif diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c index 195da91..d8460b0 100644 --- a/src/flash/at91sam3.c +++ b/src/flash/at91sam3.c @@ -2478,18 +2478,18 @@ sam3_register_commands(struct command_context *cmd_ctx) if (!sam3_registered) { sam3_registered++; - pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, pCmd, + pCmd = COMMAND_REGISTER(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, pCmd, "gpnvm", sam3_handle_gpnvm_command, COMMAND_EXEC, "at91sam3 gpnvm [action [<BIT>], by default 'show', otherwise set | clear BIT"); - register_command(cmd_ctx, pCmd, + COMMAND_REGISTER(cmd_ctx, pCmd, "info", sam3_handle_info_command, COMMAND_EXEC, "at91sam3 info - print information about the current sam3 chip"); - register_command(cmd_ctx, pCmd, + COMMAND_REGISTER(cmd_ctx, pCmd, "slowclk", sam3_handle_slowclk_command, COMMAND_EXEC, diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index 3e5dbdd..1665b91 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -1180,10 +1180,10 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) static int at91sam7_register_commands(struct command_context *cmd_ctx) { - struct command *at91sam7_cmd = register_command(cmd_ctx, NULL, "at91sam7", + struct command *at91sam7_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "at91sam7", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, at91sam7_cmd, "gpnvm", + COMMAND_REGISTER(cmd_ctx, at91sam7_cmd, "gpnvm", at91sam7_handle_gpnvm_command, COMMAND_EXEC, "at91sam7 gpnvm <bit> set | clear, " "set or clear one gpnvm bit"); diff --git a/src/flash/avrf.c b/src/flash/avrf.c index 356c404..692992f 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -451,10 +451,10 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command) static int avrf_register_commands(struct command_context *cmd_ctx) { - struct command *avr_cmd = register_command(cmd_ctx, NULL, "avr", + struct command *avr_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "avr", NULL, COMMAND_ANY, "avr flash specific commands"); - register_command(cmd_ctx, avr_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, avr_cmd, "mass_erase", avrf_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); diff --git a/src/flash/cfi.c b/src/flash/cfi.c index 59c9c6c..e743fe9 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -592,9 +592,9 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size) static int cfi_register_commands(struct command_context *cmd_ctx) { /*struct command *cfi_cmd = */ - register_command(cmd_ctx, NULL, "cfi", NULL, COMMAND_ANY, "flash bank cfi <base> <size> <chip_width> <bus_width> <targetNum> [jedec_probe/x16_as_x8]"); + COMMAND_REGISTER(cmd_ctx, NULL, "cfi", NULL, COMMAND_ANY, "flash bank cfi <base> <size> <chip_width> <bus_width> <targetNum> [jedec_probe/x16_as_x8]"); /* - register_command(cmd_ctx, cfi_cmd, "part_id", cfi_handle_part_id_command, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, cfi_cmd, "part_id", cfi_handle_part_id_command, COMMAND_EXEC, "print part id of cfi flash bank <num>"); */ return ERROR_OK; diff --git a/src/flash/ecos.c b/src/flash/ecos.c index 863c12b..381f858 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -338,7 +338,7 @@ static int ecosflash_probe(struct flash_bank *bank) static int ecosflash_register_commands(struct command_context *cmd_ctx) { - register_command(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, NULL, "ecosflash", NULL, COMMAND_ANY, NULL); return ERROR_OK; } diff --git a/src/flash/flash.c b/src/flash/flash.c index e2136b7..7bc74ab 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -1280,42 +1280,42 @@ int flash_init_drivers(struct command_context *cmd_ctx) if (!flash_banks) return ERROR_OK; - register_command(cmd_ctx, flash_cmd, "info", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC, "print info about flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "probe", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC, "identify flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "erase_check", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_check", handle_flash_erase_check_command, COMMAND_EXEC, "check erase state of sectors in flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "protect_check", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect_check", handle_flash_protect_check_command, COMMAND_EXEC, "check protection state of sectors in flash bank <num>"); - register_command(cmd_ctx, flash_cmd, "erase_sector", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_sector", handle_flash_erase_command, COMMAND_EXEC, "erase sectors at <bank> <first> <last>"); - register_command(cmd_ctx, flash_cmd, "erase_address", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "erase_address", handle_flash_erase_address_command, COMMAND_EXEC, "erase address range <address> <length>"); - register_command(cmd_ctx, flash_cmd, "fillw", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillw", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern (no autoerase) <address> <word_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "fillh", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillh", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern <address> <halfword_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "fillb", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "fillb", handle_flash_fill_command, COMMAND_EXEC, "fill with pattern <address> <byte_pattern> <count>"); - register_command(cmd_ctx, flash_cmd, "write_bank", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_bank", handle_flash_write_bank_command, COMMAND_EXEC, "write binary data to <bank> <file> <offset>"); - register_command(cmd_ctx, flash_cmd, "write_image", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC, "write_image [erase] [unlock] <file> [offset] [type]"); - register_command(cmd_ctx, flash_cmd, "protect", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "protect", handle_flash_protect_command, COMMAND_EXEC, "set protection of sectors at <bank> <first> <last> <on | off>"); @@ -1324,10 +1324,10 @@ int flash_init_drivers(struct command_context *cmd_ctx) int flash_register_commands(struct command_context *cmd_ctx) { - flash_cmd = register_command(cmd_ctx, NULL, "flash", + flash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, flash_cmd, "bank", + COMMAND_REGISTER(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash bank <driver> <base> <size> " "<chip_width> <bus_width> <target> [driver_options ...]"); diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index b60c6cf..4a934c0 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -778,10 +778,10 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command) static int lpc2000_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2000_cmd = register_command(cmd_ctx, NULL, "lpc2000", + struct command *lpc2000_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2000", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, lpc2000_cmd, "part_id", + COMMAND_REGISTER(cmd_ctx, lpc2000_cmd, "part_id", lpc2000_handle_part_id_command, COMMAND_EXEC, "print part id of lpc2000 flash bank <num>"); diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c index 465d776..c7f1b3a 100644 --- a/src/flash/lpc2900.c +++ b/src/flash/lpc2900.c @@ -954,60 +954,36 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command) */ static int lpc2900_register_commands(struct command_context *cmd_ctx) { - struct command *lpc2900_cmd = register_command(cmd_ctx, NULL, "lpc2900", + struct command *lpc2900_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc2900", NULL, COMMAND_ANY, NULL); - register_command( - cmd_ctx, - lpc2900_cmd, - "signature", - lpc2900_handle_signature_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "signature", + &lpc2900_handle_signature_command, COMMAND_EXEC, "<bank> | " - "print device signature of flash bank"); - - register_command( - cmd_ctx, - lpc2900_cmd, - "read_custom", - lpc2900_handle_read_custom_command, - COMMAND_EXEC, + "print device signature of flash bank"); + + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "read_custom", + &lpc2900_handle_read_custom_command, COMMAND_EXEC, "<bank> <filename> | " "read customer information from index sector to file"); - register_command( - cmd_ctx, - lpc2900_cmd, - "password", - lpc2900_handle_password_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "password", + &lpc2900_handle_password_command, COMMAND_EXEC, "<bank> <password> | " "enter password to enable 'dangerous' options"); - register_command( - cmd_ctx, - lpc2900_cmd, - "write_custom", - lpc2900_handle_write_custom_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "write_custom", + &lpc2900_handle_write_custom_command, COMMAND_EXEC, "<bank> <filename> [<type>] | " "write customer info from file to index sector"); - register_command( - cmd_ctx, - lpc2900_cmd, - "secure_sector", - lpc2900_handle_secure_sector_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_sector", + &lpc2900_handle_secure_sector_command, COMMAND_EXEC, "<bank> <first> <last> | " "activate sector security for a range of sectors"); - register_command( - cmd_ctx, - lpc2900_cmd, - "secure_jtag", - lpc2900_handle_secure_jtag_command, - COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, "secure_jtag", + &lpc2900_handle_secure_jtag_command, COMMAND_EXEC, "<bank> <level> | " "activate JTAG security"); diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 61bef90..801607d 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -875,9 +875,9 @@ COMMAND_HANDLER(handle_lpc3180_select_command) static int lpc3180_register_commands(struct command_context *cmd_ctx) { - struct command *lpc3180_cmd = register_command(cmd_ctx, NULL, "lpc3180", NULL, COMMAND_ANY, "commands specific to the LPC3180 NAND flash controllers"); + struct command *lpc3180_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "lpc3180", NULL, COMMAND_ANY, "commands specific to the LPC3180 NAND flash controllers"); - register_command(cmd_ctx, lpc3180_cmd, "select", handle_lpc3180_select_command, COMMAND_EXEC, "select <'mlc'|'slc'> controller (default is mlc)"); + COMMAND_REGISTER(cmd_ctx, lpc3180_cmd, "select", handle_lpc3180_select_command, COMMAND_EXEC, "select <'mlc'|'slc'> controller (default is mlc)"); return ERROR_OK; } diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 2a1fbe5..a4a45dc 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -1271,12 +1271,12 @@ COMMAND_HANDLER(mg_config_cmd) int mflash_init_drivers(struct command_context *cmd_ctx) { if (mflash_bank) { - register_command(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL); - register_command(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "probe", mg_probe_cmd, COMMAND_EXEC, NULL); + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "write", mg_write_cmd, COMMAND_EXEC, "mflash write <num> <file> <address>"); - register_command(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "dump", mg_dump_cmd, COMMAND_EXEC, "mflash dump <num> <file> <address> <size>"); - register_command(cmd_ctx, mflash_cmd, "config", mg_config_cmd, + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "config", mg_config_cmd, COMMAND_EXEC, "mflash config <num> <stage>"); } @@ -1325,8 +1325,8 @@ COMMAND_HANDLER(mg_bank_cmd) int mflash_register_commands(struct command_context *cmd_ctx) { - mflash_cmd = register_command(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG, + mflash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "mflash", NULL, COMMAND_ANY, NULL); + COMMAND_REGISTER(cmd_ctx, mflash_cmd, "bank", mg_bank_cmd, COMMAND_CONFIG, "mflash bank <soc> <base> <RST pin> <target #>"); return ERROR_OK; } diff --git a/src/flash/nand.c b/src/flash/nand.c index 77aa3e5..2438ddd 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -281,13 +281,13 @@ COMMAND_HANDLER(handle_nand_device_command) int nand_register_commands(struct command_context *cmd_ctx) { - nand_cmd = register_command(cmd_ctx, NULL, "nand", + nand_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands"); - register_command(cmd_ctx, nand_cmd, "device", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "device", &handle_nand_device_command, COMMAND_CONFIG, "defines a new NAND bank"); - register_command(cmd_ctx, nand_cmd, "drivers", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "drivers", &handle_nand_list_drivers, COMMAND_ANY, "lists available NAND drivers"); @@ -1705,36 +1705,36 @@ int nand_init(struct command_context *cmd_ctx) if (!nand_devices) return ERROR_OK; - register_command(cmd_ctx, nand_cmd, "list", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "list", handle_nand_list_command, COMMAND_EXEC, "list configured NAND flash devices"); - register_command(cmd_ctx, nand_cmd, "info", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "info", handle_nand_info_command, COMMAND_EXEC, "print info about NAND flash device <num>"); - register_command(cmd_ctx, nand_cmd, "probe", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "probe", handle_nand_probe_command, COMMAND_EXEC, "identify NAND flash device <num>"); - register_command(cmd_ctx, nand_cmd, "check_bad_blocks", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "check_bad_blocks", handle_nand_check_bad_blocks_command, COMMAND_EXEC, "check NAND flash device <num> for bad blocks [<offset> <length>]"); - register_command(cmd_ctx, nand_cmd, "erase", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "erase", handle_nand_erase_command, COMMAND_EXEC, "erase blocks on NAND flash device <num> [<offset> <length>]"); - register_command(cmd_ctx, nand_cmd, "dump", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "dump", handle_nand_dump_command, COMMAND_EXEC, "dump from NAND flash device <num> <filename> " "<offset> <length> [oob_raw | oob_only]"); - register_command(cmd_ctx, nand_cmd, "verify", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "verify", &handle_nand_verify_command, COMMAND_EXEC, "verify NAND flash device <num> <filename> <offset> " "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - register_command(cmd_ctx, nand_cmd, "write", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "write", handle_nand_write_command, COMMAND_EXEC, "write to NAND flash device <num> <filename> <offset> " "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]"); - register_command(cmd_ctx, nand_cmd, "raw_access", + COMMAND_REGISTER(cmd_ctx, nand_cmd, "raw_access", handle_nand_raw_access_command, COMMAND_EXEC, "raw access to NAND flash device <num> ['enable'|'disable']"); diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index fa5a4d6..c6d4615 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -885,20 +885,20 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) static int pic32mx_register_commands(struct command_context *cmd_ctx) { - struct command *pic32mx_cmd = register_command(cmd_ctx, NULL, "pic32mx", + struct command *pic32mx_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "pic32mx", NULL, COMMAND_ANY, "pic32mx flash specific commands"); #if 0 - register_command(cmd_ctx, pic32mx_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "lock", pic32mx_handle_lock_command, COMMAND_EXEC, "lock device"); - register_command(cmd_ctx, pic32mx_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "unlock", pic32mx_handle_unlock_command, COMMAND_EXEC, "unlock protected device"); #endif - register_command(cmd_ctx, pic32mx_cmd, "chip_erase", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "chip_erase", pic32mx_handle_chip_erase_command, COMMAND_EXEC, "erase device"); - register_command(cmd_ctx, pic32mx_cmd, "pgm_word", + COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, "pgm_word", pic32mx_handle_pgm_word_command, COMMAND_EXEC, "program a word"); return ERROR_OK; diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c index 32fa415..2d653ec 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -1163,10 +1163,10 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) static int stellaris_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = register_command(cmd_ctx, NULL, "stellaris", + struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stellaris", NULL, COMMAND_ANY, "stellaris flash specific commands"); - register_command(cmd_ctx, stm32x_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", stellaris_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); return ERROR_OK; diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index c96b49d..c628f18 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -1184,22 +1184,22 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) static int stm32x_register_commands(struct command_context *cmd_ctx) { - struct command *stm32x_cmd = register_command(cmd_ctx, NULL, "stm32x", + struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stm32x", NULL, COMMAND_ANY, "stm32x flash specific commands"); - register_command(cmd_ctx, stm32x_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "lock", stm32x_handle_lock_command, COMMAND_EXEC, "lock device"); - register_command(cmd_ctx, stm32x_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "unlock", stm32x_handle_unlock_command, COMMAND_EXEC, "unlock protected device"); - register_command(cmd_ctx, stm32x_cmd, "mass_erase", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase", stm32x_handle_mass_erase_command, COMMAND_EXEC, "mass erase device"); - register_command(cmd_ctx, stm32x_cmd, "options_read", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_read", stm32x_handle_options_read_command, COMMAND_EXEC, "read device option bytes"); - register_command(cmd_ctx, stm32x_cmd, "options_write", + COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "options_write", stm32x_handle_options_write_command, COMMAND_EXEC, "write device option bytes"); diff --git a/src/flash/str7x.c b/src/flash/str7x.c index b79dd17..b53ddf9 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -674,10 +674,10 @@ COMMAND_HANDLER(str7x_handle_disable_jtag_command) static int str7x_register_commands(struct command_context *cmd_ctx) { - struct command *str7x_cmd = register_command(cmd_ctx, NULL, "str7x", + struct command *str7x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str7x", NULL, COMMAND_ANY, "str7x flash specific commands"); - register_command(cmd_ctx, str7x_cmd, "disable_jtag", + COMMAND_REGISTER(cmd_ctx, str7x_cmd, "disable_jtag", str7x_handle_disable_jtag_command, COMMAND_EXEC, "disable jtag access"); diff --git a/src/flash/str9x.c b/src/flash/str9x.c index 3bb8970..6d556d9 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -678,10 +678,10 @@ COMMAND_HANDLER(str9x_handle_flash_config_command) static int str9x_register_commands(struct command_context *cmd_ctx) { - struct command *str9x_cmd = register_command(cmd_ctx, NULL, "str9x", + struct command *str9x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9x", NULL, COMMAND_ANY, "str9x flash commands"); - register_command(cmd_ctx, str9x_cmd, "flash_config", + COMMAND_REGISTER(cmd_ctx, str9x_cmd, "flash_config", str9x_handle_flash_config_command, COMMAND_EXEC, "configure str9 flash controller"); diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index f7c705e..7519413 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -1165,40 +1165,40 @@ COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command) static int str9xpec_register_commands(struct command_context *cmd_ctx) { - struct command *str9xpec_cmd = register_command(cmd_ctx, NULL, "str9xpec", + struct command *str9xpec_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "str9xpec", NULL, COMMAND_ANY, "str9xpec flash specific commands"); - register_command(cmd_ctx, str9xpec_cmd, "enable_turbo", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "enable_turbo", str9xpec_handle_flash_enable_turbo_command, COMMAND_EXEC, "enable str9xpec turbo mode"); - register_command(cmd_ctx, str9xpec_cmd, "disable_turbo", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "disable_turbo", str9xpec_handle_flash_disable_turbo_command, COMMAND_EXEC, "disable str9xpec turbo mode"); - register_command(cmd_ctx, str9xpec_cmd, "options_cmap", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_cmap", str9xpec_handle_flash_options_cmap_command, COMMAND_EXEC, "configure str9xpec boot sector"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdthd", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdthd", str9xpec_handle_flash_options_lvdthd_command, COMMAND_EXEC, "configure str9xpec lvd threshold"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdsel", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdsel", str9xpec_handle_flash_options_lvdsel_command, COMMAND_EXEC, "configure str9xpec lvd selection"); - register_command(cmd_ctx, str9xpec_cmd, "options_lvdwarn", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_lvdwarn", str9xpec_handle_flash_options_lvdwarn_command, COMMAND_EXEC, "configure str9xpec lvd warning"); - register_command(cmd_ctx, str9xpec_cmd, "options_read", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_read", str9xpec_handle_flash_options_read_command, COMMAND_EXEC, "read str9xpec options"); - register_command(cmd_ctx, str9xpec_cmd, "options_write", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "options_write", str9xpec_handle_flash_options_write_command, COMMAND_EXEC, "write str9xpec options"); - register_command(cmd_ctx, str9xpec_cmd, "lock", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "lock", str9xpec_handle_flash_lock_command, COMMAND_EXEC, "lock str9xpec device"); - register_command(cmd_ctx, str9xpec_cmd, "unlock", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "unlock", str9xpec_handle_flash_unlock_command, COMMAND_EXEC, "unlock str9xpec device"); - register_command(cmd_ctx, str9xpec_cmd, "part_id", + COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, "part_id", str9xpec_handle_part_id_command, COMMAND_EXEC, "print part id of str9xpec flash bank <num>"); diff --git a/src/flash/tms470.c b/src/flash/tms470.c index f6f3900..bf58f1d 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -819,11 +819,11 @@ static int tms470_erase_sector(struct flash_bank *bank, int sector) static int tms470_register_commands(struct command_context *cmd_ctx) { - struct command *tms470_cmd = register_command(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); + struct command *tms470_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "tms470", NULL, COMMAND_ANY, "applies to TI tms470 family"); - register_command(cmd_ctx, tms470_cmd, "flash_keyset", tms470_handle_flash_keyset_command, COMMAND_ANY, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); - register_command(cmd_ctx, tms470_cmd, "osc_megahertz", tms470_handle_osc_megahertz_command, COMMAND_ANY, "tms470 osc_megahertz <MHz>"); - register_command(cmd_ctx, tms470_cmd, "plldis", tms470_handle_plldis_command, COMMAND_ANY, "tms470 plldis <0/1>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "flash_keyset", tms470_handle_flash_keyset_command, COMMAND_ANY, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "osc_megahertz", tms470_handle_osc_megahertz_command, COMMAND_ANY, "tms470 osc_megahertz <MHz>"); + COMMAND_REGISTER(cmd_ctx, tms470_cmd, "plldis", tms470_handle_plldis_command, COMMAND_ANY, "tms470 plldis <0/1>"); return ERROR_OK; } diff --git a/src/hello.c b/src/hello.c index 2ab7eb5..8c97a40 100644 --- a/src/hello.c +++ b/src/hello.c @@ -56,17 +56,17 @@ COMMAND_HANDLER(handle_flag_command) 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", + struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "foo", NULL, COMMAND_ANY, "foo: command handler skeleton"); - register_command(cmd_ctx, cmd, "bar", + COMMAND_REGISTER(cmd_ctx, cmd, "bar", &handle_foo_command, COMMAND_ANY, "<address> [enable|disable] - an example command"); - register_command(cmd_ctx, cmd, "baz", + COMMAND_REGISTER(cmd_ctx, cmd, "baz", &handle_foo_command, COMMAND_ANY, "<address> [enable|disable] - a sample command"); - register_command(cmd_ctx, cmd, "flag", + COMMAND_REGISTER(cmd_ctx, cmd, "flag", &handle_flag_command, COMMAND_ANY, "[on|off] - set a flag"); @@ -103,7 +103,7 @@ int hello_register_commands(struct command_context *cmd_ctx) { foo_register_commands(cmd_ctx); - struct command *cmd = register_command(cmd_ctx, NULL, "hello", + struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, "hello", &handle_hello_command, COMMAND_ANY, "[<name>] - prints a warm welcome"); return cmd ? ERROR_OK : -ENOMEM; diff --git a/src/helper/command.c b/src/helper/command.c index f6c6b2d..0561c6c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -908,7 +908,7 @@ struct command_context* command_init(const char *startup_tcl) interp->cb_fflush = openocd_jim_fflush; interp->cb_fgets = openocd_jim_fgets; - register_command(context, NULL, "add_help_text", + COMMAND_REGISTER(context, NULL, "add_help_text", handle_help_add_command, COMMAND_ANY, "<command> [...] <help_text>] - " "add new command help text"); @@ -925,12 +925,12 @@ struct command_context* command_init(const char *startup_tcl) } Jim_DeleteAssocData(interp, "context"); - register_command(context, NULL, "sleep", + COMMAND_REGISTER(context, NULL, "sleep", handle_sleep_command, COMMAND_ANY, "<n> [busy] - sleep for n milliseconds. " "\"busy\" means busy wait"); - register_command(context, NULL, "help", + COMMAND_REGISTER(context, NULL, "help", &handle_help_command, COMMAND_ANY, "[<command_name> ...] - show built-in command help"); diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 3fb3014..52ecb9f 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -647,22 +647,22 @@ static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, int argc, int ioutil_init(struct command_context *cmd_ctx) { - register_command(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "rm", handle_rm_command, COMMAND_ANY, "remove file"); - register_command(cmd_ctx, NULL, "cat", handle_cat_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "cat", handle_cat_command, COMMAND_ANY, "display file content"); - register_command(cmd_ctx, NULL, "trunc", handle_trunc_command, COMMAND_ANY, + COMMAND_REGISTER(cmd_ctx, NULL, "trunc", handle_trunc_command, COMMAND_ANY, "truncate a file to 0 size"); - register_command(cmd_ctx, NULL, "cp", handle_cp_command, + COMMAND_REGISTER(cmd_ctx, NULL, "cp", handle_cp_command, COMMAND_ANY, "copy a file <from> <to>"); - register_command(cmd_ctx, NULL, "append_file", handle_append_command, + COMMAND_REGISTER(cmd_ctx, NULL, "append_file", handle_append_command, COMMAND_ANY, "append a variable number of strings to a file"); - register_command(cmd_ctx, NULL, "meminfo", handle_meminfo_command, + COMMAND_REGISTER(cmd_ctx, NULL, "meminfo", handle_meminfo_command, COMMAND_ANY, "display available ram memory"); Jim_CreateCommand(interp, "rm", zylinjtag_Jim_Command_rm, NULL, NULL); diff --git a/src/helper/log.c b/src/helper/log.c index 2dcf7bb..b1352a3 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -319,9 +319,9 @@ COMMAND_HANDLER(handle_log_output_command) int log_register_commands(struct command_context *cmd_ctx) { start = timeval_ms(); - register_command(cmd_ctx, NULL, "log_output", handle_log_output_command, + COMMAND_REGISTER(cmd_ctx, NULL, "log_output", handle_log_output_command, COMMAND_ANY, "redirect logging to <file> (default: stderr)"); - register_command(cmd_ctx... [truncated message content] |