From 0f376a74a51cf3e3134b0e6f2ad0415f43968ed1 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Thu, 3 Nov 2011 23:40:27 +0000 Subject: [PATCH] Remove device names, we now just find it via USB ids. 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 | 38 ++------------------------------------ src/stlink-sg.c | 18 ++++++------------ src/stlink-sg.h | 3 ++- src/test_sg.c | 21 +++++++-------------- 4 files changed, 17 insertions(+), 63 deletions(-) diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index 65297bc..df3657a 100644 --- a/gdbserver/gdb-server.c +++ b/gdbserver/gdb-server.c @@ -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; } diff --git a/src/stlink-sg.c b/src/stlink-sg.c index 2253212..64f1820 100644 --- a/src/stlink-sg.c +++ b/src/stlink-sg.c @@ -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; diff --git a/src/stlink-sg.h b/src/stlink-sg.h index 8485d3d..d4d7723 100644 --- a/src/stlink-sg.h +++ b/src/stlink-sg.h @@ -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 } diff --git a/src/test_sg.c b/src/test_sg.c index 742ba44..a8a7022 100644 --- a/src/test_sg.c +++ b/src/test_sg.c @@ -10,33 +10,26 @@ 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); -- 2.47.2