Remove device names, we now just find it via USB ids.
authorKarl Palsson <karlp@tweak.net.au>
Thu, 3 Nov 2011 23:40:27 +0000 (23:40 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Thu, 3 Nov 2011 23:40:27 +0000 (23:40 +0000)
In the future, we might actually want device names back again, if you have multiple stlink's
connected.  But that would be a new device name, not scanning for /dev/sgX looking for scsi
devices.

gdbserver/gdb-server.c
src/stlink-sg.c
src/stlink-sg.h
src/test_sg.c

index 65297bc0c3dcf56b1c1c40d27bf7ec1e897a662d..df3657a9bc1df76c49964d631fda7f78ebee9bd4 100644 (file)
@@ -197,42 +197,8 @@ int main(int argc, char** argv) {
                if(sl == NULL) return 1;
                break;
        case 1:
-               if (strlen(state.devicename) == 0) {
-                       const int DevNumMax = 99;
-                       int ExistDevCount = 0;
-
-                       for (int DevNum = 0; DevNum <= DevNumMax; DevNum++) {
-                               if (DevNum < 10) {
-                                       char DevName[] = "/dev/sgX";
-                                       const int X_index = 7;
-                                       DevName[X_index] = DevNum + '0';
-                                       if (!access(DevName, F_OK)) {
-                                               sl = stlink_v1_open(DevName, 0);
-                                               ExistDevCount++;
-                                       }
-                               } else if (DevNum < 100) {
-                                       char DevName[] = "/dev/sgXY";
-                                       const int X_index = 7;
-                                       const int Y_index = 8;
-                                       DevName[X_index] = DevNum / 10 + '0';
-                                       DevName[Y_index] = DevNum % 10 + '0';
-                                       if (!access(DevName, F_OK)) {
-                                               sl = stlink_v1_open(DevName, 0);
-                                               ExistDevCount++;
-                                       }
-                               }
-                               if (sl != NULL) break;
-                       }
-
-                       if (sl == NULL) {
-                               fprintf(stdout, "\nNumber of /dev/sgX devices found: %i \n",
-                                       ExistDevCount);
-                               fprintf(stderr, "ST-LINK not found\n");
-                               return 1;
-                       }
-               } else {
-                       sl = stlink_v1_open(state.devicename, state.logging_level);
-               }
+               sl = stlink_v1_open(NULL, state.logging_level);
+               if(sl == NULL) return 1;
                break;
     }
 
index 2253212bd819e7238e93fea4293a49f6b193dd65..64f182022da3cfdece24bc3951537b557d83436d 100644 (file)
@@ -967,8 +967,7 @@ stlink_backend_t _stlink_sg_backend = {
     _stlink_sg_force_debug
 };
 
-static stlink_t* stlink_open(const char *dev_name, const int verbose) {
-    DLOG("*** stlink_open [%s] ***\n", dev_name);
+static stlink_t* stlink_open(const int verbose) {
     
     stlink_t *sl = malloc(sizeof (stlink_t));
     struct stlink_libsg *slsg = malloc(sizeof (struct stlink_libsg));
@@ -1076,24 +1075,19 @@ static stlink_t* stlink_open(const char *dev_name, const int verbose) {
 
 
 
-stlink_t* stlink_v1_open(const char *dev_name, const int verbose) {
+stlink_t* stlink_v1_open(const int verbose) {
     ugly_init(verbose);
-    stlink_t *sl = stlink_open(dev_name, verbose);
+    stlink_t *sl = stlink_open(verbose);
     if (sl == NULL) {
         fputs("Error: could not open stlink device\n", stderr);
         return NULL;
     }
 
     stlink_version(sl);
-    struct stlink_libsg *sg = sl->backend_data;
 
     if ((sl->version.st_vid != USB_ST_VID) || (sl->version.stlink_pid != USB_STLINK_PID)) {
-        fprintf(stderr, "Error: the device %s is not a stlink\n",
-                dev_name);
-        fprintf(stderr, "       VID: got %04x expect %04x \n",
-                sl->version.st_vid, USB_ST_VID);
-        fprintf(stderr, "       PID: got %04x expect %04x \n",
-                sl->version.stlink_pid, USB_STLINK_PID);
+        ugly_log(UERROR, LOG_TAG, 
+            "WTF? successfully opened, but unable to read version details. BROKEN!\n");
         return NULL;
     }
 
@@ -1116,7 +1110,7 @@ stlink_t* stlink_v1_open(const char *dev_name, const int verbose) {
     delay(5000);
 
     DLOG("Attempting to reopen the stlink...\n");
-    sl = stlink_open(dev_name, verbose);
+    sl = stlink_open(verbose);
     if (sl == NULL) {
         fputs("Error: could not open stlink device\n", stderr);
         return NULL;
index 8485d3d88eb0d7f50c3dce9b6b059936a5ea1aee..d4d7723b84a7327fb608586ef889f3c1c6920c9f 100644 (file)
@@ -57,12 +57,13 @@ extern "C" {
         uint32_t q_addr;
 
         // Sense (error information) data
+        // obsolete, this was fed to the scsi tools
         unsigned char sense_buf[SENSE_BUF_LEN];
 
         reg reg;
     };
 
-    stlink_t* stlink_v1_open(const char *dev_name, const int verbose);
+    stlink_t* stlink_v1_open(const int verbose);
 
 #ifdef __cplusplus
 }
index 742ba445387d72bfaed11aab7be2209027a7add8..a8a7022c80cb8e9c1aa854919271b84dda125b37 100644 (file)
 
 int main(int argc, char *argv[]) {
        // set scpi lib debug level: 0 for no debug info, 10 for lots
-       char *dev_name;
 
        switch (argc) {
        case 1:
                fputs(
-                       "\nUsage: stlink-access-test /dev/sg0, sg1, ...\n"
+                       "\nUsage: stlink-access-test [anything at all] ...\n"
                                "\n*** Notice: The stlink firmware violates the USB standard.\n"
-                               "*** If you plug-in the discovery's stlink, wait a several\n"
-                               "*** minutes to let the kernel driver swallow the broken device.\n"
-                               "*** Watch:\ntail -f /var/log/messages\n"
-                               "*** This command sequence can shorten the waiting time and fix some issues.\n"
+                               "*** Because we just use libusb, we can just tell the kernel's\n"
+                               "*** driver to simply ignore the device...\n"
                                "*** Unplug the stlink and execute once as root:\n"
-                               "modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:lrwsro\n\n",
+                               "modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i\n\n",
                        stderr);
                return EXIT_FAILURE;
-       case 2:
-               dev_name = argv[1];
-               break;
        default:
-        fprintf(stderr, "bzzt\n");
-               return EXIT_FAILURE;
+        break;
        }
 
-       stlink_t *sl = stlink_v1_open(dev_name, 99);
+       stlink_t *sl = stlink_v1_open(99);
        if (sl == NULL)
                return EXIT_FAILURE;
-
+    
        // we are in mass mode, go to swd
        stlink_enter_swd_mode(sl);
        stlink_current_mode(sl);