forked from auracaster/openocd
target: arm_dap: rewrite commands 'dap create' as COMMAND_HANDLER
Rewrite only the command, but still use the old jimtcl specific code in dap_configure(). Change-Id: I3360884616367aae52f5b32247d9864000c53fdc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8897 Tested-by: jenkins
This commit is contained in:
@@ -333,61 +333,59 @@ static int dap_check_config(struct adiv5_dap *dap)
|
|||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dap_create(struct jim_getopt_info *goi)
|
COMMAND_HANDLER(handle_dap_create)
|
||||||
{
|
{
|
||||||
struct command_context *cmd_ctx;
|
if (CMD_ARGC < 3)
|
||||||
static struct arm_dap_object *dap;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
Jim_Obj *new_cmd;
|
|
||||||
Jim_Cmd *cmd;
|
|
||||||
const char *cp;
|
|
||||||
int e;
|
|
||||||
|
|
||||||
cmd_ctx = current_command_context(goi->interp);
|
int retval = ERROR_COMMAND_ARGUMENT_INVALID;
|
||||||
assert(cmd_ctx);
|
|
||||||
|
|
||||||
if (goi->argc < 3) {
|
/* check if the dap name clashes with an existing command name */
|
||||||
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
|
Jim_Cmd *jimcmd = Jim_GetCommand(CMD_CTX->interp, CMD_JIMTCL_ARGV[0], JIM_NONE);
|
||||||
return JIM_ERR;
|
if (jimcmd) {
|
||||||
}
|
command_print(CMD, "Command/dap: %s Exists", CMD_ARGV[0]);
|
||||||
/* COMMAND */
|
return ERROR_FAIL;
|
||||||
jim_getopt_obj(goi, &new_cmd);
|
|
||||||
/* does this command exist? */
|
|
||||||
cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_NONE);
|
|
||||||
if (cmd) {
|
|
||||||
cp = Jim_GetString(new_cmd, NULL);
|
|
||||||
Jim_SetResultFormatted(goi->interp, "Command: %s Exists", cp);
|
|
||||||
return JIM_ERR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create it */
|
/* Create it */
|
||||||
dap = calloc(1, sizeof(struct arm_dap_object));
|
struct arm_dap_object *dap = calloc(1, sizeof(struct arm_dap_object));
|
||||||
if (!dap)
|
if (!dap) {
|
||||||
return JIM_ERR;
|
LOG_ERROR("Out of memory");
|
||||||
|
return ERROR_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
dap_instance_init(&dap->dap);
|
dap_instance_init(&dap->dap);
|
||||||
|
|
||||||
cp = Jim_GetString(new_cmd, NULL);
|
dap->name = strdup(CMD_ARGV[0]);
|
||||||
dap->name = strdup(cp);
|
if (!dap->name) {
|
||||||
|
LOG_ERROR("Out of memory");
|
||||||
|
free(dap);
|
||||||
|
return ERROR_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
e = dap_configure(goi, dap);
|
struct jim_getopt_info goi;
|
||||||
if (e != JIM_OK)
|
jim_getopt_setup(&goi, CMD_CTX->interp, CMD_ARGC - 1, CMD_JIMTCL_ARGV + 1);
|
||||||
|
int e = dap_configure(&goi, dap);
|
||||||
|
if (e != JIM_OK) {
|
||||||
|
int reslen;
|
||||||
|
const char *result = Jim_GetString(Jim_GetResult(CMD_CTX->interp), &reslen);
|
||||||
|
if (reslen > 0)
|
||||||
|
command_print(CMD, "%s", result);
|
||||||
goto err;
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dap->dap.tap) {
|
if (!dap->dap.tap) {
|
||||||
Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
|
command_print(CMD, "-chain-position required when creating DAP");
|
||||||
e = JIM_ERR;
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = dap_check_config(&dap->dap);
|
retval = dap_check_config(&dap->dap);
|
||||||
if (e != ERROR_OK) {
|
if (retval != ERROR_OK)
|
||||||
e = JIM_ERR;
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
struct command_registration dap_create_commands[] = {
|
struct command_registration dap_create_commands[] = {
|
||||||
{
|
{
|
||||||
.name = cp,
|
.name = CMD_ARGV[0],
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.help = "dap instance command group",
|
.help = "dap instance command group",
|
||||||
.usage = "",
|
.usage = "",
|
||||||
@@ -400,32 +398,18 @@ static int dap_create(struct jim_getopt_info *goi)
|
|||||||
if (transport_is_hla())
|
if (transport_is_hla())
|
||||||
dap_create_commands[0].chain = NULL;
|
dap_create_commands[0].chain = NULL;
|
||||||
|
|
||||||
e = register_commands_with_data(cmd_ctx, NULL, dap_create_commands, dap);
|
retval = register_commands_with_data(CMD_CTX, NULL, dap_create_commands, dap);
|
||||||
if (e != ERROR_OK) {
|
if (retval != ERROR_OK)
|
||||||
e = JIM_ERR;
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
list_add_tail(&dap->lh, &all_dap);
|
list_add_tail(&dap->lh, &all_dap);
|
||||||
|
|
||||||
return JIM_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
free(dap->name);
|
free(dap->name);
|
||||||
free(dap);
|
free(dap);
|
||||||
return e;
|
return retval;
|
||||||
}
|
|
||||||
|
|
||||||
static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
|
||||||
{
|
|
||||||
struct jim_getopt_info goi;
|
|
||||||
jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
|
|
||||||
if (goi.argc < 2) {
|
|
||||||
Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv,
|
|
||||||
"<name> [<dap_options> ...]");
|
|
||||||
return JIM_ERR;
|
|
||||||
}
|
|
||||||
return dap_create(&goi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND_HANDLER(handle_dap_names)
|
COMMAND_HANDLER(handle_dap_names)
|
||||||
@@ -496,7 +480,7 @@ static const struct command_registration dap_subcommand_handlers[] = {
|
|||||||
{
|
{
|
||||||
.name = "create",
|
.name = "create",
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.jim_handler = jim_dap_create,
|
.handler = handle_dap_create,
|
||||||
.usage = "name '-chain-position' name",
|
.usage = "name '-chain-position' name",
|
||||||
.help = "Creates a new DAP instance",
|
.help = "Creates a new DAP instance",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user