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 <vanekt@fbl.cz>
Change-Id: I7260c79332940adfa49d57b45cae39325cdaf432
Reviewed-on: https://review.openocd.org/c/openocd/+/8138
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek 2024-02-11 17:22:38 +01:00 committed by Antonio Borneo
parent 348b79aafe
commit 263dbc1472
4 changed files with 29 additions and 26 deletions

View File

@ -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 * options, JIM_OK if it correctly parsed the topmost option
* and JIM_ERR if an error occurred during parameter evaluation. * and JIM_ERR if an error occurred during parameter evaluation.
* For JIM_CONTINUE, we check our own params. * 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_ext(target, goi, &pc->adiv5_config, ADI_CONFIGURE_DAP_COMPULSORY);
e = adiv5_jim_configure(target, goi);
target->private_config = pc;
if (e != JIM_CONTINUE) if (e != JIM_CONTINUE)
return e; return e;

View File

@ -2424,23 +2424,26 @@ err_no_param:
return JIM_ERR; 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; int e;
pc = (struct adiv5_private_config *)target->private_config;
if (!pc) { if (!pc) {
pc = calloc(1, sizeof(struct adiv5_private_config)); pc = (struct adiv5_private_config *)target->private_config;
if (!pc) { if (!pc) {
LOG_ERROR("Out of memory"); pc = calloc(1, sizeof(struct adiv5_private_config));
return JIM_ERR; 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); e = adiv5_jim_spot_configure(goi, &pc->dap, &pc->ap_num, NULL);
if (e != JIM_OK) 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->tap = pc->dap->tap;
target->dap_configured = true; target->dap_configured = true;
target->has_dap = true;
} }
return JIM_OK; 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) int adiv5_verify_config(struct adiv5_private_config *pc)
{ {
if (!pc) if (!pc)

View File

@ -788,6 +788,15 @@ struct adiv5_private_config {
}; };
extern int adiv5_verify_config(struct adiv5_private_config *pc); 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); extern int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi);
struct adiv5_mem_ap_spot { struct adiv5_mem_ap_spot {

View File

@ -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 int xtensa_chip_jim_configure(struct target *target, struct jim_getopt_info *goi)
{ {
static bool dap_configured; return adiv5_jim_configure_ext(target, goi, NULL, ADI_CONFIGURE_DAP_OPTIONAL);
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;
} }
/** Methods for generic example of Xtensa-based chip-level targets. */ /** Methods for generic example of Xtensa-based chip-level targets. */