From 165560edd8d93f89c342931e64442b7f7d03d48a Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 10 Feb 2021 21:43:44 +0100 Subject: [PATCH] cl_utils: target selection '-n' argument needs optarg. foreach now returns the number of targets. --- src/include/target.h | 2 +- src/platforms/pc/cl_utils.c | 10 +++++----- src/target/target.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/include/target.h b/src/include/target.h index 7c71340..b7808d7 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -41,7 +41,7 @@ int platform_jtag_scan(const uint8_t *lrlens); int adiv5_swdp_scan(void); int jtag_scan(const uint8_t *lrlens); -bool target_foreach(void (*cb)(int i, target *t, void *context), void *context); +int target_foreach(void (*cb)(int i, target *t, void *context), void *context); void target_list_free(void); /* Attach/detach functions */ diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 686828f..3d4a3fd 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -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 * (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify @@ -168,7 +168,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:CnltVtTa:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:tVtTa:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -333,11 +333,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) DEBUG_WARN("No target found\n"); return res; } else { - target_foreach(display_target, NULL); + num_targets = target_foreach(display_target, &num_targets); } if (opt->opt_target_dev > num_targets) { - DEBUG_WARN("Given target nummer %d not available\n", - opt->opt_target_dev); + DEBUG_WARN("Given target nummer %d not available max %d\n", + opt->opt_target_dev, num_targets); return res; } target *t = target_attach_n(opt->opt_target_dev, NULL); diff --git a/src/target/target.c b/src/target/target.c index 5a5ec38..3004c97 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -69,13 +69,13 @@ target *target_new(void) return t; } -bool target_foreach(void (*cb)(int, target *t, void *context), void *context) +int target_foreach(void (*cb)(int, target *t, void *context), void *context) { int i = 1; target *t = target_list; for (; t; t = t->next, i++) cb(i, t, context); - return target_list != NULL; + return i; } void target_mem_map_free(target *t)