From: Zach W. <zw...@us...> - 2009-11-13 20:03:50
|
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 ebbc762182c943d5967ea106933181a2fb726b1b (commit) via 89870c86e7aafd81a5720fcfd30002d24d26b232 (commit) via f973320cbb98d661bc0e4ba4fa9939ce8bce2b83 (commit) via deede35c270b078ae63713cfc12aa2bbc9eb78a7 (commit) via cc63d6e72b49dd01706c4d768c1f9bb91db2ae1d (commit) via d22270e0ed291d3b08fd03a25181b279ca5e0911 (commit) via a585bdf7269ce5c861c83ee3294ba1f074e9c877 (commit) via 5b6df55a1e5e4c0f531bc336691bc7c9a6a0df87 (commit) via 1df5cc18f51366b823bccdaec4ffa1ee3fac2447 (commit) via 670f999e7a1ec04cda599a5487de068379e36f0e (commit) via 0796dfff89bf00f82a780d7719767bcffe881d67 (commit) via 57c5c5f46304a785092874a7dc0f6abc84794cc3 (commit) via 76868e071306bc83d25b89e57b785fef4637c4c8 (commit) via d02fee197f62331e36e9de110040f0170341c3e8 (commit) via 63a26b421b1731df5826a157ea633b9d2c02aaee (commit) via cfc4d5c6b7b6f8f82dc5bbf3ee661c179814666e (commit) via ddb6138ed428f666064d26bb08036de3afe44bc8 (commit) via 3f9fd4e2a6ab7b3ce3819c385c34cf6f4630763c (commit) via 1ae4d93c3c90f176f6b94579ba3fabe1e17d715e (commit) from 5eb638c71e95048b090b8a19640d7d4902c07902 (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 ebbc762182c943d5967ea106933181a2fb726b1b Author: Zachary T Welch <zw...@su...> Date: Wed Nov 11 01:31:34 2009 -0800 add documention for writing built-in commands This documentation update provides an introduction to the command handling facilities provided by command.[ch]. A primer walks the user through the elements of a pointedly pedantic module: src/hello.c. A summary of the API is provided in the OpenOCD Architecture section. diff --git a/doc/manual/helper.txt b/doc/manual/helper.txt index 91bf2d5..7060607 100644 --- a/doc/manual/helper.txt +++ b/doc/manual/helper.txt @@ -31,7 +31,63 @@ This section needs to be expanded to describe OpenOCD's Jim API. /** @page helpercommand OpenOCD Command API -This section needs to be expanded to describe OpenOCD's Command API. +OpenOCD's command API allows modules to register callbacks that are then +available to the scripting services. It provides the mechanism for +these commands to be dispatched to the modlue using a standard +interfaces. It provides macros for defining functions that use and +extend this interface. + +@section helpercmdhandler Command Handlers + +Command handlers are functions with a particular signature, which can +be extended by modules for passing additional parameters to helpers or +another layer of handlers. + +@subsection helpercmdhandlerdef Defining and Calling Command Handlers + +These functions should be defined using the COMMAND_HANDLER macro. +These methods must be defined as static, as their principle entry point +should be the run_command dispatch mechanism. + +Command helper functions that require access to the full set of +parameters should be defined using the COMMAND_HELPER. These must be +declared static by you, as sometimes you might want to share a helper +among several files (e.g. s3c24xx_nand.h). + +Both types of routines must be called using the CALL_COMMAND_HANDLER macro. +Calls using this macro to normal handlers require the name of the command +handler (which can a name or function pointer). Calls to helpers and +derived handlers must pass those extra parameters specified by their +definitions; however, lexical capture is used for the core parameters. +This dirty trick is being used as a stop-gap measure while the API is +migrated to one that passes a pointer to a structure containing the +same ingredients. At that point, this macro will be removed and callers +will be able to use direct invocations. + +Thus, the following macros can be used to define and call command +handlers or helpers: + +- COMMAND_HANDLER - declare or define a command handler. +- COMMAND_HELPER - declare or define a derived command handler or helper. +- CALL_COMMAND_COMMAND - call a command handler/helper. + +@subsection helpercmdhandlerparam Command Handler Parameters + +The following parameters are defined in the scope of all command +handlers and helpers: +- <code>struct command_context_s *cmd_ctx</code> - the command's context +- <code>unsigned argc</code> - the number of command arguments +- <code>const char *args[]</code> - contains the command arguments + +@subsection helpercmdhandlermacros Command Handler Macros + +In addition, the following macro may be used: +- <code>COMMAND_NAME</code> - contains the command name + +@section helpercmdprimer Command Development Primer + +This @ref primercommand provides details about the @c hello module, +showing how the pieces desrcribed on this page fit together. */ diff --git a/doc/manual/main.txt b/doc/manual/main.txt index b9430b6..8e76464 100644 --- a/doc/manual/main.txt +++ b/doc/manual/main.txt @@ -42,11 +42,17 @@ associated with the fundamental technologies used by OpenOCD. - @subpage primertcl - @subpage primerjtag -These documents should bridge any "ancillary" gaps in contributor +The above documents should bridge any "ancillary" gaps in contributor knowledge, without having to learn the complete languages or technology. They should provide enough information for experienced developers to learn how to make "correct" changes when creating patches. +Beyond the fundamentals, the following primers provide introductory +tutorials for OpenOCD's sub-systems. These complement the @ref oocd +pages that provide more high-level perspective on related topics. + +- @subpage primercommand + In all cases, these Primers should use idiomatic conventions that the community has agreed are the "right way of doing things". In this respect, these documents typically assume some familiarity with the diff --git a/doc/manual/primer/commands.txt b/doc/manual/primer/commands.txt new file mode 100644 index 0000000..9efcca2 --- /dev/null +++ b/doc/manual/primer/commands.txt @@ -0,0 +1,99 @@ +/** @page primercommand Command Development Primer + +This page provides a primer for writing commands by introducing @c hello +module. The full source code used in this example can be found in +hello.c, and the @ref primercmdcode section shows how to use it. + +A summary of this information can be found in @ref helpercommand . + +@section primercmdhandler Command Handlers + +Defining new commands and their helpers is easy. The following code +defines a simple command handler that delegates its argument parsing: +@code +COMMAND_HANDLER(handle_hello_command) +{ + const char *sep, *name; + int retval = CALL_COMMAND_HANDLER(handle_hello_args); + if (ERROR_OK == retval) + command_print(cmd_ctx, "Greetings%s%s!", sep, name); + return retval; +} +@endcode + +Here, the @c COMMAND_HANDLER macro establishes the function signature, +see in command.h by the @c __COMMAND_HANDLER macro. + +The COMMAND_HELPER macro function allows defining functions with an +extended version of the base signature. These helper functions can be +called (with the appropriate parameters), the @c CALL_COMMAND_HANDLER +macro to pass any e as parameters to the following helper function: + +The subsequent blocks of code are a normal C function that can do +anything, so only complex commands deserve should use comamnd helper +functions. In this respect, this example uses one to demonstrate how -- +not when -- they should be used. + +@code +static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name) +{ + if (argc > 1) + { + LOG_ERROR("%s: too many arguments", COMMAND_NAME); + return ERROR_COMMAND_SYNTAX_ERROR; + } + if (1 == argc) + { + *sep = ", "; + *name = args[0]; + } + else + *sep = *name = ""; + + return ERROR_OK; +} +@endcode + +Of course, you may also call other macros or functions, but that extends +beyond the scope of this tutorial on writing commands. + +@section primercmdreg Command Registration + +Before this new function can be used, it must be registered somehow. +For a new module, registering should be done in a new function for +the purpose, which must be called from @c openocd.c: +@code +int hello_register_commands(struct command_context_s *cmd_ctx) +{ + struct command_s *cmd = register_command(cmd_ctx, NULL, "hello", + NULL, COMMAND_ANY, "print greetings"); + return cmd ? ERROR_OK : -ENOMEM; +} +@endcode + +That's it! The command should now be registered and avaiable to scripts. + +@section primercmdcode Trying These Example Commands + +The commands may be enabled by editing src/openocd.c and uncommenting +the call to @c hello_register_commands and rebuilding the source tree. + +Once OpenOCD has been built with this example code, the following script +demonstrate the abilities that the @c hello module provides: +@code +hello +hello World +hello {John Doe} +hello John Doe # error: too many arguments +@endcode + +If saved in @c hello.cfg, then running <code>openocd -f hello.cfg</code> +should produce the following output before exiting: +@code +Greetings! +Greetings, World! +Greetings, John Doe! +Error: ocd_hello: too many arguments +@endcode + + */ commit 89870c86e7aafd81a5720fcfd30002d24d26b232 Author: Zachary T Welch <zw...@su...> Date: Wed Nov 11 01:20:49 2009 -0800 add src/hello.c to augment new command tutorial The hello module provides the 'hello' command, printing a greetings to the command console. It can grow to serve as pedagogical example of services that OpenOCD developers should use: a runnable style guide. diff --git a/src/Makefile.am b/src/Makefile.am index 6717910..7721f34 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,9 @@ endif openocd_SOURCES = $(MAINFILE) openocd_LDADD = libopenocd.la -libopenocd_la_SOURCES = openocd.c +libopenocd_la_SOURCES = \ + hello.c \ + openocd.c # set the include path found by configure AM_CPPFLAGS = \ diff --git a/src/hello.c b/src/hello.c new file mode 100644 index 0000000..8a4f701 --- /dev/null +++ b/src/hello.c @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2009 Zachary T Welch <zw...@su...> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include "log.h" + +static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name) +{ + if (argc > 1) + { + LOG_ERROR("%s: too many arguments", CMD_NAME); + return ERROR_COMMAND_SYNTAX_ERROR; + } + if (1 == argc) + { + *sep = " "; + *name = args[0]; + } + else + *sep = *name = ""; + + return ERROR_OK; +} +COMMAND_HANDLER(handle_hello_command) +{ + const char *sep, *name; + int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name); + if (ERROR_OK == retval) + command_print(cmd_ctx, "Greetings%s%s!", sep, name); + return retval; +} + +int hello_register_commands(struct command_context_s *cmd_ctx) +{ + struct command_s *cmd = register_command(cmd_ctx, NULL, "hello", + &handle_hello_command, COMMAND_ANY, + "option"); + return cmd ? ERROR_OK : -ENOMEM; +} diff --git a/src/openocd.c b/src/openocd.c index 2a74a46..d67ebd5 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -177,6 +177,9 @@ COMMAND_HANDLER(handle_init_command) command_context_t *global_cmd_ctx; +/// src/hello.c gives a simple example for writing new command modules +int hello_register_commands(struct command_context_s *cmd_ctx); + /* NB! this fn can be invoked outside this file for non PC hosted builds */ command_context_t *setup_command_handler(void) { @@ -188,6 +191,7 @@ command_context_t *setup_command_handler(void) COMMAND_EXEC, "show OpenOCD version"); /* register subsystem commands */ + hello_register_commands(cmd_ctx); server_register_commands(cmd_ctx); telnet_register_commands(cmd_ctx); gdb_register_commands(cmd_ctx); commit f973320cbb98d661bc0e4ba4fa9939ce8bce2b83 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 23:01:44 2009 -0800 command_handler_t: make cmd an indirect parameter This patch removes 'cmd' from the list of direct parameters, moving that pointer to args[-1] (by way of the new CMD_NAME macro). diff --git a/src/helper/command.c b/src/helper/command.c index 7a42ab2..3cd11d2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -102,7 +102,8 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) script_debug(interp, c->name, argc, argv); - words = malloc(sizeof(char *) * argc); + words = malloc(sizeof(char *) * (argc + 1)); + words[0] = c->name; for (i = 0; i < argc; i++) { int len; @@ -112,12 +113,12 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) /* hit an end of line comment */ break; } - words[i] = strdup(w); - if (words[i] == NULL) + words[i + 1] = strdup(w); + if (words[i + 1] == NULL) { int j; for (j = 0; j < i; j++) - free(words[j]); + free(words[j + 1]); free(words); return JIM_ERR; } @@ -141,7 +142,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); + // turn words[0] into args[-1] with this cast + retval = run_command(context, c, (const char **)words + 1, nwords); log_remove_callback(tcl_output, tclOutput); @@ -150,7 +152,7 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_DecrRefCount(interp, tclOutput); for (i = 0; i < nwords; i++) - free(words[i]); + free(words[i + 1]); free(words); int *return_retval = Jim_GetAssocData(interp, "retval"); @@ -447,7 +449,7 @@ static int run_command(command_context_t *context, unsigned argc = num_words - start_word - 1; const char **args = words + start_word + 1; - int retval = c->handler(context, c->name, args, argc); + int retval = c->handler(context, args, argc); if (retval == ERROR_COMMAND_SYNTAX_ERROR) { /* Print help for command */ diff --git a/src/helper/command.h b/src/helper/command.h index fbcc0aa..bddb053 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -88,7 +88,7 @@ typedef struct command_context_s */ #define __COMMAND_HANDLER(name, extra...) \ int name(struct command_context_s *cmd_ctx, \ - const char *cmd, const char *args[], unsigned argc, ##extra) + const char *args[], unsigned argc, ##extra) /** * Use this to macro to call a command helper (or a nested handler). @@ -104,7 +104,7 @@ typedef struct command_context_s * variables in intervening scope(s) by accident. */ #define CALL_COMMAND_HANDLER(name, extra...) \ - name(cmd_ctx, cmd, args, argc, ##extra) + name(cmd_ctx, args, argc, ##extra) /** * Always use this macro to define new command handler functions. @@ -125,7 +125,7 @@ typedef struct command_context_s * Use this macro to access the name of the command being handled, * rather than accessing the variable directly. It may be moved. */ -#define CMD_NAME cmd +#define CMD_NAME args[-1] /// The type signature for commands' handler functions. commit deede35c270b078ae63713cfc12aa2bbc9eb78a7 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 04:37:17 2009 -0800 command_handler_t: make args parameter const This patch prevents command handlers from modifying the strings passed in the 'args' array. diff --git a/src/helper/command.c b/src/helper/command.c index 4ce5085..7a42ab2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -48,7 +48,7 @@ int fast_and_dangerous = 0; Jim_Interp *interp = NULL; static int run_command(command_context_t *context, - command_t *c, char *words[], unsigned num_words); + command_t *c, const char *words[], unsigned num_words); static void tcl_output(void *privData, const char *file, unsigned line, const char *function, const char *string) @@ -141,7 +141,7 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) log_add_callback(tcl_output, tclOutput); - retval = run_command(context, c, words, nwords); + retval = run_command(context, c, (const char **)words, nwords); log_remove_callback(tcl_output, tclOutput); @@ -435,7 +435,7 @@ char *command_name(struct command_s *c, char delim) } static int run_command(command_context_t *context, - command_t *c, char *words[], unsigned num_words) + command_t *c, const char *words[], unsigned num_words) { int start_word = 0; if (!((context->mode == COMMAND_CONFIG) || (c->mode == COMMAND_ANY) || (c->mode == context->mode))) @@ -445,7 +445,9 @@ static int run_command(command_context_t *context, return ERROR_FAIL; } - int retval = c->handler(context, c->name, words + start_word + 1, num_words - start_word - 1); + unsigned argc = num_words - start_word - 1; + const char **args = words + start_word + 1; + int retval = c->handler(context, c->name, args, argc); if (retval == ERROR_COMMAND_SYNTAX_ERROR) { /* Print help for command */ diff --git a/src/helper/command.h b/src/helper/command.h index 18664d2..fbcc0aa 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -88,7 +88,7 @@ typedef struct command_context_s */ #define __COMMAND_HANDLER(name, extra...) \ int name(struct command_context_s *cmd_ctx, \ - const char *cmd, char **args, unsigned argc, ##extra) + const char *cmd, const char *args[], unsigned argc, ##extra) /** * Use this to macro to call a command helper (or a nested handler). commit cc63d6e72b49dd01706c4d768c1f9bb91db2ae1d Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 00:10:25 2009 -0800 command_handler_t: make cmd parameter const Prevents the command name from being modified in command handlers. Again, this has cascading effects, but the patches are fairly minimal. diff --git a/src/helper/command.h b/src/helper/command.h index 5577315..18664d2 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -88,7 +88,7 @@ typedef struct command_context_s */ #define __COMMAND_HANDLER(name, extra...) \ int name(struct command_context_s *cmd_ctx, \ - char *cmd, char **args, unsigned argc, ##extra) + const char *cmd, char **args, unsigned argc, ##extra) /** * Use this to macro to call a command helper (or a nested handler). commit d22270e0ed291d3b08fd03a25181b279ca5e0911 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 00:02:18 2009 -0800 command_handler_t: make argc unsigned The number of command arguments will always be 0 or more, so use the right type in handlers. This has a cascading effect up through the layers, but the new COMMAND_HANDLER macros prevented total chaos. diff --git a/src/flash/cfi.c b/src/flash/cfi.c index 08c4358..88f57df 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -604,9 +604,6 @@ static int cfi_register_commands(struct command_context_s *cmd_ctx) FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command) { cfi_flash_bank_t *cfi_info; - int i; - (void) cmd_ctx; - (void) cmd; if (argc < 6) { @@ -635,7 +632,7 @@ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command) cfi_info->jedec_probe = 0; cfi_info->not_cfi = 0; - for (i = 6; i < argc; i++) + for (unsigned i = 6; i < argc; i++) { if (strcmp(args[i], "x16_as_x8") == 0) { diff --git a/src/flash/nand.c b/src/flash/nand.c index 88d3e42..26eb63a 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -1315,8 +1315,7 @@ COMMAND_HANDLER(handle_nand_write_command) if (argc > 3) { - int i; - for (i = 3; i < argc; i++) + for (unsigned i = 3; i < argc; i++) { if (!strcmp(args[i], "oob_raw")) oob_format |= NAND_OOB_RAW; @@ -1485,8 +1484,7 @@ COMMAND_HANDLER(handle_nand_dump_command) if (argc > 4) { - int i; - for (i = 4; i < argc; i++) + for (unsigned i = 4; i < argc; i++) { if (!strcmp(args[i], "oob_raw")) oob_format |= NAND_OOB_RAW; diff --git a/src/helper/command.h b/src/helper/command.h index 74c6f36..5577315 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -88,7 +88,7 @@ typedef struct command_context_s */ #define __COMMAND_HANDLER(name, extra...) \ int name(struct command_context_s *cmd_ctx, \ - char *cmd, char **args, int argc, ##extra) + char *cmd, char **args, unsigned argc, ##extra) /** * Use this to macro to call a command helper (or a nested handler). diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 1423462..3a62961 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -214,9 +214,9 @@ COMMAND_HANDLER(handle_append_command) config_file = fopen(args[0], "a"); if (config_file != NULL) { - int i; fseek(config_file, 0, SEEK_END); + unsigned i; for (i = 1; i < argc; i++) { if (fwrite(args[i], 1, strlen(args[i]), config_file) != strlen(args[i])) diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 6d23356..39036bc 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -2874,8 +2874,7 @@ COMMAND_HANDLER(ft2232_handle_vid_pid_command) argc -= 1; } - int i; - int retval = ERROR_OK; + unsigned i; for (i = 0; i < argc; i += 2) { COMMAND_PARSE_NUMBER(u16, args[i], ft2232_vid[i >> 1]); @@ -2888,7 +2887,7 @@ COMMAND_HANDLER(ft2232_handle_vid_pid_command) */ ft2232_vid[i >> 1] = ft2232_pid[i >> 1] = 0; - return retval; + return ERROR_OK; } COMMAND_HANDLER(ft2232_handle_latency_command) diff --git a/src/svf/svf.c b/src/svf/svf.c index 76b0670..8f2ee80 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -304,7 +304,7 @@ int svf_add_statemove(tap_state_t state_to) COMMAND_HANDLER(handle_svf_command) { #define SVF_NUM_OF_OPTIONS 1 - int command_num = 0, i; + int command_num = 0; int ret = ERROR_OK; long long time_ago; @@ -316,7 +316,7 @@ COMMAND_HANDLER(handle_svf_command) // parse variant svf_quiet = 0; - for (i = 1; i < argc; i++) + for (unsigned i = 1; i < argc; i++) { if (!strcmp(args[i], "quiet")) { diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 112ec2a..416fe79 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -862,7 +862,6 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) struct arm7_9_common_s *arm7_9 = target_to_arm7_9(target); reg_t *vector_catch; uint32_t vector_catch_value; - int i, j; /* it's uncommon, but some ARM7 chips can support this */ if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC @@ -894,9 +893,10 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) } else { - for (i = 0; i < argc; i++) + for (unsigned i = 0; i < argc; i++) { /* go through list of vectors */ + unsigned j; for (j = 0; arm9tdmi_vectors[j].name; j++) { if (strcmp(args[i], arm9tdmi_vectors[j].name) == 0) @@ -927,7 +927,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) } /* output current settings */ - for (i = 0; arm9tdmi_vectors[i].name; i++) { + for (unsigned i = 0; arm9tdmi_vectors[i].name; i++) { command_print(cmd_ctx, "%s: %s", arm9tdmi_vectors[i].name, (vector_catch_value & arm9tdmi_vectors[i].value) ? "catch" : "don't catch"); commit a585bdf7269ce5c861c83ee3294ba1f074e9c877 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 22:29:36 2009 -0800 add CMD_NAME macro for command handlers By introducing the CMD_NAME macro, this parameter may be integrated as args[-1] in command.[ch], without touching any other call sites. diff --git a/src/flash/flash.c b/src/flash/flash.c index da43e1a..f3f0086 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -728,7 +728,7 @@ COMMAND_HANDLER(handle_flash_fill_command) if (count == 0) return ERROR_OK; - switch (cmd[4]) + switch (CMD_NAME[4]) { case 'w': wordsize = 4; diff --git a/src/helper/command.h b/src/helper/command.h index aec066d..74c6f36 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -121,6 +121,12 @@ typedef struct command_context_s */ #define COMMAND_HELPER(name, extra...) __COMMAND_HANDLER(name, extra) +/** + * Use this macro to access the name of the command being handled, + * rather than accessing the variable directly. It may be moved. + */ +#define CMD_NAME cmd + /// The type signature for commands' handler functions. typedef __COMMAND_HANDLER((*command_handler_t)); diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 4da8838..923542f 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -605,7 +605,7 @@ static int default_srst_asserted(int *srst_asserted) COMMAND_HANDLER(handle_interface_list_command) { - if (strcmp(cmd, "interface_list") == 0 && argc > 0) + if (strcmp(CMD_NAME, "interface_list") == 0 && argc > 0) return ERROR_COMMAND_SYNTAX_ERROR; command_print(cmd_ctx, "The following JTAG interfaces are available:"); diff --git a/src/target/arm720t.c b/src/target/arm720t.c index 6a5a4e7..af326bf 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -424,7 +424,7 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 5576f60..81f5c6a 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -1203,7 +1203,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1257,7 +1257,7 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 6f347d8..77405a8 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -740,7 +740,7 @@ COMMAND_HANDLER(arm926ejs_handle_cp15_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } diff --git a/src/target/arm966e.c b/src/target/arm966e.c index e61943a..62ccaa8 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -174,7 +174,7 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index 5084231..86469c4 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -1902,7 +1902,7 @@ COMMAND_HANDLER(handle_cortex_m3_mask_interrupts_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } diff --git a/src/target/target.c b/src/target/target.c index 21c0526..8cc46ec 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2046,7 +2046,7 @@ COMMAND_HANDLER(handle_wait_halt_command) int retval = parse_uint(args[0], &ms); if (ERROR_OK != retval) { - command_print(cmd_ctx, "usage: %s [seconds]", cmd); + command_print(cmd_ctx, "usage: %s [seconds]", CMD_NAME); return ERROR_COMMAND_SYNTAX_ERROR; } // convert seconds (given) to milliseconds (needed) @@ -2256,7 +2256,7 @@ COMMAND_HANDLER(handle_md_command) return ERROR_COMMAND_SYNTAX_ERROR; unsigned size = 0; - switch (cmd[2]) { + switch (CMD_NAME[2]) { case 'w': size = 4; break; case 'h': size = 2; break; case 'b': size = 1; break; @@ -2333,7 +2333,7 @@ COMMAND_HANDLER(handle_mw_command) target_t *target = get_current_target(cmd_ctx); unsigned wordsize; uint8_t value_buf[4]; - switch (cmd[2]) + switch (CMD_NAME[2]) { case 'w': wordsize = 4; diff --git a/src/target/xscale.c b/src/target/xscale.c index 6f2d6ee..e18d591 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -3127,7 +3127,7 @@ COMMAND_HANDLER(xscale_handle_mmu_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3163,13 +3163,13 @@ COMMAND_HANDLER(xscale_handle_idcache_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } - if (strcmp(cmd, "icache") == 0) + if (strcmp(CMD_NAME, "icache") == 0) icache = 1; - else if (strcmp(cmd, "dcache") == 0) + else if (strcmp(CMD_NAME, "dcache") == 0) dcache = 1; if (argc >= 1) @@ -3302,7 +3302,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3429,7 +3429,7 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3499,7 +3499,7 @@ COMMAND_HANDLER(xscale_handle_cp15) if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd); + command_print(cmd_ctx, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } uint32_t reg_no = 0; commit 5b6df55a1e5e4c0f531bc336691bc7c9a6a0df87 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 22:23:07 2009 -0800 use CALL_COMMAND_HANDLER instead of direct calls By using CALL_COMMAND_HANDLER, parameters can be reordered, added, or even removed in inherited signatures, without requiring revisiting all of the various call sites. diff --git a/src/flash/flash.c b/src/flash/flash.c index d3889b9..da43e1a 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -259,7 +259,8 @@ COMMAND_HANDLER(handle_flash_bank_command) c->sectors = NULL; c->next = NULL; - if ((retval = flash_drivers[i]->flash_bank_command(cmd_ctx, cmd, args, argc, c)) != ERROR_OK) + retval = CALL_COMMAND_HANDLER(flash_drivers[i]->flash_bank_command, c); + if (ERROR_OK != retval) { LOG_ERROR("'%s' driver rejected flash bank at 0x%8.8" PRIx32 , args[0], c->base); free(c); diff --git a/src/flash/nand.c b/src/flash/nand.c index 181700d..88d3e42 100644 --- a/src/flash/nand.c +++ b/src/flash/nand.c @@ -241,7 +241,8 @@ COMMAND_HANDLER(handle_nand_device_command) c->use_raw = 0; c->next = NULL; - if ((retval = nand_flash_controllers[i]->nand_device_command(cmd_ctx, cmd, args, argc, c)) != ERROR_OK) + retval = CALL_COMMAND_HANDLER(nand_flash_controllers[i]->nand_device_command, c); + if (ERROR_OK != retval) { LOG_ERROR("'%s' driver rejected nand flash", c->controller->name); free(c); diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 653d3a7..4da8838 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -658,7 +658,7 @@ COMMAND_HANDLER(handle_interface_command) * didn't match one of the compiled-in interfaces */ LOG_ERROR("The specified JTAG interface was not found (%s)", args[0]); - handle_interface_list_command(cmd_ctx, cmd, args, argc); + CALL_COMMAND_HANDLER(handle_interface_list_command); return ERROR_JTAG_INVALID_INTERFACE; } diff --git a/src/pld/pld.c b/src/pld/pld.c index c20b936..e8cd075 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -85,7 +85,8 @@ COMMAND_HANDLER(handle_pld_device_command) c->driver = pld_drivers[i]; c->next = NULL; - if (pld_drivers[i]->pld_device_command(cmd_ctx, cmd, args, argc, c) != ERROR_OK) + int retval = CALL_COMMAND_HANDLER(pld_drivers[i]->pld_device_command, c); + if (ERROR_OK != retval) { LOG_ERROR("'%s' driver rejected pld device", args[0]); free(c); diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index c0c5d77..761ae40 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2271,7 +2271,7 @@ COMMAND_HANDLER(handle_gdb_sync_command) /* daemon configuration command gdb_port */ COMMAND_HANDLER(handle_gdb_port_command) { - return server_port_command(cmd_ctx, cmd, args, argc, &gdb_port); + return CALL_COMMAND_HANDLER(server_port_command, &gdb_port); } COMMAND_HANDLER(handle_gdb_memory_map_command) diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 3410ca9..c8da5bc 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -172,7 +172,7 @@ int tcl_init(void) COMMAND_HANDLER(handle_tcl_port_command) { - return server_port_command(cmd_ctx, cmd, args, argc, &tcl_port); + return CALL_COMMAND_HANDLER(server_port_command, &tcl_port); } int tcl_register_commands(command_context_t *cmd_ctx) diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index c409ec0..6cb4746 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -608,7 +608,7 @@ int telnet_init(char *banner) /* daemon configuration command telnet_port */ COMMAND_HANDLER(handle_telnet_port_command) { - return server_port_command(cmd_ctx, cmd, args, argc, &telnet_port); + return CALL_COMMAND_HANDLER(server_port_command, &telnet_port); } COMMAND_HANDLER(handle_exit_command) diff --git a/src/target/arm11.c b/src/target/arm11.c index 949c947..5b11f8e 100644 --- a/src/target/arm11.c +++ b/src/target/arm11.c @@ -2029,7 +2029,8 @@ static COMMAND_HELPER(arm11_handle_bool, bool *var, char *name) #define BOOL_WRAPPER(name, print_name) \ COMMAND_HANDLER(arm11_handle_bool_##name) \ { \ - return arm11_handle_bool(cmd_ctx, cmd, args, argc, &arm11_config_##name, print_name); \ + return CALL_COMMAND_HANDLER(arm11_handle_bool, \ + &arm11_config_##name, print_name); \ } BOOL_WRAPPER(memwrite_burst, "memory write burst mode") @@ -2186,12 +2187,12 @@ static COMMAND_HELPER(arm11_handle_etm_read_write, bool read) COMMAND_HANDLER(arm11_handle_etmr) { - return arm11_handle_etm_read_write(cmd_ctx, cmd, args, argc, true); + return CALL_COMMAND_HANDLER(arm11_handle_etm_read_write, true); } COMMAND_HANDLER(arm11_handle_etmw) { - return arm11_handle_etm_read_write(cmd_ctx, cmd, args, argc, false); + return CALL_COMMAND_HANDLER(arm11_handle_etm_read_write, false); } #define ARM11_HANDLER(x) .x = arm11_##x diff --git a/src/target/etm.c b/src/target/etm.c index df02904..a4ff6c5 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -1271,7 +1271,7 @@ COMMAND_HANDLER(handle_etm_tracemode_command) case 0: break; case 4: - handle_etm_tracemode_command_update(cmd_ctx, cmd, args, argc, &tracemode); + CALL_COMMAND_HANDLER(handle_etm_tracemode_command_update, &tracemode); break; default: command_print(cmd_ctx, "usage: configure trace mode " diff --git a/src/target/target.c b/src/target/target.c index 26c20cf..21c0526 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2121,7 +2121,7 @@ COMMAND_HANDLER(handle_halt_command) return ERROR_OK; } - return handle_wait_halt_command(cmd_ctx, cmd, args, argc); + return CALL_COMMAND_HANDLER(handle_wait_halt_command); } COMMAND_HANDLER(handle_soft_reset_halt_command) @@ -2410,7 +2410,7 @@ COMMAND_HANDLER(handle_load_image_command) int i; image_t image; - int retval = parse_load_image_command_args(cmd_ctx, cmd, args, argc, + int retval = CALL_COMMAND_HANDLER(parse_load_image_command_args, &image, &min_address, &max_address); if (ERROR_OK != retval) return retval; @@ -2701,12 +2701,12 @@ done: COMMAND_HANDLER(handle_verify_image_command) { - return handle_verify_image_command_internal(cmd_ctx, cmd, args, argc, 1); + return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, 1); } COMMAND_HANDLER(handle_test_image_command) { - return handle_verify_image_command_internal(cmd_ctx, cmd, args, argc, 0); + return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, 0); } static int handle_bp_command_list(struct command_context_s *cmd_ctx) @@ -4547,7 +4547,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) image_t image; - int retval = parse_load_image_command_args(cmd_ctx, cmd, args, argc, + int retval = CALL_COMMAND_HANDLER(parse_load_image_command_args, &image, &min_address, &max_address); if (ERROR_OK != retval) return retval; commit 1df5cc18f51366b823bccdaec4ffa1ee3fac2447 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 01:21:29 2009 -0800 add PLD_DEVICE_COMMAND_HANDLER macro Update virtex module to use abstracted PLD command handling. diff --git a/src/pld/pld.h b/src/pld/pld.h index 3db4bad..22f2c13 100644 --- a/src/pld/pld.h +++ b/src/pld/pld.h @@ -24,14 +24,19 @@ struct pld_device_s; +#define __PLD_DEVICE_COMMAND(name) \ + COMMAND_HELPER(name, struct pld_device_s *pld) + typedef struct pld_driver_s { char *name; + __PLD_DEVICE_COMMAND((*pld_device_command)); int (*register_commands)(struct command_context_s *cmd_ctx); - int (*pld_device_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct pld_device_s *pld_device); int (*load)(struct pld_device_s *pld_device, const char *filename); } pld_driver_t; +#define PLD_DEVICE_COMMAND_HANDLER(name) static __PLD_DEVICE_COMMAND(name) + typedef struct pld_device_s { pld_driver_t *driver; diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index 3c6d61f..7e422fb 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -207,8 +207,7 @@ COMMAND_HANDLER(virtex2_handle_read_stat_command) return ERROR_OK; } -static int virtex2_pld_device_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, struct pld_device_s *pld_device) +PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command) { jtag_tap_t *tap; @@ -227,9 +226,10 @@ static int virtex2_pld_device_command(struct command_context_s *cmd_ctx, } virtex2_info = malloc(sizeof(virtex2_pld_device_t)); - pld_device->driver_priv = virtex2_info; virtex2_info->tap = tap; + pld->driver_priv = virtex2_info; + return ERROR_OK; } commit 670f999e7a1ec04cda599a5487de068379e36f0e Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 00:53:40 2009 -0800 nand: add NAND_DEVICE_COMMAND_HANDLER macro Abstracts the extended NAND command handling to allow the function signature to be controlled by __COMMAND_HANDLER. diff --git a/src/flash/davinci_nand.c b/src/flash/davinci_nand.c index 6ecc60a..b3164ab 100644 --- a/src/flash/davinci_nand.c +++ b/src/flash/davinci_nand.c @@ -629,9 +629,7 @@ static int davinci_read_page_ecc4infix(struct nand_device_s *nand, uint32_t page return ERROR_OK; } -static int davinci_nand_device_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(davinci_nand_device_command) { struct davinci_nand *info; target_t *target; diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 4b12077..41cc33e 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -29,7 +29,7 @@ static int lpc3180_controller_ready(struct nand_device_s *nand, int timeout); /* nand device lpc3180 <target#> <oscillator_frequency> */ -static int lpc3180_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(lpc3180_nand_device_command) { if (argc < 3) { diff --git a/src/flash/mx3_nand.c b/src/flash/mx3_nand.c index f6a75ef..a51f8c8 100644 --- a/src/flash/mx3_nand.c +++ b/src/flash/mx3_nand.c @@ -61,9 +61,7 @@ static int imx31_command (struct nand_device_s *nand, uint8_t command); static int imx31_address (struct nand_device_s *nand, uint8_t address); static int imx31_controller_ready (struct nand_device_s *nand, int tout); -static int imx31_nand_device_command (struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(imx31_nand_device_command) { mx3_nf_controller_t *mx3_nf_info; mx3_nf_info = malloc (sizeof (mx3_nf_controller_t)); diff --git a/src/flash/nand.h b/src/flash/nand.h index d96e288..57076d5 100644 --- a/src/flash/nand.h +++ b/src/flash/nand.h @@ -29,10 +29,13 @@ struct nand_device_s; +#define __NAND_DEVICE_COMMAND(name) \ + COMMAND_HELPER(name, struct nand_device_s *nand) + typedef struct nand_flash_controller_s { char *name; - int (*nand_device_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *nand); + __NAND_DEVICE_COMMAND((*nand_device_command)); int (*register_commands)(struct command_context_s *cmd_ctx); int (*init)(struct nand_device_s *nand); int (*reset)(struct nand_device_s *nand); @@ -48,6 +51,8 @@ typedef struct nand_flash_controller_s int (*nand_ready)(struct nand_device_s *nand, int timeout); } nand_flash_controller_t; +#define NAND_DEVICE_COMMAND_HANDLER(name) static __NAND_DEVICE_COMMAND(name) + typedef struct nand_block_s { uint32_t offset; diff --git a/src/flash/orion_nand.c b/src/flash/orion_nand.c index 471c562..b112c9e 100644 --- a/src/flash/orion_nand.c +++ b/src/flash/orion_nand.c @@ -125,9 +125,7 @@ static int orion_nand_register_commands(struct command_context_s *cmd_ctx) return ERROR_OK; } -int orion_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(orion_nand_device_command) { orion_nand_controller_t *hw; uint32_t base; diff --git a/src/flash/s3c2410_nand.c b/src/flash/s3c2410_nand.c index 176a1a4..5badf1a 100644 --- a/src/flash/s3c2410_nand.c +++ b/src/flash/s3c2410_nand.c @@ -30,9 +30,7 @@ #include "s3c24xx_nand.h" -static int s3c2410_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(s3c2410_nand_device_command) { s3c24xx_nand_controller_t *info; CALL_S3C24XX_DEVICE_COMMAND(nand, &info); diff --git a/src/flash/s3c2412_nand.c b/src/flash/s3c2412_nand.c index 7b65f84..958f013 100644 --- a/src/flash/s3c2412_nand.c +++ b/src/flash/s3c2412_nand.c @@ -30,9 +30,7 @@ #include "s3c24xx_nand.h" -static int s3c2412_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(s3c2412_nand_device_command) { s3c24xx_nand_controller_t *info; CALL_S3C24XX_DEVICE_COMMAND(nand, &info); diff --git a/src/flash/s3c2440_nand.c b/src/flash/s3c2440_nand.c index c6d658d..80020f6 100644 --- a/src/flash/s3c2440_nand.c +++ b/src/flash/s3c2440_nand.c @@ -31,9 +31,7 @@ #include "s3c24xx_nand.h" -static int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(s3c2440_nand_device_command) { s3c24xx_nand_controller_t *info; CALL_S3C24XX_DEVICE_COMMAND(nand, &info); diff --git a/src/flash/s3c2443_nand.c b/src/flash/s3c2443_nand.c index 6e92021..af7d9a9 100644 --- a/src/flash/s3c2443_nand.c +++ b/src/flash/s3c2443_nand.c @@ -31,9 +31,7 @@ #include "s3c24xx_nand.h" -static int s3c2443_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +NAND_DEVICE_COMMAND_HANDLER(s3c2443_nand_device_command) { s3c24xx_nand_controller_t *info; CALL_S3C24XX_DEVICE_COMMAND(nand, &info); commit 0796dfff89bf00f82a780d7719767bcffe881d67 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 01:41:30 2009 -0800 use FLASH_BANK_COMMAND_HANDLER macro Defines all flash_bank_command handlers using the new macro. diff --git a/src/flash/aduc702x.c b/src/flash/aduc702x.c index 7d6fa24..0e862e9 100644 --- a/src/flash/aduc702x.c +++ b/src/flash/aduc702x.c @@ -61,7 +61,7 @@ typedef struct /* flash bank aduc702x 0 0 0 0 <target#> * The ADC7019-28 devices all have the same flash layout */ -static int aduc702x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(aduc702x_flash_bank_command) { aduc702x_flash_bank_t *nbank; diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c index 804a35b..7e6b456 100644 --- a/src/flash/at91sam3.c +++ b/src/flash/at91sam3.c @@ -1641,12 +1641,7 @@ sam3_protect_check(struct flash_bank_s *bank) return ERROR_OK; } -static int -sam3_flash_bank_command(struct command_context_s *cmd_ctx, - char *cmd, - char **args, - int argc, - struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(sam3_flash_bank_command) { struct sam3_chip *pChip; diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index 4cd2705..266be06 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -711,7 +711,7 @@ static int at91sam7_protect_check(struct flash_bank_s *bank) return ERROR_OK; } -static int at91sam7_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command) { flash_bank_t *t_bank = bank; at91sam7_flash_bank_t *at91sam7_info; diff --git a/src/flash/avrf.c b/src/flash/avrf.c index 6badb2d..35d31fb 100644 --- a/src/flash/avrf.c +++ b/src/flash/avrf.c @@ -180,7 +180,7 @@ static int avr_jtagprg_writeflashpage(avr_common_t *avr, uint8_t *page_buf, uint return ERROR_OK; } -static int avrf_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(avrf_flash_bank_command) { avrf_flash_bank_t *avrf_info; diff --git a/src/flash/cfi.c b/src/flash/cfi.c index b448a30..08c4358 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -601,7 +601,7 @@ static int cfi_register_commands(struct command_context_s *cmd_ctx) /* flash_bank cfi <base> <size> <chip_width> <bus_width> <target#> [options] */ -static int cfi_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command) { cfi_flash_bank_t *cfi_info; int i; diff --git a/src/flash/ecos.c b/src/flash/ecos.c index 401fdf2..2c3190a 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -104,7 +104,7 @@ flash_errmsg(int err) /* flash bank ecosflash <base> <size> <chip_width> <bus_width> <target#> <driverPath> */ -static int ecosflash_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(ecosflash_flash_bank_command) { ecosflash_flash_bank_t *info; diff --git a/src/flash/faux.c b/src/flash/faux.c index 474dee5..b997b87 100644 --- a/src/flash/faux.c +++ b/src/flash/faux.c @@ -37,7 +37,7 @@ static const int sectorSize = 0x10000; /* flash bank faux <base> <size> <chip_width> <bus_width> <target#> <driverPath> */ -static int faux_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command) { faux_flash_bank_t *info; diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c index 4d4d9a2..0481355 100644 --- a/src/flash/lpc2000.c +++ b/src/flash/lpc2000.c @@ -419,7 +419,7 @@ static int lpc2000_iap_blank_check(struct flash_bank_s *bank, int first, int las /* * flash bank lpc2000 <base> <size> 0 0 <target#> <lpc_variant> <cclk> [calc_checksum] */ -static int lpc2000_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command) { lpc2000_flash_bank_t *lpc2000_info; diff --git a/src/flash/lpc288x.c b/src/flash/lpc288x.c index 36444fb..3c3e1e4 100644 --- a/src/flash/lpc288x.c +++ b/src/flash/lpc288x.c @@ -165,7 +165,7 @@ static int lpc288x_protect_check(struct flash_bank_s *bank) } /* flash_bank LPC288x 0 0 0 0 <target#> <cclk> */ -static int lpc288x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(lpc288x_flash_bank_command) { lpc288x_flash_bank_t *lpc288x_info; diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c index 945fc9a..953a62a 100644 --- a/src/flash/lpc2900.c +++ b/src/flash/lpc2900.c @@ -1016,9 +1016,7 @@ static int lpc2900_register_commands(struct command_context_s *cmd_ctx) /// Evaluate flash bank command. -static int lpc2900_flash_bank_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, - struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command) { lpc2900_flash_bank_t *lpc2900_info; diff --git a/src/flash/ocl.c b/src/flash/ocl.c index 51ccc96..63e9282 100644 --- a/src/flash/ocl.c +++ b/src/flash/ocl.c @@ -44,7 +44,7 @@ static int ocl_protect_check(struct flash_bank_s *bank) } /* flash_bank ocl 0 0 0 0 <target#> */ -static int ocl_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command) { int retval; armv4_5_common_t *armv4_5; diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index aa34aea..1408fe9 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -62,7 +62,7 @@ static int pic32mx_write_word(struct flash_bank_s *bank, uint32_t address, uint3 /* flash bank pic32mx <base> <size> 0 0 <target#> */ -static int pic32mx_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(pic32mx_flash_bank_command) { pic32mx_flash_bank_t *pic32mx_info; diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c index 22d5bc4..d66b9a8 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -213,7 +213,7 @@ static char * StellarisClassname[5] = /* flash_bank stellaris <base> <size> 0 0 <target#> */ -static int stellaris_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command) { stellaris_flash_bank_t *stellaris_info; diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index 95d15a9..41b9008 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -33,7 +33,7 @@ static int stm32x_mass_erase(struct flash_bank_s *bank); /* flash bank stm32x <base> <size> 0 0 <target#> */ -static int stm32x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(stm32x_flash_bank_command) { stm32x_flash_bank_t *stm32x_info; diff --git a/src/flash/str7x.c b/src/flash/str7x.c index 028eab6..9738180 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -109,7 +109,7 @@ static int str7x_build_block_list(struct flash_bank_s *bank) /* flash bank str7x <base> <size> 0 0 <target#> <str71_variant> */ -static int str7x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command) { str7x_flash_bank_t *str7x_info; diff --git a/src/flash/str9x.c b/src/flash/str9x.c index 665c160..cdee571 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -116,8 +116,7 @@ static int str9x_build_block_list(struct flash_bank_s *bank) /* flash bank str9x <base> <size> 0 0 <target#> */ -static int str9x_flash_bank_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(str9x_flash_bank_command) { str9x_flash_bank_t *str9x_info; diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c index 3a35ee1..4056ba7 100644 --- a/src/flash/str9xpec.c +++ b/src/flash/str9xpec.c @@ -235,7 +235,7 @@ static int str9xpec_build_block_list(struct flash_bank_s *bank) /* flash bank str9x <base> <size> 0 0 <target#> */ -static int str9xpec_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command) { str9xpec_flash_controller_t *str9xpec_info; armv4_5_common_t *armv4_5 = NULL; diff --git a/src/flash/tms470.c b/src/flash/tms470.c index 53043cd..d33ccd6 100644 --- a/src/flash/tms470.c +++ b/src/flash/tms470.c @@ -1222,7 +1222,7 @@ static int tms470_info(struct flash_bank_s *bank, char *buf, int buf_size) * [options...] */ -static int tms470_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank) +FLASH_BANK_COMMAND_HANDLER(tms470_flash_bank_command) { bank->driver_priv = malloc(sizeof(tms470_flash_bank_t)); commit 57c5c5f46304a785092874a7dc0f6abc84794cc3 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 01:39:30 2009 -0800 add FLASH_BANK_COMMAND_HANDLER macro The FLASH_BANK_COMMAND_HANDLER provides an extended command handler using the __COMMAND_HANDLER macro, whereby changing that macro is sufficient to update flash handlers with the new signature. It also enforces uniform style and scope when implementing this handler. diff --git a/src/flash/flash.h b/src/flash/flash.h index 7f5875e..7afb132 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -59,6 +59,9 @@ typedef struct flash_sector_s struct flash_bank_s; +#define __FLASH_BANK_COMMAND(name) \ + COMMAND_HELPER(name, struct flash_bank_s *bank) + /** * @brief Provides the implementation-independent structure that defines * all of the callbacks required by OpenOCD flash drivers. @@ -121,8 +124,7 @@ typedef struct flash_driver_s * * @returns ERROR_OK if successful; otherwise, an error code. */ - int (*flash_bank_command)(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc, struct flash_bank_s *bank); + __FLASH_BANK_COMMAND((*flash_bank_command)); /** * Bank/sector erase routine (target-specific). When @@ -224,6 +226,8 @@ typedef struct flash_driver_s int (*auto_probe)(struct flash_bank_s *bank); } flash_driver_t; +#define FLASH_BANK_COMMAND_HANDLER(name) static __FLASH_BANK_COMMAND(name) + /** * Provides details of a flash bank, available either on-chip or through * a major interface. commit 76868e071306bc83d25b89e57b785fef4637c4c8 Author: Zachary T Welch <zw...@su...> Date: Tue Nov 10 05:32:51 2009 -0800 s3c24xx: use COMMAND_HANDLER with command helper Add S3C24XX_DEVICE_COMMAND macros to abstract common command handler conventions. diff --git a/src/flash/s3c2410_nand.c b/src/flash/s3c2410_nand.c index e663507..176a1a4 100644 --- a/src/flash/s3c2410_nand.c +++ b/src/flash/s3c2410_nand.c @@ -35,11 +35,7 @@ static int s3c2410_nand_device_command(struct command_context_s *cmd_ctx, char * struct nand_device_s *nand) { s3c24xx_nand_controller_t *info; - - info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand); - if (info == NULL) { - return ERROR_NAND_DEVICE_INVALID; - } + CALL_S3C24XX_DEVICE_COMMAND(nand, &info); /* fill in the address fields for the core device */ info->cmd = S3C2410_NFCMD; diff --git a/src/flash/s3c2412_nand.c b/src/flash/s3c2412_nand.c index 5c9d319..7b65f84 100644 --- a/src/flash/s3c2412_nand.c +++ b/src/flash/s3c2412_nand.c @@ -35,11 +35,7 @@ static int s3c2412_nand_device_command(struct command_context_s *cmd_ctx, char * struct nand_device_s *nand) { s3c24xx_nand_controller_t *info; - - info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand); - if (info == NULL) { - return ERROR_NAND_DEVICE_INVALID; - } + CALL_S3C24XX_DEVICE_COMMAND(nand, &info); /* fill in the address fields for the core device */ info->cmd = S3C2440_NFCMD; diff --git a/src/flash/s3c2440_nand.c b/src/flash/s3c2440_nand.c index fd1fbd0..c6d658d 100644 --- a/src/flash/s3c2440_nand.c +++ b/src/flash/s3c2440_nand.c @@ -36,11 +36,7 @@ static int s3c2440_nand_device_command(struct command_context_s *cmd_ctx, char * struct nand_device_s *nand) { s3c24xx_nand_controller_t *info; - - info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand); - if (info == NULL) { - return ERROR_NAND_DEVICE_INVALID; - } + CALL_S3C24XX_DEVICE_COMMAND(nand, &info); /* fill in the address fields for the core device */ info->cmd = S3C2440_NFCMD; diff --git a/src/flash/s3c2443_nand.c b/src/flash/s3c2443_nand.c index 82d9b8e..6e92021 100644 --- a/src/flash/s3c2443_nand.c +++ b/src/flash/s3c2443_nand.c @@ -36,11 +36,7 @@ static int s3c2443_nand_device_command(struct command_context_s *cmd_ctx, char * struct nand_device_s *nand) { s3c24xx_nand_controller_t *info; - - info = s3c24xx_nand_device_command(cmd_ctx, cmd, args, argc, nand); - if (info == NULL) { - return ERROR_NAND_DEVICE_INVALID; - } + CALL_S3C24XX_DEVICE_COMMAND(nand, &info); /* fill in the address fields for the core device */ info->cmd = S3C2440_NFCMD; diff --git a/src/flash/s3c24xx_nand.c b/src/flash/s3c24xx_nand.c index 59d4d5b..e2bc005 100644 --- a/src/flash/s3c24xx_nand.c +++ b/src/flash/s3c24xx_nand.c @@ -31,17 +31,14 @@ #include "s3c24xx_nand.h" -s3c24xx_nand_controller_t * -s3c24xx_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, - char **args, int argc, - struct nand_device_s *nand) +S3C24XX_DEVICE_COMMAND() { s3c24xx_nand_controller_t *s3c24xx_info; s3c24xx_info = malloc(sizeof(s3c24xx_nand_controller_t)); if (s3c24xx_info == NULL) { LOG_ERROR("no memory for nand controller\n"); - return NULL; + return -ENOMEM; } nand->controller_priv = s3c24xx_info; @@ -49,10 +46,10 @@ s3c24xx_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, s3c24xx_info->target = get_target(args[1]); if (s3c24xx_info->target == NULL) { LOG_ERROR("target '%s' not defined", args[1]); - return NULL; + return ERROR_COMMAND_SYNTAX_ERROR; } - return s3c24xx_info; + return ERROR_OK; } int s3c24xx_register_commands(struct command_context_s *cmd_ctx) diff --git a/src/flash/s3c24xx_nand.h b/src/flash/s3c24xx_nand.h index ed14295..3f304a9... [truncated message content] |