Upstream a whole host of RISC-V changes.
[openocd.git] / src / target / arm_dap.c
index 797feb5bafdf83dbe36ff5bf338fe52afafdd8bd..94edfc09d14116859955ffc3a263b5aad612b71d 100644 (file)
@@ -34,7 +34,7 @@ static LIST_HEAD(all_dap);
 
 extern const struct dap_ops swd_dap_ops;
 extern const struct dap_ops jtag_dp_ops;
-extern struct jtag_interface *jtag_interface;
+extern struct adapter_driver *adapter_driver;
 
 /* DAP command support */
 struct arm_dap_object {
@@ -48,15 +48,19 @@ static void dap_instance_init(struct adiv5_dap *dap)
 {
        int i;
        /* Set up with safe defaults */
-       for (i = 0; i <= 255; i++) {
+       for (i = 0; i <= DP_APSEL_MAX; i++) {
                dap->ap[i].dap = dap;
                dap->ap[i].ap_num = i;
                /* memaccess_tck max is 255 */
                dap->ap[i].memaccess_tck = 255;
                /* Number of bits for tar autoincrement, impl. dep. at least 10 */
                dap->ap[i].tar_autoincr_block = (1<<10);
+               /* default CSW value */
+               dap->ap[i].csw_default = CSW_AHB_DEFAULT;
+               dap->ap[i].cfg_reg = MEM_AP_REG_CFG_INVALID; /* mem_ap configuration reg (large physical addr, etc.) */
        }
        INIT_LIST_HEAD(&dap->cmd_journal);
+       INIT_LIST_HEAD(&dap->cmd_pool);
 }
 
 const char *adiv5_dap_name(struct adiv5_dap *self)
@@ -115,7 +119,11 @@ static int dap_init_all(void)
 
                if (transport_is_swd()) {
                        dap->ops = &swd_dap_ops;
-                       obj->swd = jtag_interface->swd;
+                       obj->swd = adapter_driver->swd_ops;
+               } else if (transport_is_dapdirect_swd()) {
+                       dap->ops = adapter_driver->dap_swd_ops;
+               } else if (transport_is_dapdirect_jtag()) {
+                       dap->ops = adapter_driver->dap_jtag_ops;
                } else
                        dap->ops = &jtag_dp_ops;
 
@@ -130,8 +138,13 @@ static int dap_init_all(void)
 int dap_cleanup_all(void)
 {
        struct arm_dap_object *obj, *tmp;
+       struct adiv5_dap *dap;
 
        list_for_each_entry_safe(obj, tmp, &all_dap, lh) {
+               dap = &obj->dap;
+               if (dap->ops && dap->ops->quit)
+                       dap->ops->quit(dap);
+
                free(obj->name);
                free(obj);
        }
@@ -144,35 +157,35 @@ enum dap_cfg_param {
        CFG_IGNORE_SYSPWRUPACK,
 };
 
-static const Jim_Nvp nvp_config_opts[] = {
+static const struct jim_nvp nvp_config_opts[] = {
        { .name = "-chain-position",   .value = CFG_CHAIN_POSITION },
        { .name = "-ignore-syspwrupack", .value = CFG_IGNORE_SYSPWRUPACK },
        { .name = NULL, .value = -1 }
 };
 
-static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap)
+static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap)
 {
        struct jtag_tap *tap = NULL;
-       Jim_Nvp *n;
+       struct jim_nvp *n;
        int e;
 
        /* parse config or cget options ... */
        while (goi->argc > 0) {
                Jim_SetEmptyResult(goi->interp);
 
-               e = Jim_GetOpt_Nvp(goi, nvp_config_opts, &n);
+               e = jim_getopt_nvp(goi, nvp_config_opts, &n);
                if (e != JIM_OK) {
-                       Jim_GetOpt_NvpUnknown(goi, nvp_config_opts, 0);
+                       jim_getopt_nvp_unknown(goi, nvp_config_opts, 0);
                        return e;
                }
                switch (n->value) {
                case CFG_CHAIN_POSITION: {
                        Jim_Obj *o_t;
-                       e = Jim_GetOpt_Obj(goi, &o_t);
+                       e = jim_getopt_obj(goi, &o_t);
                        if (e != JIM_OK)
                                return e;
                        tap = jtag_tap_by_jim_obj(goi->interp, o_t);
-                       if (tap == NULL) {
+                       if (!tap) {
                                Jim_SetResultString(goi->interp, "-chain-position is invalid", -1);
                                return JIM_ERR;
                        }
@@ -187,7 +200,7 @@ static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap)
                }
        }
 
-       if (tap == NULL) {
+       if (!tap) {
                Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
                return JIM_ERR;
        }
@@ -198,7 +211,7 @@ static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap)
        return JIM_OK;
 }
 
-static int dap_create(Jim_GetOptInfo *goi)
+static int dap_create(struct jim_getopt_info *goi)
 {
        struct command_context *cmd_ctx;
        static struct arm_dap_object *dap;
@@ -208,16 +221,16 @@ static int dap_create(Jim_GetOptInfo *goi)
        int e;
 
        cmd_ctx = current_command_context(goi->interp);
-       assert(cmd_ctx != NULL);
+       assert(cmd_ctx);
 
        if (goi->argc < 3) {
                Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
                return JIM_ERR;
        }
        /* COMMAND */
-       Jim_GetOpt_Obj(goi, &new_cmd);
+       jim_getopt_obj(goi, &new_cmd);
        /* does this command exist? */
-       cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_ERRMSG);
+       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);
@@ -226,7 +239,7 @@ static int dap_create(Jim_GetOptInfo *goi)
 
        /* Create it */
        dap = calloc(1, sizeof(struct arm_dap_object));
-       if (dap == NULL)
+       if (!dap)
                return JIM_ERR;
 
        e = dap_configure(goi, dap);
@@ -253,23 +266,19 @@ static int dap_create(Jim_GetOptInfo *goi)
        if (transport_is_hla())
                dap_commands[0].chain = NULL;
 
-       e = register_commands(cmd_ctx, NULL, dap_commands);
-       if (ERROR_OK != e)
+       e = register_commands_with_data(cmd_ctx, NULL, dap_commands, dap);
+       if (e != ERROR_OK)
                return JIM_ERR;
 
-       struct command *c = command_find_in_context(cmd_ctx, cp);
-       assert(c);
-       command_set_handler_data(c, dap);
-
        list_add_tail(&dap->lh, &all_dap);
 
-       return (ERROR_OK == e) ? JIM_OK : JIM_ERR;
+       return JIM_OK;
 }
 
 static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       Jim_GetOptInfo goi;
-       Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1);
+       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> ...]");
@@ -306,20 +315,25 @@ COMMAND_HANDLER(handle_dap_info_command)
        struct adiv5_dap *dap = arm->dap;
        uint32_t apsel;
 
+       if (!dap) {
+               LOG_ERROR("DAP instance not available. Probably a HLA target...");
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+       }
+
        switch (CMD_ARGC) {
                case 0:
                        apsel = dap->apsel;
                        break;
                case 1:
                        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
-                       if (apsel >= 256)
+                       if (apsel > DP_APSEL_MAX)
                                return ERROR_COMMAND_SYNTAX_ERROR;
                        break;
                default:
                        return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       return dap_info_command(CMD_CTX, &dap->ap[apsel]);
+       return dap_info_command(CMD, &dap->ap[apsel]);
 }
 
 static const struct command_registration dap_subcommand_handlers[] = {
@@ -361,6 +375,7 @@ static const struct command_registration dap_commands[] = {
                .mode = COMMAND_CONFIG,
                .help = "DAP commands",
                .chain = dap_subcommand_handlers,
+               .usage = "",
        },
        COMMAND_REGISTRATION_DONE
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)