bmp_serial: Autodetect more BMP string variants.
This commit is contained in:
parent
891633322a
commit
c0437e7b25
|
@ -8,7 +8,7 @@ CFLAGS +=-I ./target -I./platforms/pc
|
||||||
# be useful to minimize external dependencies, and make building on
|
# be useful to minimize external dependencies, and make building on
|
||||||
# windows systems easier.
|
# windows systems easier.
|
||||||
HOSTED_BMP_ONLY ?= 0
|
HOSTED_BMP_ONLY ?= 0
|
||||||
CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY)
|
CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY) -Wno-format-truncation
|
||||||
|
|
||||||
ifneq (, $(findstring linux, $(SYS)))
|
ifneq (, $(findstring linux, $(SYS)))
|
||||||
SRC += serial_unix.c
|
SRC += serial_unix.c
|
||||||
|
|
|
@ -27,8 +27,10 @@
|
||||||
|
|
||||||
void bmp_ident(bmp_info_t *info)
|
void bmp_ident(bmp_info_t *info)
|
||||||
{
|
{
|
||||||
(void) info;
|
if (!info)
|
||||||
|
return;
|
||||||
DEBUG_INFO("BMP hosted (BMP Only) %s\n", FIRMWARE_VERSION);
|
DEBUG_INFO("BMP hosted (BMP Only) %s\n", FIRMWARE_VERSION);
|
||||||
|
DEBUG_INFO("Using:\n %s %s %s\n", info->manufacturer, info->version, info->serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void libusb_exit_function(bmp_info_t *info) {(void)info;};
|
void libusb_exit_function(bmp_info_t *info) {(void)info;};
|
||||||
|
@ -152,6 +154,10 @@ print_probes_info:
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
/* Old ID: Black_Sphere_Technologies_Black_Magic_Probe_BFE4D6EC-if00
|
||||||
|
* Recent: Black_Sphere_Technologies_Black_Magic_Probe_v1.7.1-212-g212292ab_7BAE7AB8-if00
|
||||||
|
* usb-Black_Sphere_Technologies_Black_Magic_Probe__SWLINK__v1.7.1-155-gf55ad67b-dirty_DECB8811-if00
|
||||||
|
*/
|
||||||
#define BMP_IDSTRING "usb-Black_Sphere_Technologies_Black_Magic_Probe"
|
#define BMP_IDSTRING "usb-Black_Sphere_Technologies_Black_Magic_Probe"
|
||||||
#define DEVICE_BY_ID "/dev/serial/by-id/"
|
#define DEVICE_BY_ID "/dev/serial/by-id/"
|
||||||
|
|
||||||
|
@ -170,41 +176,45 @@ static int scan_linux_id(char *name, char *type, char *version, char *serial)
|
||||||
DEBUG_WARN("Unexpected end\n");
|
DEBUG_WARN("Unexpected end\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char *p = strchr(name, '_');
|
char *p = name;
|
||||||
if (!p) {
|
char *delims[4] = {0,0,0,0};
|
||||||
DEBUG_WARN("type not found\n");
|
int underscores = 0;
|
||||||
return -1;
|
while (*p) {
|
||||||
|
if (*p == '_') {
|
||||||
|
while (p[1] == '_')
|
||||||
|
p++; /* remove multiple underscores */
|
||||||
|
if (underscores > 2)
|
||||||
|
return -1;
|
||||||
|
delims[underscores] = p;
|
||||||
|
underscores ++;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
}
|
}
|
||||||
strncpy(type, name, p - name);
|
if (underscores == 0) { /* Old BMP native */
|
||||||
type[p - name] = 0;
|
int res;
|
||||||
name = p;
|
res = sscanf(name, "%8s-if00", serial);
|
||||||
while (*name != 'v')
|
if (res != 1)
|
||||||
name++;
|
return -1;
|
||||||
if (!*name) {
|
strcpy(type, "Native");
|
||||||
DEBUG_WARN("Unexpected end after type\n");
|
strcpy(version, "Unknown");
|
||||||
return -1;
|
} else if (underscores == 2) {
|
||||||
|
strncpy(type, name, delims[0] - name - 1);
|
||||||
|
strncpy(version, delims[0] + 1, delims[1] - delims[0] - 1);
|
||||||
|
int res = sscanf(delims[1] + 1, "%8s-if00", serial);
|
||||||
|
if (!res)
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
int res = sscanf(delims[0] + 1, "%8s-if00", serial);
|
||||||
|
if (!res)
|
||||||
|
return -1;
|
||||||
|
if (name[0] == 'v') {
|
||||||
|
strcpy(type, "Unknown");
|
||||||
|
strncpy(version, name, delims[0] - name - 1);
|
||||||
|
} else {
|
||||||
|
strncpy(type, name, delims[0] - name);
|
||||||
|
strcpy(type, "Unknown");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = strchr(name, '_');
|
|
||||||
if (!p) {
|
|
||||||
DEBUG_WARN("version not found\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(version, name, p - name);
|
|
||||||
version[p - name] = 0;
|
|
||||||
name = p;
|
|
||||||
while (*name == '_')
|
|
||||||
name++;
|
|
||||||
if (!*name) {
|
|
||||||
DEBUG_WARN("Unexpected end after version\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
p = strchr(name, '-');
|
|
||||||
if (!p) {
|
|
||||||
DEBUG_WARN("Serial not found\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(serial, name, p - name);
|
|
||||||
serial[p - name] = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,8 +242,9 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info)
|
||||||
(cl_opts->opt_position && cl_opts->opt_position == i)) {
|
(cl_opts->opt_position && cl_opts->opt_position == i)) {
|
||||||
/* With serial number given and partial match, we are done!*/
|
/* With serial number given and partial match, we are done!*/
|
||||||
strncpy(info->serial, serial, sizeof(info->serial));
|
strncpy(info->serial, serial, sizeof(info->serial));
|
||||||
strncpy(info->manufacturer, "BMP", sizeof(info->manufacturer));
|
int res = snprintf(info->manufacturer, sizeof(info->manufacturer), "Black Magic Probe (%s)", type);
|
||||||
strncpy(info->product, type, sizeof(info->product));
|
if (res)
|
||||||
|
DEBUG_WARN("Overflow\n");
|
||||||
strncpy(info->version, version, sizeof(info->version));
|
strncpy(info->version, version, sizeof(info->version));
|
||||||
found_bmps = 1;
|
found_bmps = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -263,8 +274,7 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info)
|
||||||
strncpy(info->serial, serial, sizeof(info->serial));
|
strncpy(info->serial, serial, sizeof(info->serial));
|
||||||
found_bmps = 1;
|
found_bmps = 1;
|
||||||
strncpy(info->serial, serial, sizeof(info->serial));
|
strncpy(info->serial, serial, sizeof(info->serial));
|
||||||
strncpy(info->manufacturer, "BMP", sizeof(info->manufacturer));
|
snprintf(info->manufacturer, sizeof(info->manufacturer), "Black Magic Probe (%s)", type);
|
||||||
strncpy(info->product, type, sizeof(info->product));
|
|
||||||
strncpy(info->version, version, sizeof(info->version));
|
strncpy(info->version, version, sizeof(info->version));
|
||||||
break;
|
break;
|
||||||
} else if (found_bmps > 0) {
|
} else if (found_bmps > 0) {
|
||||||
|
|
Loading…
Reference in New Issue