]> git.sur5r.net Git - openocd/commitdiff
cortex_m: allow setting debug ap during create
authorMatthias Welwarsky <matthias.welwarsky@sysgo.com>
Sun, 13 Nov 2016 12:23:08 +0000 (13:23 +0100)
committerPaul Fertser <fercerpav@gmail.com>
Thu, 8 Dec 2016 12:35:58 +0000 (12:35 +0000)
This patch adds a Cortex-M private configuration option
that allows setting the acess point during target
creation. This circumvents situations in hybrid systems
when the correct access point can not be automatically
detected.

Change-Id: If313a5250e6e66509bb9080f3498feab7781dced
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
Reviewed-on: http://openocd.zylin.com/3639
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
doc/openocd.texi
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h
src/target/cortex_m.c
src/target/cortex_m.h
src/target/target.h

index 7c2152b1c927a8987cc0b35a480f61513c8478cd..b47d2c4479209ee1e7c8697793d4033d38f3eeb9 100644 (file)
@@ -4152,6 +4152,10 @@ The value should normally correspond to a static mapping for the
 scan and after a reset. A manual call to arp_examine is required to
 access the target for debugging.
 
+@item @code{-ap-num} @var{ap_number} -- set DAP access port for target,
+@var{ap_number} is the numeric index of the DAP AP the target is connected to.
+Use this option with systems where multiple, independent cores are connected
+to separate access ports of the same DAP.
 @end itemize
 @end deffn
 
index 39f2b399bfbee1ac6678483304c0de2718cfef34..eafc2ddc082f276fd72076f421bc6077fc771b7a 100644 (file)
@@ -1359,6 +1359,41 @@ static int dap_info_command(struct command_context *cmd_ctx,
        return ERROR_OK;
 }
 
+int adiv5_jim_configure(struct target *target, Jim_GetOptInfo *goi)
+{
+       struct adiv5_private_config *pc;
+       const char *arg;
+       jim_wide ap_num;
+       int e;
+
+       /* check if argv[0] is for us */
+       arg = Jim_GetString(goi->argv[0], NULL);
+       if (strcmp(arg, "-ap-num"))
+               return JIM_CONTINUE;
+
+       e = Jim_GetOpt_String(goi, &arg, NULL);
+       if (e != JIM_OK)
+               return e;
+
+       if (goi->argc == 0) {
+               Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-ap-num ?ap-number? ...");
+               return JIM_ERR;
+       }
+
+       e = Jim_GetOpt_Wide(goi, &ap_num);
+       if (e != JIM_OK)
+               return e;
+
+       if (target->private_config == NULL) {
+               pc = calloc(1, sizeof(struct adiv5_private_config));
+               target->private_config = pc;
+               pc->ap_num = ap_num;
+       }
+
+
+       return JIM_OK;
+}
+
 COMMAND_HANDLER(handle_dap_info_command)
 {
        struct target *target = get_current_target(CMD_CTX);
index 3220d8b6d27e12c260b43a6a80cd8a9d426a6241..bf9cb5ccee51a208fdda3ce8f9a4ef8fc77209fa 100644 (file)
@@ -504,4 +504,10 @@ int dap_to_jtag(struct target *target);
 
 extern const struct command_registration dap_command_handlers[];
 
+struct adiv5_private_config {
+       int ap_num;
+};
+
+extern int adiv5_jim_configure(struct target *target, Jim_GetOptInfo *goi);
+
 #endif /* OPENOCD_TARGET_ARM_ADI_V5_H */
index f674cc527c0a6a7c7e5fa6fa616436c3607663f6..36a774671d77fdc4b85a3fa8a9520dc14a208d7c 100644 (file)
@@ -1709,6 +1709,7 @@ void cortex_m_deinit_target(struct target *target)
        cortex_m_dwt_free(target);
        armv7m_free_reg_cache(target);
 
+       free(target->private_config);
        free(cortex_m);
 }
 
@@ -1912,11 +1913,15 @@ int cortex_m_examine(struct target *target)
                        return retval;
                }
 
-               /* Search for the MEM-AP */
-               retval = dap_find_ap(swjdp, AP_TYPE_AHB_AP, &armv7m->debug_ap);
-               if (retval != ERROR_OK) {
-                       LOG_ERROR("Could not find MEM-AP to control the core");
-                       return retval;
+               if (cortex_m->apsel < 0) {
+                       /* Search for the MEM-AP */
+                       retval = dap_find_ap(swjdp, AP_TYPE_AHB_AP, &armv7m->debug_ap);
+                       if (retval != ERROR_OK) {
+                               LOG_ERROR("Could not find MEM-AP to control the core");
+                               return retval;
+                       }
+               } else {
+                       armv7m->debug_ap = dap_ap(swjdp, cortex_m->apsel);
                }
 
                /* Leave (only) generic DAP stuff for debugport_init(); */
@@ -2180,6 +2185,13 @@ static int cortex_m_target_create(struct target *target, Jim_Interp *interp)
        cortex_m->common_magic = CORTEX_M_COMMON_MAGIC;
        cortex_m_init_arch_info(target, cortex_m, target->tap);
 
+       if (target->private_config != NULL) {
+               struct adiv5_private_config *pc =
+                               (struct adiv5_private_config *)target->private_config;
+               cortex_m->apsel = pc->ap_num;
+       } else
+               cortex_m->apsel = -1;
+
        return ERROR_OK;
 }
 
@@ -2441,6 +2453,7 @@ struct target_type cortexm_target = {
 
        .commands = cortex_m_command_handlers,
        .target_create = cortex_m_target_create,
+       .target_jim_configure = adiv5_jim_configure,
        .init_target = cortex_m_init_target,
        .examine = cortex_m_examine,
        .deinit_target = cortex_m_deinit_target,
index eabaac49f45e6170ed26ca29fdb69657a1ccbbfe..3d9714b9005fc2a1c57ed016ccd22cd65386e10f 100644 (file)
@@ -188,6 +188,8 @@ struct cortex_m_common {
        enum cortex_m_isrmasking_mode isrmasking_mode;
 
        struct armv7m_common armv7m;
+
+       int apsel;
 };
 
 static inline struct cortex_m_common *
index 7f6ac148579c15dd93243c876d98d7ef794b584f..e86b700a3fb69863c8300b673a69626e109df3cf 100644 (file)
@@ -173,6 +173,7 @@ struct target {
        struct debug_msg_receiver *dbgmsg;      /* list of debug message receivers */
        uint32_t dbg_msg_enabled;                       /* debug message status */
        void *arch_info;                                        /* architecture specific information */
+       void *private_config;                           /* pointer to target specific config data (for jim_configure hook) */
        struct target *next;                            /* next target in list */
 
        int display;                                            /* display async info in telnet session. Do not display