hosted: Add -l argument to list only available debuggers and exit.

This commit is contained in:
Uwe Bonnes 2020-05-12 18:40:09 +02:00
parent dc3fd2eb06
commit 425002a38f
3 changed files with 27 additions and 10 deletions

View File

@ -100,6 +100,7 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info)
char manufacturer[128];
char product[128];
bmp_type_t type = BMP_TYPE_NONE;
bool access_problems = false;
rescan:
found_debuggers = 0;
for (int i = 0; devs[i]; i++) {
@ -114,8 +115,11 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info)
libusb_device_handle *handle;
res = libusb_open(dev, &handle);
if (res != LIBUSB_SUCCESS) {
DEBUG_INFO("INFO: Open USB %04x:%04x failed\n",
desc.idVendor, desc.idProduct);
if (!access_problems) {
DEBUG_INFO("INFO: Open USB %04x:%04x failed\n",
desc.idVendor, desc.idProduct);
access_problems = true;
}
continue;
}
res = libusb_get_string_descriptor_ascii(
@ -198,15 +202,23 @@ static int find_debuggers( BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info)
break;
}
}
if (found_debuggers > 1) {
if ((found_debuggers > 1) ||
((found_debuggers == 1) && (cl_opts->opt_list_only))) {
if (!report) {
DEBUG_WARN("%d debuggers found! Select with -P <num>, -s <string> "
"and/or -S <string>\n",
found_debuggers);
if (found_debuggers > 1)
DEBUG_WARN("%d debuggers found!\nSelect with -P <pos>, "
"-s <(partial)serial no.> "
"and/or -S <(partial)description>\n",
found_debuggers);
report = true;
goto rescan;
} else {
found_debuggers = 0;
}
}
if (!found_debuggers && access_problems)
DEBUG_WARN(
"No debugger found. Please check access rights to USB devices!\n");
libusb_free_device_list(devs, 1);
return (found_debuggers == 1) ? 0 : -1;
}

View File

@ -124,10 +124,10 @@ static void cl_help(char **argv, BMP_CL_OPTIONS_t *opt)
DEBUG_WARN("\t\t\t 1 = INFO, 2 = GDB, 4 = TARGET, 8 = PROBE, 16 = WIRE\n");
DEBUG_WARN("Probe selection arguments:\n");
DEBUG_WARN("\t-d \"path\"\t: Use serial device at \"path\"\n");
DEBUG_WARN("\t-P <num>\t: Use debugger found at position <num>\n");
DEBUG_WARN("\t-P <pos>\t: Use debugger found at position <pos>\n");
DEBUG_WARN("\t-n <num>\t: Use target device found at position <num>\n");
DEBUG_WARN("\t-s \"string\"\t: Use dongle with (partial) "
"serial number \"string\"\n");
DEBUG_WARN("\t-s \"serial\"\t: Use dongle with (partial) "
"serial number \"serial\"\n");
DEBUG_WARN("\t-c \"string\"\t: Use ftdi dongle with type \"string\"\n");
DEBUG_WARN("Run mode related options:\n");
DEBUG_WARN("\tDefault mode is to start the debug server at :2000\n");
@ -155,7 +155,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
opt->opt_target_dev = 1;
opt->opt_flash_start = 0x08000000;
opt->opt_flash_size = 16 * 1024 *1024;
while((c = getopt(argc, argv, "Ehv:d:s:I:c:Cn:tVta:S:jpP:rR")) != -1) {
while((c = getopt(argc, argv, "Ehv:d:s:I:c:CnltVta:S:jpP:rR")) != -1) {
switch(c) {
case 'c':
if (optarg)
@ -171,6 +171,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
case 'j':
opt->opt_usejtag = true;
break;
case 'l':
opt->opt_list_only = true;
cl_debuglevel |= BMP_DEBUG_STDOUT;
break;
case 'C':
opt->opt_connect_under_reset = true;
break;

View File

@ -40,6 +40,7 @@ typedef struct BMP_CL_OPTIONS_s {
enum bmp_cl_mode opt_mode;
bool opt_usejtag;
bool opt_tpwr;
bool opt_list_only;
bool opt_connect_under_reset;
char *opt_flash_file;
char *opt_device;