int flash_init_drivers(struct command_context *cmd_ctx)
{
- register_jim(cmd_ctx, "ocd_flash_banks",
- jim_flash_banks, "return information about the flash banks");
if (!flash_banks)
return ERROR_OK;
return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
}
-
static const struct command_registration flash_config_command_handlers[] = {
{
.name = "bank",
.help = "Define a new bank with the given name, "
"using the specified NOR flash driver.",
},
+ {
+ .name = "banks",
+ .mode = COMMAND_ANY,
+ .jim_handler = &jim_flash_banks,
+ .help = "return information about the flash banks",
+ },
COMMAND_REGISTRATION_DONE
};
static const struct command_registration flash_command_handlers[] = {
c->usage = strdup(cr->usage);
c->parent = parent;
c->handler = cr->handler;
+ c->jim_handler = cr->jim_handler;
+ c->jim_handler_data = cr->jim_handler_data;
c->mode = cr->mode;
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
}
c = command_new(context, parent, cr);
- /* if allocation failed or it is a placeholder (no handler), we're done */
- if (NULL == c || NULL == c->handler)
- return c;
+ if (NULL == c)
+ return NULL;
- int retval = register_command_handler(c);
- if (ERROR_OK != retval)
+ if (NULL != c->handler)
{
- unregister_command(context, parent, name);
- c = NULL;
+ int retval = register_command_handler(c);
+ if (ERROR_OK != retval)
+ {
+ unregister_command(context, parent, name);
+ return NULL;
+ }
}
+
+ if (NULL != cr->jim_handler && NULL == parent)
+ Jim_CreateCommand(interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL);
+
return c;
}
bool found = true;
Jim_Obj *const *start;
unsigned count;
- if (c->handler)
+ if (c->handler || c->jim_handler)
{
// include the command name in the list
count = remaining + 1;
start = argv;
found = false;
}
+ // pass the command through to the intended handler
+ if (c->jim_handler)
+ {
+ interp->cmdPrivData = c->jim_handler_data;
+ return (*c->jim_handler)(interp, count, start);
+ }
unsigned nwords;
const char **words = script_command_args_alloc(count, start, &nwords);
#endif
}
-void register_jim(struct command_context *cmd_ctx, const char *name,
- Jim_CmdProc cmd, const char *help)
-{
- Jim_CreateCommand(interp, name, cmd, NULL, NULL);
-
- Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
- Jim_ListAppendElement(interp, cmd_list,
- Jim_NewStringObj(interp, name, -1));
-
- help_add_command(cmd_ctx, NULL, name, help, NULL);
-}
-
#define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
int parse##name(const char *str, type *ul) \
{ \
struct command *parent;
struct command *children;
command_handler_t handler;
+ Jim_CmdProc jim_handler;
+ void *jim_handler_data;
enum command_mode mode;
struct command *next;
};
struct command_registration {
const char *name;
command_handler_t handler;
+ Jim_CmdProc jim_handler;
+ void *jim_handler_data;
enum command_mode mode;
const char *help;
/// a string listing the options and arguments, required or optional
extern Jim_Interp *interp;
-void register_jim(struct command_context *context, const char *name,
- Jim_CmdProc cmd, const char *help);
-
int parse_ulong(const char *str, unsigned long *ul);
int parse_ullong(const char *str, unsigned long long *ul);
.mode = COMMAND_ANY,
.help = "display available ram memory",
},
+ // jim handlers
+ {
+ .name = "rm",
+ .mode = COMMAND_ANY,
+ .jim_handler = &zylinjtag_Jim_Command_rm,
+ .help = "remove a file",
+ .usage = "<file>",
+ },
+ {
+ .name = "peek",
+ .mode = COMMAND_ANY,
+ .jim_handler = &zylinjtag_Jim_Command_peek,
+ .help = "peek at a memory address",
+ .usage = "<addr>",
+ },
+ {
+ .name = "poke",
+ .mode = COMMAND_ANY,
+ .jim_handler = &zylinjtag_Jim_Command_poke,
+ .help = "poke at a memory address",
+ .usage = "<addr> <value>",
+ },
+ {
+ .name = "ls",
+ .mode = COMMAND_ANY,
+ .jim_handler = &zylinjtag_Jim_Command_ls,
+ .help = "show a listing of files",
+ .usage = "<dir>",
+ },
+ {
+ .name = "mac",
+ .mode = COMMAND_ANY,
+ .jim_handler = &zylinjtag_Jim_Command_mac,
+ .help = "show MAC address",
+ },
+ {
+ .name = "ip",
+ .jim_handler = &zylinjtag_Jim_Command_ip,
+ .mode = COMMAND_ANY,
+ .help = "show IP address",
+ },
COMMAND_REGISTRATION_DONE
};
-
int ioutil_init(struct command_context *cmd_ctx)
{
- register_commands(cmd_ctx, NULL, ioutil_command_handlers);
-
- Jim_CreateCommand(interp, "rm", zylinjtag_Jim_Command_rm, NULL, NULL);
-
- Jim_CreateCommand(interp, "peek", zylinjtag_Jim_Command_peek, NULL, NULL);
- Jim_CreateCommand(interp, "poke", zylinjtag_Jim_Command_poke, NULL, NULL);
- Jim_CreateCommand(interp, "ls", zylinjtag_Jim_Command_ls, NULL, NULL);
-
- Jim_CreateCommand(interp, "mac", zylinjtag_Jim_Command_mac,
- NULL, NULL);
-
- Jim_CreateCommand(interp, "ip", zylinjtag_Jim_Command_ip,
- NULL, NULL);
-
- return ERROR_OK;
+ return register_commands(cmd_ctx, NULL, ioutil_command_handlers);
}
-
-
.help = "choose short(default) or long tms_sequence",
.usage = "<short | long>",
},
+ // jim commands
+ {
+ .name = "jtag",
+ .mode = COMMAND_ANY,
+ .jim_handler = &jim_jtag_command,
+ .help = "perform jtag tap actions",
+ },
+ {
+ .name = "drscan",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &Jim_Command_drscan,
+ .help = "execute DR scan <device> "
+ "<num_bits> <value> <num_bits1> <value2> ...",
+ },
+ {
+ .name = "flush_count",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &Jim_Command_flush_count,
+ .help = "returns number of times the JTAG queue has been flushed",
+ },
+ {
+ .name = "pathmove",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &Jim_Command_pathmove,
+ .usage = "<state1>,<state2>,<state3>... ",
+ .help = "move JTAG to state1 then to state2, state3, etc.",
+ },
COMMAND_REGISTRATION_DONE
};
int jtag_register_commands(struct command_context *cmd_ctx)
{
- register_jim(cmd_ctx, "jtag", jim_jtag_command,
- "perform jtag tap actions");
-
- register_jim(cmd_ctx, "drscan", Jim_Command_drscan,
- "execute DR scan <device> "
- "<num_bits> <value> <num_bits1> <value2> ...");
-
- register_jim(cmd_ctx, "flush_count", Jim_Command_flush_count,
- "returns number of times the JTAG queue has been flushed");
-
- register_jim(cmd_ctx, "pathmove", Jim_Command_pathmove,
- "<state1>,<state2>,<state3>... "
- "- move JTAG to state1 then to state2, state3, etc.");
-
return register_commands(cmd_ctx, NULL, jtag_command_handlers);
}
-
-
target->type->mcr = default_mcr;
} else
{
- /* FIX! multiple targets will generally register global commands
- * multiple times. Only register this one if *one* of the
- * targets need the command. Hmm... make it a command on the
- * Jim Tcl target object?
- */
- register_jim(cmd_ctx, "mcr", jim_mcrmrc, "write coprocessor <cpnum> <op1> <op2> <CRn> <CRm> <value>");
+ const struct command_registration mcr_cmd = {
+ .name = "mcr",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &jim_mcrmrc,
+ .help = "write coprocessor",
+ .usage = "<cpnum> <op1> <op2> <CRn> <CRm> <value>",
+ };
+ register_command(cmd_ctx, NULL, &mcr_cmd);
}
if (target->type->mrc == NULL)
target->type->mrc = default_mrc;
} else
{
- register_jim(cmd_ctx, "mrc", jim_mcrmrc, "read coprocessor <cpnum> <op1> <op2> <CRn> <CRm>");
+ const struct command_registration mrc_cmd = {
+ .name = "mrc",
+ .jim_handler = &jim_mcrmrc,
+ .help = "read coprocessor",
+ .usage = "<cpnum> <op1> <op2> <CRn> <CRm>",
+ };
+ register_command(cmd_ctx, NULL, &mrc_cmd);
}
}
/* now - create the new target name command */
- e = Jim_CreateCommand(goi->interp,
- /* name */
- cp,
- tcl_target_func, /* C function */
- target, /* private data */
- NULL); /* no del proc */
-
- return e;
+ const struct command_registration target_command = {
+ .name = cp,
+ .jim_handler = &tcl_target_func,
+ .jim_handler_data = target,
+ .help = "target command group",
+ };
+ struct command *c = register_command(cmd_ctx, NULL, &target_command);
+ return (NULL != c) ? ERROR_OK : ERROR_FAIL;
}
static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
"or list targets (no parameters)",
.usage = "[<new_current_target>]",
},
+ {
+ .name = "target",
+ .mode = COMMAND_CONFIG,
+ .jim_handler = &jim_target,
+ .help = "configure target",
+ },
COMMAND_REGISTRATION_DONE
};
int target_register_commands(struct command_context *cmd_ctx)
{
- register_jim(cmd_ctx, "target", jim_target, "configure target");
return register_commands(cmd_ctx, NULL, target_command_handlers);
}
.mode = COMMAND_EXEC,
.usage = "<file> [offset] [type]",
},
+ {
+ .name = "ocd_mem2array",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &jim_mem2array,
+ .help = "read memory and return as a TCL array "
+ "for script processing",
+ .usage = "<arrayname> <width=32|16|8> <address> <count>",
+ },
+ {
+ .name = "ocd_array2mem",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &jim_array2mem,
+ .help = "convert a TCL array to memory locations "
+ "and write the values",
+ .usage = "<arrayname> <width=32|16|8> <address> <count>",
+ },
COMMAND_REGISTRATION_DONE
};
int target_register_user_commands(struct command_context *cmd_ctx)
if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
return retval;
- register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array,
- "read memory and return as a TCL array for script processing "
- "<ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>");
-
- register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem,
- "convert a TCL array to memory locations and write the values "
- "<ARRAYNAME> <WIDTH = 32/16/8> <ADDRESS> <COUNT>");
return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
}