From 42d2da531f52ead18091a1211a5e6206e27dc178 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Sat, 22 Oct 2011 19:09:31 +0000 Subject: [PATCH] flag out the only scsi specific code Also flag out some places where code appears unused. --- Makefile | 2 +- flash/main.c | 4 +++- gdbserver/gdb-server.c | 6 +++--- src/stlink-sg.c | 13 +++++++------ src/stlink-sg.h | 6 +----- src/stlink-usb.c | 7 ++++++- src/test_sg.c | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index bbd76a8..2c73f16 100644 --- 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 diff --git a/flash/main.c b/flash/main.c index a443f95..a74525a 100644 --- a/flash/main.c +++ b/flash/main.c @@ -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 #include @@ -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 */ diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index f1da63e..3e2f99a 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -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; } diff --git a/src/stlink-sg.c b/src/stlink-sg.c index b8220de..137f6f6 100644 --- a/src/stlink-sg.c +++ b/src/stlink-sg.c @@ -82,12 +82,7 @@ #include "stlink-common.h" -#if CONFIG_USE_LIBSG -// sgutils2 (apt-get install libsgutils2-dev) -#include -#include #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) { diff --git a/src/stlink-sg.h b/src/stlink-sg.h index 523b7d8..afa47c5 100644 --- a/src/stlink-sg.h +++ b/src/stlink-sg.h @@ -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 } diff --git a/src/stlink-usb.c b/src/stlink-usb.c index 57a4a2f..5269961 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -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 */ diff --git a/src/test_sg.c b/src/test_sg.c index 9efe6d8..a12ed1f 100644 --- a/src/test_sg.c +++ b/src/test_sg.c @@ -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; -- 2.39.5