Merge branch 'master' of https://github.com/texane/stlink
[fw/stlink] / gdbserver / gdb-server.c
index e7efbf15bca8aef35ddce8d13aeb9f43b059e5a3..bcb3c974b1e86d171482bff50a61d00dc15d7ea6 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "gdb-remote.h"
 
-#define DEFAULT_LOGGING_LEVEL 10
+#define DEFAULT_LOGGING_LEVEL 100
 #define DEFAULT_GDB_LISTEN_PORT 4242
 
 #define STRINGIFY_inner(name) #name
@@ -143,7 +143,7 @@ int parse_options(int argc, char** argv, st_state_t *st) {
             break;
         case 'd':
             if (strlen(optarg) > sizeof (st->devicename)) {
-                fprintf(stderr, "device name too long: %ld\n", strlen(optarg));
+                fprintf(stderr, "device name too long: %zd\n", strlen(optarg));
             } else {
                 strcpy(st->devicename, optarg);
             }
@@ -188,7 +188,7 @@ int main(int argc, char** argv) {
        memset(&state, 0, sizeof(state));
        // set defaults...
        state.stlink_version = 2;
-       state.logging_level = 10;
+       state.logging_level = DEFAULT_LOGGING_LEVEL;
        state.listen_port = DEFAULT_GDB_LISTEN_PORT;
        parse_options(argc, argv, &state);
        switch (state.stlink_version) {
@@ -197,58 +197,17 @@ 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;
-
-                       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_quirk_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_quirk_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_quirk_open(state.devicename, state.logging_level);
-               }
+               sl = stlink_v1_open(state.logging_level);
+               if(sl == NULL) return 1;
                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) {
-               stlink_exit_dfu_mode(sl);
-       }
+    }
 
-       if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
-         stlink_enter_swd_mode(sl);
-       }
+    if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
+        if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
+            stlink_exit_dfu_mode(sl);
+        }
+        stlink_enter_swd_mode(sl);
+    }
 
        uint32_t chip_id = stlink_chip_id(sl);
        uint32_t core_id = stlink_core_id(sl);