kopia lustrzana https://github.com/stlink-org/stlink
Remove all #ifdefs for sg-utils.
We're starting on integration from github.com/afaerber So, instead of scanning all the usb devices, just open what we want.pull/29/head
rodzic
c37975c157
commit
076f1086fa
25
Makefile
25
Makefile
|
@ -1,28 +1,13 @@
|
||||||
# make ... for both libusb and libsg
|
# make ... for both stlink v1 and stlink v2 support
|
||||||
#
|
##
|
||||||
# make CONFIG_USE_LIBSG=0 ...
|
|
||||||
# for just libusb
|
|
||||||
#
|
|
||||||
VPATH=src
|
VPATH=src
|
||||||
|
|
||||||
SOURCES_LIB=stlink-common.c stlink-usb.c
|
SOURCES_LIB=stlink-common.c stlink-usb.c #stlink-sg.c
|
||||||
OBJS_LIB=$(SOURCES_LIB:.c=.o)
|
OBJS_LIB=$(SOURCES_LIB:.c=.o)
|
||||||
TEST_PROGRAMS=test_usb
|
TEST_PROGRAMS=test_usb #test_sg
|
||||||
LDFLAGS=-lusb-1.0 -L. -lstlink
|
LDFLAGS=-lusb-1.0 -L. -lstlink
|
||||||
|
|
||||||
ifeq ($(CONFIG_USE_LIBSG),)
|
|
||||||
CONFIG_USE_LIBSG=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_USE_LIBSG),0)
|
|
||||||
SOURCES_LIB+=stlink-sg.c
|
|
||||||
CFLAGS+=-DCONFIG_USE_LIBSG=1
|
|
||||||
LDFLAGS+=-lsgutils2
|
|
||||||
TEST_PROGRAMS+=test_sg
|
|
||||||
endif
|
|
||||||
|
|
||||||
CFLAGS+=-g
|
CFLAGS+=-g
|
||||||
CFLAGS+=-DCONFIG_USE_LIBUSB=1
|
|
||||||
CFLAGS+=-DDEBUG=1
|
CFLAGS+=-DDEBUG=1
|
||||||
CFLAGS+=-std=gnu99
|
CFLAGS+=-std=gnu99
|
||||||
CFLAGS+=-Wall -Wextra
|
CFLAGS+=-Wall -Wextra
|
||||||
|
@ -63,7 +48,7 @@ distclean: clean
|
||||||
$(MAKE) -C gdbserver clean
|
$(MAKE) -C gdbserver clean
|
||||||
|
|
||||||
flash:
|
flash:
|
||||||
$(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)"
|
$(MAKE) -C flash
|
||||||
|
|
||||||
gdbserver:
|
gdbserver:
|
||||||
$(MAKE) -C gdbserver
|
$(MAKE) -C gdbserver
|
||||||
|
|
|
@ -86,14 +86,9 @@ int main(int ac, char** av)
|
||||||
|
|
||||||
if (o.devname != NULL) /* stlinkv1 */
|
if (o.devname != NULL) /* stlinkv1 */
|
||||||
{
|
{
|
||||||
#if CONFIG_USE_LIBSG
|
|
||||||
static const int scsi_verbose = 2;
|
static const int scsi_verbose = 2;
|
||||||
sl = stlink_quirk_open(o.devname, scsi_verbose);
|
sl = stlink_quirk_open(o.devname, scsi_verbose);
|
||||||
if (sl == NULL) goto on_error;
|
if (sl == NULL) goto on_error;
|
||||||
#else
|
|
||||||
printf("not compiled for use with STLink/V1");
|
|
||||||
goto on_error;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else /* stlinkv2 */
|
else /* stlinkv2 */
|
||||||
{
|
{
|
||||||
|
|
|
@ -197,7 +197,6 @@ int main(int argc, char** argv) {
|
||||||
if(sl == NULL) return 1;
|
if(sl == NULL) return 1;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#if (CONFIG_USE_LIBSG == 1)
|
|
||||||
if (strlen(state.devicename) == 0) {
|
if (strlen(state.devicename) == 0) {
|
||||||
const int DevNumMax = 99;
|
const int DevNumMax = 99;
|
||||||
int ExistDevCount = 0;
|
int ExistDevCount = 0;
|
||||||
|
@ -235,11 +234,6 @@ int main(int argc, char** argv) {
|
||||||
sl = stlink_quirk_open(state.devicename, state.logging_level);
|
sl = stlink_quirk_open(state.devicename, state.logging_level);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#else
|
|
||||||
fprintf(stderr, "Support for stlink v1 disabled at build time...\n");
|
|
||||||
fprintf(stderr, "Perhaps you're on OSX, and we haven't finished removing the libsg deps?\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
|
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
|
||||||
|
|
|
@ -604,47 +604,14 @@ stlink_t* stlink_open_usb(const int verbose) {
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = libusb_get_device_list(slu->libusb_ctx, &devs);
|
slu->usb_handle = libusb_open_device_with_vid_pid(slu->libusb_ctx, USB_ST_VID, USB_STLINK_32L_PID);
|
||||||
if (count < 0) {
|
if (slu->usb_handle == NULL) {
|
||||||
printf("libusb_get_device_list\n");
|
// TODO - free usb context too...
|
||||||
goto on_libusb_error;
|
free(slu);
|
||||||
}
|
fprintf(stderr, "Couldn't find any ST-Link/V2 devices");
|
||||||
|
return NULL;
|
||||||
for (i = 0; i < count; ++i) {
|
|
||||||
dev = devs[i];
|
|
||||||
slu->protocoll = is_stlink_device(dev, 0);
|
|
||||||
if (slu->protocoll > 0) break;
|
|
||||||
}
|
|
||||||
if (i == count) goto on_libusb_error;
|
|
||||||
|
|
||||||
if (libusb_open(dev, &(slu->usb_handle))) {
|
|
||||||
printf("libusb_open()\n");
|
|
||||||
goto on_libusb_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iSerial) {
|
|
||||||
unsigned char serial[256];
|
|
||||||
struct libusb_device_descriptor desc;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
r = libusb_get_device_descriptor(dev, &desc);
|
|
||||||
if (r<0) {
|
|
||||||
printf("Can't get descriptor to match Iserial\n");
|
|
||||||
goto on_libusb_error;
|
|
||||||
}
|
|
||||||
r = libusb_get_string_descriptor_ascii
|
|
||||||
(slu->usb_handle, desc.iSerialNumber, serial, 256);
|
|
||||||
if (r<0) {
|
|
||||||
printf("Can't get Serialnumber to match Iserial\n");
|
|
||||||
goto on_libusb_error;
|
|
||||||
}
|
|
||||||
if (strcmp((char*)serial, iSerial)) {
|
|
||||||
printf("Mismatch in serial numbers, dev %s vs given %s\n",
|
|
||||||
serial, iSerial);
|
|
||||||
goto on_libusb_error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (libusb_kernel_driver_active(slu->usb_handle, 0) == 1) {
|
if (libusb_kernel_driver_active(slu->usb_handle, 0) == 1) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ extern "C" {
|
||||||
#define STLINK_SG_SIZE 31
|
#define STLINK_SG_SIZE 31
|
||||||
#define STLINK_CMD_SIZE 16
|
#define STLINK_CMD_SIZE 16
|
||||||
|
|
||||||
#if defined(CONFIG_USE_LIBUSB)
|
|
||||||
struct stlink_libusb {
|
struct stlink_libusb {
|
||||||
libusb_context* libusb_ctx;
|
libusb_context* libusb_ctx;
|
||||||
libusb_device_handle* usb_handle;
|
libusb_device_handle* usb_handle;
|
||||||
|
@ -30,11 +29,6 @@ extern "C" {
|
||||||
unsigned int sg_transfer_idx;
|
unsigned int sg_transfer_idx;
|
||||||
unsigned int cmd_len;
|
unsigned int cmd_len;
|
||||||
};
|
};
|
||||||
#else
|
|
||||||
#error "it's all bad!"
|
|
||||||
struct stlink_libusb {};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
stlink_t* stlink_open_usb(const int verbose);
|
stlink_t* stlink_open_usb(const int verbose);
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,6 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if CONFIG_USE_LIBSG
|
|
||||||
#include <scsi/sg_lib.h>
|
|
||||||
#include <scsi/sg_pt.h>
|
|
||||||
#endif
|
|
||||||
#include "stlink-common.h"
|
#include "stlink-common.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
Ładowanie…
Reference in New Issue