flag out the only scsi specific code
authorKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 19:09:31 +0000 (19:09 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Sat, 22 Oct 2011 19:09:31 +0000 (19:09 +0000)
Also flag out some places where code appears unused.

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

index bbd76a807fb6f9541d529d182a6f83f4caec6fa9..2c73f165f5287e3b16f35382c93b5abc90bdb50f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 ##
 VPATH=src
 
-SOURCES_LIB=stlink-common.c stlink-usb.c #stlink-sg.c
+SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c
 OBJS_LIB=$(SOURCES_LIB:.c=.o)
 TEST_PROGRAMS=test_usb #test_sg
 LDFLAGS=-lusb-1.0 -L. -lstlink
index a443f95f6bb58b59460e3231a5a650d637763d6c..a74525a5a300f87354b1b51812393093582bb6af 100644 (file)
@@ -1,5 +1,7 @@
 /* simple wrapper around the stlink_flash_write function */
 
+// TODO - this should be done as just a simple flag to the st-util command line...
+
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -87,7 +89,7 @@ int main(int ac, char** av)
   if (o.devname != NULL) /* stlinkv1 */
   {
     static const int scsi_verbose = 2;
-    sl = stlink_quirk_open(o.devname, scsi_verbose);
+    sl = stlink_v1_open(o.devname, scsi_verbose);
     if (sl == NULL) goto on_error;
   }
   else /* stlinkv2 */
index f1da63e45c4462ed21f82177c432b7361320a88f..3e2f99a96d112fc884fb90251e33d0b58bd7865a 100644 (file)
@@ -207,7 +207,7 @@ int main(int argc, char** argv) {
                                        const int X_index = 7;
                                        DevName[X_index] = DevNum + '0';
                                        if (!access(DevName, F_OK)) {
-                                               sl = stlink_quirk_open(DevName, 0);
+                                               sl = stlink_v1_open(DevName, 0);
                                                ExistDevCount++;
                                        }
                                } else if (DevNum < 100) {
@@ -217,7 +217,7 @@ int main(int argc, char** argv) {
                                        DevName[X_index] = DevNum / 10 + '0';
                                        DevName[Y_index] = DevNum % 10 + '0';
                                        if (!access(DevName, F_OK)) {
-                                               sl = stlink_quirk_open(DevName, 0);
+                                               sl = stlink_v1_open(DevName, 0);
                                                ExistDevCount++;
                                        }
                                }
@@ -231,7 +231,7 @@ int main(int argc, char** argv) {
                                return 1;
                        }
                } else {
-                       sl = stlink_quirk_open(state.devicename, state.logging_level);
+                       sl = stlink_v1_open(state.devicename, state.logging_level);
                }
                break;
        }
index b8220de133bf2c26a5f6b92338c87b288bb8e09c..137f6f605e4d58e41a0b540b8dbb8ae9d9f77089 100644 (file)
 
 #include "stlink-common.h"
 
-#if CONFIG_USE_LIBSG
-// sgutils2 (apt-get install libsgutils2-dev)
-#include <scsi/sg_lib.h>
-#include <scsi/sg_pt.h>
 #include "stlink-sg.h"
-#endif
 
 
 // Suspends execution of the calling process for
@@ -119,15 +114,18 @@ static void clear_buf(stlink_t *sl) {
 
 void _stlink_sg_close(stlink_t *sl) {
     if (sl) {
+#if FINISHED_WITH_SG
         struct stlink_libsg *slsg = sl->backend_data;
         scsi_pt_close_device(slsg->sg_fd);
         free(slsg);
+#endif
     }
 }
 
 
 //TODO rewrite/cleanup, save the error in sl
 
+#if FINISHED_WITH_SG
 static void stlink_confirm_inq(stlink_t *stl, struct sg_pt_base *ptvp) {
     struct stlink_libsg *sl = stl->backend_data;
     const int e = sl->do_scsi_pt_err;
@@ -209,8 +207,10 @@ static void stlink_confirm_inq(stlink_t *stl, struct sg_pt_base *ptvp) {
                     "category (%d)\n", cat);
     }
 }
+#endif
 
 void stlink_q(stlink_t *sl) {
+#if FINISHED_WITH_SG
     struct stlink_libsg* sg = sl->backend_data;
     DD(sl, "CDB[");
     for (int i = 0; i < CDB_SL; i++)
@@ -245,6 +245,7 @@ void stlink_q(stlink_t *sl) {
     stlink_confirm_inq(sl, ptvp);
     // TODO recycle: clear_scsi_pt_obj(struct sg_pt_base * objp);
     destruct_scsi_pt_obj(ptvp);
+#endif
 }
 
 // TODO thinking, cleanup
@@ -803,7 +804,7 @@ stlink_t* stlink_open(const char *dev_name, const int verbose) {
 
 
 
-stlink_t* stlink_quirk_open(const char *dev_name, const int verbose) {
+stlink_t* stlink_v1_open(const char *dev_name, const int verbose) {
 
     stlink_t *sl = stlink_open(dev_name, verbose);
     if (sl == NULL) {
index 523b7d8836927df90385f94df8ca1613307bd390..afa47c51a3805c9f84cc551bc8d0ddede72a81e1 100644 (file)
@@ -40,7 +40,6 @@ extern "C" {
 
 
 
-#if defined(CONFIG_USE_LIBUSB)
     struct stlink_libsg {
         int sg_fd;
         int do_scsi_pt_err;
@@ -63,11 +62,8 @@ extern "C" {
 
         reg reg;
     };
-#else
-    struct stlink_libsg {};
-#endif
 
-    stlink_t* stlink_quirk_open(const char *dev_name, const int verbose);
+    stlink_t* stlink_v1_open(const char *dev_name, const int verbose);
 
 #ifdef __cplusplus
 }
index 57a4a2fddff510c8b653893cbf8f58fe3161c473..52699614420b464eb095f0f3c264db2d39219e82 100644 (file)
@@ -116,7 +116,10 @@ ssize_t send_recv(struct stlink_libusb* handle, int terminate,
         if (submit_wait(handle, handle->rep_trans)) return -1;
         res = handle->rep_trans->actual_length;
     }
+    
     if ((handle->protocoll == 1) && terminate) {
+        fprintf(stderr, "This is never used....\n");
+        exit(EXIT_FAILURE);
         /* Read the SG reply */
         unsigned char sg_buf[13];
         libusb_fill_bulk_transfer
@@ -172,6 +175,7 @@ static int fill_command
     int i = 0;
     memset(cmd, 0, sizeof (sl->c_buf));
     if(slu->protocoll == 1) {
+        fprintf(stderr, "This is never used....\n");
         cmd[i++] = 'U';
         cmd[i++] = 'S';
         cmd[i++] = 'B';
@@ -652,11 +656,12 @@ stlink_t* stlink_open_usb(const int verbose) {
         printf("libusb_alloc_transfer\n");
         goto on_libusb_error;
     }
-
+    // TODO - could use the scanning techniq from stm8 code here...
     slu->ep_rep = 1 /* ep rep */ | LIBUSB_ENDPOINT_IN;
     slu->ep_req = 2 /* ep req */ | LIBUSB_ENDPOINT_OUT;
 
     slu->sg_transfer_idx = 0;
+    // TODO - never used at the moment, always CMD_SIZE
     slu->cmd_len = (slu->protocoll == 1)? STLINK_SG_SIZE: STLINK_CMD_SIZE;
 
     /* success */
index 9efe6d80db94ae1ddfed9162a4b441dcf2d7911f..a12ed1f409ffc6c057a54f98911ccf75dfd65c68 100644 (file)
@@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
        fprintf(stderr, "Using sg_lib %s : scsi_pt %s\n", sg_lib_version(),
                scsi_pt_version());
 
-       stlink_t *sl = stlink_quirk_open(dev_name, scsi_verbose);
+       stlink_t *sl = stlink_v1_open(dev_name, scsi_verbose);
        if (sl == NULL)
                return EXIT_FAILURE;