From c776e7a9a6309fb8172dd62c169d7e217ce94088 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 10 Feb 2021 10:18:31 +0100 Subject: [PATCH] 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. --- src/command.c | 9 +++++---- src/include/target.h | 4 ++-- src/platforms/hosted/platform.c | 8 +++++--- src/platforms/pc/cl_utils.c | 9 +++++++-- src/platforms/pc/cl_utils.h | 3 ++- src/target/adiv5_swdp.c | 5 +++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/command.c b/src/command.c index c84237b..859496a 100644 --- a/src/command.c +++ b/src/command.c @@ -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) { diff --git a/src/include/target.h b/src/include/target.h index b7808d7..5cf04ac 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -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); diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 7b95c8d..fc4d101 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -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: { diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index a675657..92cf29a 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -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 \t: Use (target)id for SWD multi-drop.\n"); DEBUG_WARN("\t-M \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"); diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index 4e6c851..e002cda 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -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; diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index 0678064..68c3602 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -3,6 +3,7 @@ * * Copyright (C) 2011 Black Sphere Technologies Ltd. * Written by Gareth McMullin + * 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()) {