This is an automated email from Gerrit.

"Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/8138

-- gerrit

commit cd5456eba2475afee15ef52d36c3076502ead7fe
Author: Tomas Vanek <van...@fbl.cz>
Date:   Sun Feb 11 17:22:38 2024 +0100

    target/arm_adi_v5: introduce adiv5_jim_configure_ext()
    
    Allow direct pointer to struct adiv5_private_config
    for targets with adiv5_private_config inside of a bigger
    private config container. Use it instead of the private_config
    pointer toggling hack in aarch64.c
    
    Allow optional use of -dap parameter and use it instead
    of the static variable hack in xtensa_chip.c
    
    Signed-off-by: Tomas Vanek <van...@fbl.cz>
    Change-Id: I7260c79332940adfa49d57b45cae39325cdaf432

diff --git a/src/target/aarch64.c b/src/target/aarch64.c
index 1c056a015e..36bcddc31c 100644
--- a/src/target/aarch64.c
+++ b/src/target/aarch64.c
@@ -2891,13 +2891,8 @@ static int aarch64_jim_configure(struct target *target, 
struct jim_getopt_info *
         * options, JIM_OK if it correctly parsed the topmost option
         * and JIM_ERR if an error occurred during parameter evaluation.
         * For JIM_CONTINUE, we check our own params.
-        *
-        * adiv5_jim_configure() assumes 'private_config' to point to
-        * 'struct adiv5_private_config'. Override 'private_config'!
         */
-       target->private_config = &pc->adiv5_config;
-       e = adiv5_jim_configure(target, goi);
-       target->private_config = pc;
+       e = adiv5_jim_configure_ext(target, goi, &pc->adiv5_config, 
ADI_CONFIGURE_DAP_COMPULSORY);
        if (e != JIM_CONTINUE)
                return e;
 
diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c
index ff12658c83..9129acecf9 100644
--- a/src/target/arm_adi_v5.c
+++ b/src/target/arm_adi_v5.c
@@ -2424,23 +2424,26 @@ err_no_param:
        return JIM_ERR;
 }
 
-int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi)
+int adiv5_jim_configure_ext(struct target *target, struct jim_getopt_info *goi,
+               struct adiv5_private_config *pc, enum 
adiv5_configure_dap_optional optional)
 {
-       struct adiv5_private_config *pc;
        int e;
 
-       pc = (struct adiv5_private_config *)target->private_config;
        if (!pc) {
-               pc = calloc(1, sizeof(struct adiv5_private_config));
+               pc = (struct adiv5_private_config *)target->private_config;
                if (!pc) {
-                       LOG_ERROR("Out of memory");
-                       return JIM_ERR;
+                       pc = calloc(1, sizeof(struct adiv5_private_config));
+                       if (!pc) {
+                               LOG_ERROR("Out of memory");
+                               return JIM_ERR;
+                       }
+                       pc->ap_num = DP_APSEL_INVALID;
+                       target->private_config = pc;
                }
-               pc->ap_num = DP_APSEL_INVALID;
-               target->private_config = pc;
        }
 
-       target->has_dap = true;
+       if (optional == ADI_CONFIGURE_DAP_COMPULSORY)
+               target->has_dap = true;
 
        e = adiv5_jim_spot_configure(goi, &pc->dap, &pc->ap_num, NULL);
        if (e != JIM_OK)
@@ -2455,11 +2458,17 @@ int adiv5_jim_configure(struct target *target, struct 
jim_getopt_info *goi)
                }
                target->tap = pc->dap->tap;
                target->dap_configured = true;
+               target->has_dap = true;
        }
 
        return JIM_OK;
 }
 
+int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi)
+{
+       return adiv5_jim_configure_ext(target, goi, NULL, 
ADI_CONFIGURE_DAP_COMPULSORY);
+}
+
 int adiv5_verify_config(struct adiv5_private_config *pc)
 {
        if (!pc)
diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h
index 60c161f3ca..92c3dbc3a6 100644
--- a/src/target/arm_adi_v5.h
+++ b/src/target/arm_adi_v5.h
@@ -788,6 +788,15 @@ struct adiv5_private_config {
 };
 
 extern int adiv5_verify_config(struct adiv5_private_config *pc);
+
+enum adiv5_configure_dap_optional {
+       ADI_CONFIGURE_DAP_COMPULSORY = false,
+       ADI_CONFIGURE_DAP_OPTIONAL = true
+};
+
+extern int adiv5_jim_configure_ext(struct target *target, struct 
jim_getopt_info *goi,
+                                                                  struct 
adiv5_private_config *pc,
+                                                                  enum 
adiv5_configure_dap_optional optional);
 extern int adiv5_jim_configure(struct target *target, struct jim_getopt_info 
*goi);
 
 struct adiv5_mem_ap_spot {
diff --git a/src/target/xtensa/xtensa_chip.c b/src/target/xtensa/xtensa_chip.c
index ac758ed830..ac4a49ccf4 100644
--- a/src/target/xtensa/xtensa_chip.c
+++ b/src/target/xtensa/xtensa_chip.c
@@ -144,17 +144,7 @@ static int xtensa_chip_examine(struct target *target)
 
 static int xtensa_chip_jim_configure(struct target *target, struct 
jim_getopt_info *goi)
 {
-       static bool dap_configured;
-       int ret = adiv5_jim_configure(target, goi);
-       if (ret == JIM_OK) {
-               LOG_DEBUG("xtensa '-dap' target option found");
-               dap_configured = true;
-       }
-       if (!dap_configured) {
-               LOG_DEBUG("xtensa '-dap' target option not yet found, assuming 
JTAG...");
-               target->has_dap = false;
-       }
-       return ret;
+       return adiv5_jim_configure_ext(target, goi, NULL, 
ADI_CONFIGURE_DAP_OPTIONAL);
 }
 
 /** Methods for generic example of Xtensa-based chip-level targets. */

-- 

Reply via email to