swd_scan: Add '-m' as targetid argument to swd_scan to prepare multi-drop.

In a real multi-drop setup, the device to use must be specified.
This commit is contained in:
Uwe Bonnes 2021-02-10 10:18:31 +01:00 committed by UweBonnes
parent 8e2f6937d5
commit c776e7a9a6
6 changed files with 24 additions and 14 deletions

View File

@ -219,8 +219,9 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv)
bool cmd_swdp_scan(target *t, int argc, char **argv)
{
(void)t;
(void)argc;
(void)argv;
volatile uint32_t targetid = 0;
if (argc > 1)
targetid = strtol(argv[1], NULL, 0);
if (platform_target_voltage())
gdb_outf("Target voltage: %s\n", platform_target_voltage());
@ -231,9 +232,9 @@ bool cmd_swdp_scan(target *t, int argc, char **argv)
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
devs = platform_adiv5_swdp_scan();
devs = platform_adiv5_swdp_scan(targetid);
#else
devs = adiv5_swdp_scan();
devs = adiv5_swdp_scan(targetid);
#endif
}
switch (e.type) {

View File

@ -35,10 +35,10 @@ typedef uint32_t target_addr;
struct target_controller;
#if PC_HOSTED == 1
int platform_adiv5_swdp_scan(void);
int platform_adiv5_swdp_scan(uint32_t targetid);
int platform_jtag_scan(const uint8_t *lrlens);
#endif
int adiv5_swdp_scan(void);
int adiv5_swdp_scan(uint32_t targetid);
int jtag_scan(const uint8_t *lrlens);
int target_foreach(void (*cb)(int i, target *t, void *context), void *context);

View File

@ -1,7 +1,7 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2020 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
* Copyright (C) 2020- 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -119,14 +119,16 @@ void platform_init(int argc, char **argv)
exit(ret);
}
int platform_adiv5_swdp_scan(void)
int platform_adiv5_swdp_scan(uint32_t targetid)
{
info.is_jtag = false;
platform_max_frequency_set(cl_opts.opt_max_swj_frequency);
if (targetid && (info.bmp_type != BMP_TYPE_BMP))
DEBUG_WARN("Ignoring TARGETID for now!\n");
switch (info.bmp_type) {
case BMP_TYPE_BMP:
case BMP_TYPE_LIBFTDI:
return adiv5_swdp_scan();
return adiv5_swdp_scan(targetid);
break;
case BMP_TYPE_STLINKV2:
{

View File

@ -165,6 +165,7 @@ static void cl_help(char **argv)
DEBUG_WARN("\t-p\t\t: Supplies power to the target (where applicable)\n");
DEBUG_WARN("\t-R\t\t: Reset device\n");
DEBUG_WARN("\t-H\t\t: Do not use high level commands (BMP-Remote)\n");
DEBUG_WARN("\t-m <target>\t: Use (target)id for SWD multi-drop.\n");
DEBUG_WARN("\t-M <string>\t: Run target specific monitor commands. Quote multi\n");
DEBUG_WARN("\t\t\t word strings. Run \"-M help\" for help.\n");
DEBUG_WARN("Flash operation modifiers options:\n");
@ -183,7 +184,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
opt->opt_flash_size = 16 * 1024 *1024;
opt->opt_flash_start = 0xffffffff;
opt->opt_max_swj_frequency = 4000000;
while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:M:tVtTa:S:jpP:rR")) != -1) {
while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:tVtTa:S:jpP:rR")) != -1) {
switch(c) {
case 'c':
if (optarg)
@ -270,6 +271,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
if (optarg)
opt->opt_target_dev = strtol(optarg, NULL, 0);
break;
case 'm':
if (optarg)
opt->opt_targetid = strtol(optarg, NULL, 0);
break;
case 'M':
opt->opt_mode = BMP_MODE_MONITOR;
if (optarg)
@ -347,7 +352,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (opt->opt_usejtag) {
num_targets = platform_jtag_scan(NULL);
} else {
num_targets = platform_adiv5_swdp_scan();
num_targets = platform_adiv5_swdp_scan(opt->opt_targetid);
}
if (!num_targets) {
DEBUG_WARN("No target found\n");

View File

@ -1,7 +1,7 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2019 - 2020 Uwe Bonnes
* Copyright (C) 2019 - 2021 Uwe Bonnes
* Written by Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
*
* This program is free software: you can redistribute it and/or modify
@ -49,6 +49,7 @@ typedef struct BMP_CL_OPTIONS_s {
char *opt_flash_file;
char *opt_device;
char *opt_serial;
uint32_t opt_targetid;
char *opt_ident_string;
int opt_position;
char *opt_cable;

View File

@ -3,6 +3,7 @@
*
* Copyright (C) 2011 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2020- 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,10 +34,10 @@
#define SWDP_ACK_WAIT 0x02
#define SWDP_ACK_FAULT 0x04
int adiv5_swdp_scan(void)
int adiv5_swdp_scan(uint32_t targetid)
{
uint32_t ack;
(void) targetid;
target_list_free();
#if PC_HOSTED == 1
if (platform_swdptap_init()) {