Allow multiple scan routines.

This commit is contained in:
Uwe Bonnes 2020-04-15 18:59:13 +02:00
parent b0cf7d24bd
commit 1e10b96b03
8 changed files with 72 additions and 5 deletions

View File

@ -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");

View File

@ -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);

View File

@ -21,6 +21,7 @@
#include "gdb_if.h"
#include "version.h"
#include "platform.h"
#include "target.h"
#include <assert.h>
#include <unistd.h>
@ -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};

View File

@ -23,6 +23,7 @@
#include "version.h"
#include "platform.h"
#include "remote.h"
#include "target.h"
#include <assert.h>
#include <sys/time.h>
@ -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";

View File

@ -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;

View File

@ -20,6 +20,8 @@
#include "gdb_if.h"
#include "version.h"
#include "platform.h"
#include "target.h"
#include "target_internal.h"
#include <assert.h>
#include <unistd.h>
@ -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);

View File

@ -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

View File

@ -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");