add jim_handler to command_registration
Adding jim_handler field to command_registration allows removing the register_jim helper. All command registrations now go through the register_command{,s}() functions.__archive__
parent
cd7e76ebf0
commit
17a9dea53a
|
@ -1368,8 +1368,6 @@ static const struct command_registration flash_exec_command_handlers[] = {
|
||||||
|
|
||||||
int flash_init_drivers(struct command_context *cmd_ctx)
|
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)
|
if (!flash_banks)
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
|
@ -1377,7 +1375,6 @@ int flash_init_drivers(struct command_context *cmd_ctx)
|
||||||
return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
|
return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const struct command_registration flash_config_command_handlers[] = {
|
static const struct command_registration flash_config_command_handlers[] = {
|
||||||
{
|
{
|
||||||
.name = "bank",
|
.name = "bank",
|
||||||
|
@ -1389,6 +1386,12 @@ static const struct command_registration flash_config_command_handlers[] = {
|
||||||
.help = "Define a new bank with the given name, "
|
.help = "Define a new bank with the given name, "
|
||||||
"using the specified NOR flash driver.",
|
"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
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
static const struct command_registration flash_command_handlers[] = {
|
static const struct command_registration flash_command_handlers[] = {
|
||||||
|
|
|
@ -252,6 +252,8 @@ static struct command *command_new(struct command_context *cmd_ctx,
|
||||||
c->usage = strdup(cr->usage);
|
c->usage = strdup(cr->usage);
|
||||||
c->parent = parent;
|
c->parent = parent;
|
||||||
c->handler = cr->handler;
|
c->handler = cr->handler;
|
||||||
|
c->jim_handler = cr->jim_handler;
|
||||||
|
c->jim_handler_data = cr->jim_handler_data;
|
||||||
c->mode = cr->mode;
|
c->mode = cr->mode;
|
||||||
|
|
||||||
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
|
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
|
||||||
|
@ -327,16 +329,22 @@ struct command* register_command(struct command_context *context,
|
||||||
}
|
}
|
||||||
|
|
||||||
c = command_new(context, parent, cr);
|
c = command_new(context, parent, cr);
|
||||||
/* if allocation failed or it is a placeholder (no handler), we're done */
|
if (NULL == c)
|
||||||
if (NULL == c || NULL == c->handler)
|
return NULL;
|
||||||
return c;
|
|
||||||
|
|
||||||
|
if (NULL != c->handler)
|
||||||
|
{
|
||||||
int retval = register_command_handler(c);
|
int retval = register_command_handler(c);
|
||||||
if (ERROR_OK != retval)
|
if (ERROR_OK != retval)
|
||||||
{
|
{
|
||||||
unregister_command(context, parent, name);
|
unregister_command(context, parent, name);
|
||||||
c = NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != cr->jim_handler && NULL == parent)
|
||||||
|
Jim_CreateCommand(interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +890,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
bool found = true;
|
bool found = true;
|
||||||
Jim_Obj *const *start;
|
Jim_Obj *const *start;
|
||||||
unsigned count;
|
unsigned count;
|
||||||
if (c->handler)
|
if (c->handler || c->jim_handler)
|
||||||
{
|
{
|
||||||
// include the command name in the list
|
// include the command name in the list
|
||||||
count = remaining + 1;
|
count = remaining + 1;
|
||||||
|
@ -900,6 +908,12 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
start = argv;
|
start = argv;
|
||||||
found = false;
|
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;
|
unsigned nwords;
|
||||||
const char **words = script_command_args_alloc(count, start, &nwords);
|
const char **words = script_command_args_alloc(count, start, &nwords);
|
||||||
|
@ -1149,18 +1163,6 @@ void process_jim_events(void)
|
||||||
#endif
|
#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) \
|
#define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
|
||||||
int parse##name(const char *str, type *ul) \
|
int parse##name(const char *str, type *ul) \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -164,6 +164,8 @@ struct command
|
||||||
struct command *parent;
|
struct command *parent;
|
||||||
struct command *children;
|
struct command *children;
|
||||||
command_handler_t handler;
|
command_handler_t handler;
|
||||||
|
Jim_CmdProc jim_handler;
|
||||||
|
void *jim_handler_data;
|
||||||
enum command_mode mode;
|
enum command_mode mode;
|
||||||
struct command *next;
|
struct command *next;
|
||||||
};
|
};
|
||||||
|
@ -198,6 +200,8 @@ char *command_name(struct command *c, char delim);
|
||||||
struct command_registration {
|
struct command_registration {
|
||||||
const char *name;
|
const char *name;
|
||||||
command_handler_t handler;
|
command_handler_t handler;
|
||||||
|
Jim_CmdProc jim_handler;
|
||||||
|
void *jim_handler_data;
|
||||||
enum command_mode mode;
|
enum command_mode mode;
|
||||||
const char *help;
|
const char *help;
|
||||||
/// a string listing the options and arguments, required or optional
|
/// a string listing the options and arguments, required or optional
|
||||||
|
@ -319,9 +323,6 @@ void process_jim_events(void);
|
||||||
|
|
||||||
extern Jim_Interp *interp;
|
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_ulong(const char *str, unsigned long *ul);
|
||||||
int parse_ullong(const char *str, unsigned long long *ul);
|
int parse_ullong(const char *str, unsigned long long *ul);
|
||||||
|
|
||||||
|
|
|
@ -685,27 +685,51 @@ static const struct command_registration ioutil_command_handlers[] = {
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.help = "display available ram memory",
|
.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
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int ioutil_init(struct command_context *cmd_ctx)
|
int ioutil_init(struct command_context *cmd_ctx)
|
||||||
{
|
{
|
||||||
register_commands(cmd_ctx, NULL, ioutil_command_handlers);
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1529,26 +1529,37 @@ static const struct command_registration jtag_command_handlers[] = {
|
||||||
.help = "choose short(default) or long tms_sequence",
|
.help = "choose short(default) or long tms_sequence",
|
||||||
.usage = "<short | long>",
|
.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
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
int jtag_register_commands(struct command_context *cmd_ctx)
|
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);
|
return register_commands(cmd_ctx, NULL, jtag_command_handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -777,12 +777,14 @@ int target_init(struct command_context *cmd_ctx)
|
||||||
target->type->mcr = default_mcr;
|
target->type->mcr = default_mcr;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
/* FIX! multiple targets will generally register global commands
|
const struct command_registration mcr_cmd = {
|
||||||
* multiple times. Only register this one if *one* of the
|
.name = "mcr",
|
||||||
* targets need the command. Hmm... make it a command on the
|
.mode = COMMAND_EXEC,
|
||||||
* Jim Tcl target object?
|
.jim_handler = &jim_mcrmrc,
|
||||||
*/
|
.help = "write coprocessor",
|
||||||
register_jim(cmd_ctx, "mcr", jim_mcrmrc, "write coprocessor <cpnum> <op1> <op2> <CRn> <CRm> <value>");
|
.usage = "<cpnum> <op1> <op2> <CRn> <CRm> <value>",
|
||||||
|
};
|
||||||
|
register_command(cmd_ctx, NULL, &mcr_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target->type->mrc == NULL)
|
if (target->type->mrc == NULL)
|
||||||
|
@ -790,7 +792,13 @@ int target_init(struct command_context *cmd_ctx)
|
||||||
target->type->mrc = default_mrc;
|
target->type->mrc = default_mrc;
|
||||||
} else
|
} 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4377,14 +4385,14 @@ static int target_create(Jim_GetOptInfo *goi)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now - create the new target name command */
|
/* now - create the new target name command */
|
||||||
e = Jim_CreateCommand(goi->interp,
|
const struct command_registration target_command = {
|
||||||
/* name */
|
.name = cp,
|
||||||
cp,
|
.jim_handler = &tcl_target_func,
|
||||||
tcl_target_func, /* C function */
|
.jim_handler_data = target,
|
||||||
target, /* private data */
|
.help = "target command group",
|
||||||
NULL); /* no del proc */
|
};
|
||||||
|
struct command *c = register_command(cmd_ctx, NULL, &target_command);
|
||||||
return e;
|
return (NULL != c) ? ERROR_OK : ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
|
@ -4773,12 +4781,17 @@ static const struct command_registration target_command_handlers[] = {
|
||||||
"or list targets (no parameters)",
|
"or list targets (no parameters)",
|
||||||
.usage = "[<new_current_target>]",
|
.usage = "[<new_current_target>]",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "target",
|
||||||
|
.mode = COMMAND_CONFIG,
|
||||||
|
.jim_handler = &jim_target,
|
||||||
|
.help = "configure target",
|
||||||
|
},
|
||||||
COMMAND_REGISTRATION_DONE
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
int target_register_commands(struct command_context *cmd_ctx)
|
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);
|
return register_commands(cmd_ctx, NULL, target_command_handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4967,6 +4980,22 @@ static const struct command_registration target_exec_command_handlers[] = {
|
||||||
.mode = COMMAND_EXEC,
|
.mode = COMMAND_EXEC,
|
||||||
.usage = "<file> [offset] [type]",
|
.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
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
int target_register_user_commands(struct command_context *cmd_ctx)
|
int target_register_user_commands(struct command_context *cmd_ctx)
|
||||||
|
@ -4978,13 +5007,6 @@ int target_register_user_commands(struct command_context *cmd_ctx)
|
||||||
if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
|
if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
|
||||||
return retval;
|
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);
|
return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue