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.
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;
}
_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));
-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;
}
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;
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
}
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);