From 076f1086fa9c0dfa043300fb1776bc10e8eaa77f Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Sat, 22 Oct 2011 18:05:24 +0000 Subject: [PATCH] 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. --- Makefile | 25 +++++------------------ flash/main.c | 5 ----- gdbserver/gdb-server.c | 6 ------ src/stlink-usb.c | 45 ++++++------------------------------------ src/stlink-usb.h | 6 ------ src/test_sg.c | 4 ---- 6 files changed, 11 insertions(+), 80 deletions(-) diff --git a/Makefile b/Makefile index c5bb1d9..bbd76a8 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,13 @@ -# make ... for both libusb and libsg -# -# make CONFIG_USE_LIBSG=0 ... -# for just libusb -# +# make ... for both stlink v1 and stlink v2 support +## 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) -TEST_PROGRAMS=test_usb +TEST_PROGRAMS=test_usb #test_sg 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+=-DCONFIG_USE_LIBUSB=1 CFLAGS+=-DDEBUG=1 CFLAGS+=-std=gnu99 CFLAGS+=-Wall -Wextra @@ -63,7 +48,7 @@ distclean: clean $(MAKE) -C gdbserver clean flash: - $(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)" + $(MAKE) -C flash gdbserver: $(MAKE) -C gdbserver diff --git a/flash/main.c b/flash/main.c index e474174..a443f95 100644 --- a/flash/main.c +++ b/flash/main.c @@ -86,14 +86,9 @@ int main(int ac, char** av) if (o.devname != NULL) /* stlinkv1 */ { -#if CONFIG_USE_LIBSG static const int scsi_verbose = 2; sl = stlink_quirk_open(o.devname, scsi_verbose); if (sl == NULL) goto on_error; -#else - printf("not compiled for use with STLink/V1"); - goto on_error; -#endif } else /* stlinkv2 */ { diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index e7efbf1..f1da63e 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -197,7 +197,6 @@ int main(int argc, char** argv) { if(sl == NULL) return 1; break; case 1: -#if (CONFIG_USE_LIBSG == 1) if (strlen(state.devicename) == 0) { const int DevNumMax = 99; int ExistDevCount = 0; @@ -235,11 +234,6 @@ int main(int argc, char** argv) { sl = stlink_quirk_open(state.devicename, state.logging_level); } 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) { diff --git a/src/stlink-usb.c b/src/stlink-usb.c index ff9ef71..57a4a2f 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -604,47 +604,14 @@ stlink_t* stlink_open_usb(const int verbose) { goto on_error; } - count = libusb_get_device_list(slu->libusb_ctx, &devs); - if (count < 0) { - printf("libusb_get_device_list\n"); - goto on_libusb_error; - } - - 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; + slu->usb_handle = libusb_open_device_with_vid_pid(slu->libusb_ctx, USB_ST_VID, USB_STLINK_32L_PID); + if (slu->usb_handle == NULL) { + // TODO - free usb context too... + free(slu); + fprintf(stderr, "Couldn't find any ST-Link/V2 devices"); + return NULL; } - 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) { int r; diff --git a/src/stlink-usb.h b/src/stlink-usb.h index c632a8c..2f3b8cc 100644 --- a/src/stlink-usb.h +++ b/src/stlink-usb.h @@ -18,7 +18,6 @@ extern "C" { #define STLINK_SG_SIZE 31 #define STLINK_CMD_SIZE 16 -#if defined(CONFIG_USE_LIBUSB) struct stlink_libusb { libusb_context* libusb_ctx; libusb_device_handle* usb_handle; @@ -30,11 +29,6 @@ extern "C" { unsigned int sg_transfer_idx; unsigned int cmd_len; }; -#else -#error "it's all bad!" - struct stlink_libusb {}; -#endif - stlink_t* stlink_open_usb(const int verbose); diff --git a/src/test_sg.c b/src/test_sg.c index 34fbe54..9efe6d8 100644 --- a/src/test_sg.c +++ b/src/test_sg.c @@ -6,10 +6,6 @@ #include #include -#if CONFIG_USE_LIBSG -#include -#include -#endif #include "stlink-common.h" int main(int argc, char *argv[]) { -- 2.30.2