]> git.gag.com Git - fw/stlink/commitdiff
Remove all #ifdefs for sg-utils.
authorKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 18:05:24 +0000 (18:05 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 18:05:24 +0000 (18:05 +0000)
We're starting on integration from github.com/afaerber
So, instead of scanning all the usb devices, just open what we want.

Makefile
flash/main.c
gdbserver/gdb-server.c
src/stlink-usb.c
src/stlink-usb.h
src/test_sg.c

index c5bb1d9a1f082db033aea7d5da793578475537c2..bbd76a807fb6f9541d529d182a6f83f4caec6fa9 100644 (file)
--- 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
index e474174377b1ac154d17cfaf96e46823f087e551..a443f95f6bb58b59460e3231a5a650d637763d6c 100644 (file)
@@ -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 */
   {
index e7efbf15bca8aef35ddce8d13aeb9f43b059e5a3..f1da63e45c4462ed21f82177c432b7361320a88f 100644 (file)
@@ -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) {
index ff9ef71de7a4e6afc0b632342b473cc97826ff0b..57a4a2fddff510c8b653893cbf8f58fe3161c473 100644 (file)
@@ -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;
         
index c632a8c4163da3257a61014cf1b614b30e7cc884..2f3b8cc3ed7f84c17994debaaa68da442aaf86bd 100644 (file)
@@ -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);
 
index 34fbe540caa000c2665a87582b7578487b2f1816..9efe6d80db94ae1ddfed9162a4b441dcf2d7911f 100644 (file)
@@ -6,10 +6,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#if CONFIG_USE_LIBSG
-#include <scsi/sg_lib.h>
-#include <scsi/sg_pt.h>
-#endif
 #include "stlink-common.h"
 
 int main(int argc, char *argv[]) {