From 1e10b96b03da71b1a101c108ca9511c8a613666e Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 15 Apr 2020 18:59:13 +0200 Subject: [PATCH] Allow multiple scan routines. --- src/command.c | 10 +++++++- src/include/target.h | 7 ++++++ src/platforms/libftdi/platform.c | 11 +++++++++ src/platforms/pc-hosted/platform.c | 11 +++++++++ src/platforms/pc-stlinkv2/adiv5_jtagdp.c | 2 +- src/platforms/pc-stlinkv2/platform.c | 30 ++++++++++++++++++++++++ src/platforms/pc-stlinkv2/platform.h | 2 +- src/platforms/pc/cl_utils.c | 4 ++-- 8 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/command.c b/src/command.c index 12a5e4a..4d0d1e5 100644 --- a/src/command.c +++ b/src/command.c @@ -186,7 +186,11 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv) int devs = -1; volatile struct exception e; TRY_CATCH (e, EXCEPTION_ALL) { +#if PC_HOSTED == 1 + devs = platform_jtag_scan(argc > 1 ? irlens : NULL); +#else devs = jtag_scan(argc > 1 ? irlens : NULL); +#endif } switch (e.type) { case EXCEPTION_TIMEOUT: @@ -220,8 +224,12 @@ bool cmd_swdp_scan(target *t, int argc, char **argv) int devs = -1; volatile struct exception e; TRY_CATCH (e, EXCEPTION_ALL) { +#if PC_HOSTED == 1 + devs = platform_adiv5_swdp_scan(); +#else devs = adiv5_swdp_scan(); - } +#endif + } switch (e.type) { case EXCEPTION_TIMEOUT: gdb_outf("Timeout during scan. Is target stuck in WFI?\n"); diff --git a/src/include/target.h b/src/include/target.h index cc6131e..b4b840c 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -34,6 +34,13 @@ typedef struct target_s target; typedef uint32_t target_addr; struct target_controller; +#if defined(PC_HOSTED) +int platform_adiv5_swdp_scan(void); +int platform_jtag_scan(const uint8_t *lrlens); +#endif +int adiv5_swdp_scan(void); +int jtag_scan(const uint8_t *lrlens); + int adiv5_swdp_scan(void); int jtag_scan(const uint8_t *lrlens); diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 8fad4cc..88ed4f2 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -21,6 +21,7 @@ #include "gdb_if.h" #include "version.h" #include "platform.h" +#include "target.h" #include #include @@ -180,6 +181,16 @@ cable_desc_t cable_desc[] = { }, }; +int platform_adiv5_swdp_scan(void) +{ + return adiv5_swdp_scan(); +} + +int platform_jtag_scan(const uint8_t *lrlens) +{ + return jtag_scan(lrlens); +} + void platform_init(int argc, char **argv) { BMP_CL_OPTIONS_t cl_opts = {0}; diff --git a/src/platforms/pc-hosted/platform.c b/src/platforms/pc-hosted/platform.c index 361574d..82f7996 100644 --- a/src/platforms/pc-hosted/platform.c +++ b/src/platforms/pc-hosted/platform.c @@ -23,6 +23,7 @@ #include "version.h" #include "platform.h" #include "remote.h" +#include "target.h" #include #include @@ -33,6 +34,16 @@ #include "cl_utils.h" static BMP_CL_OPTIONS_t cl_opts; /* Portable way to nullify the struct*/ +int platform_adiv5_swdp_scan(void) +{ + return adiv5_swdp_scan(); +} + +int platform_jtag_scan(const uint8_t *lrlens) +{ + return jtag_scan(lrlens); +} + void platform_init(int argc, char **argv) { cl_opts.opt_idstring = "Blackmagic Debug Probe Remote"; diff --git a/src/platforms/pc-stlinkv2/adiv5_jtagdp.c b/src/platforms/pc-stlinkv2/adiv5_jtagdp.c index 4c228fd..30ff697 100644 --- a/src/platforms/pc-stlinkv2/adiv5_jtagdp.c +++ b/src/platforms/pc-stlinkv2/adiv5_jtagdp.c @@ -31,7 +31,7 @@ struct jtag_dev_s jtag_devs[JTAG_MAX_DEVS+1]; int jtag_dev_count; -int jtag_scan(const uint8_t *irlens) +int jtag_scan_stlinkv2(const uint8_t *irlens) { uint32_t idcodes[JTAG_MAX_DEVS+1]; (void) *irlens; diff --git a/src/platforms/pc-stlinkv2/platform.c b/src/platforms/pc-stlinkv2/platform.c index e3f0a1f..f594af1 100644 --- a/src/platforms/pc-stlinkv2/platform.c +++ b/src/platforms/pc-stlinkv2/platform.c @@ -20,6 +20,8 @@ #include "gdb_if.h" #include "version.h" #include "platform.h" +#include "target.h" +#include "target_internal.h" #include #include @@ -39,6 +41,34 @@ const char *platform_target_voltage(void) return stlink_target_voltage(); } +static int adiv5_swdp_scan_stlinkv2(void) +{ + target_list_free(); + ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); + if (stlink_enter_debug_swd()) + return 0; + dp->idcode = stlink_read_coreid(); + dp->dp_read = stlink_dp_read; + dp->error = stlink_dp_error; + dp->low_access = stlink_dp_low_access; + dp->abort = stlink_dp_abort; + + stlink_dp_error(dp); + adiv5_dp_init(dp); + + return target_list?1:0; + return 0; +} +int platform_adiv5_swdp_scan(void) +{ + return adiv5_swdp_scan_stlinkv2(); +} + +int platform_jtag_scan(const uint8_t *lrlens) +{ + return jtag_scan_stlinkv2(lrlens); +} + void platform_init(int argc, char **argv) { stlink_init(argc, argv); diff --git a/src/platforms/pc-stlinkv2/platform.h b/src/platforms/pc-stlinkv2/platform.h index 7db112d..c3f0bba 100644 --- a/src/platforms/pc-stlinkv2/platform.h +++ b/src/platforms/pc-stlinkv2/platform.h @@ -44,5 +44,5 @@ void stlink_check_detach(int state); void platform_buffer_flush(void); int platform_buffer_write(const uint8_t *data, int size); int platform_buffer_read(uint8_t *data, int size); - +int jtag_scan_stlinkv2(const uint8_t *irlens); #endif diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 45f6373..d68dc78 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -275,9 +275,9 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) printf("Running in Test Mode\n"); printf("Target voltage: %s Volt\n", platform_target_voltage()); if (opt->opt_usejtag) { - num_targets = jtag_scan(NULL); + num_targets = platform_jtag_scan(NULL); } else { - num_targets = adiv5_swdp_scan(); + num_targets = platform_adiv5_swdp_scan(); } if (!num_targets) { DEBUG("No target found\n");