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.
pull/29/head
Karl Palsson 2011-11-03 23:40:27 +00:00
rodzic 87490393e8
commit 0f376a74a5
4 zmienionych plików z 17 dodań i 63 usunięć

Wyświetl plik

@ -197,42 +197,8 @@ int main(int argc, char** argv) {
if(sl == NULL) return 1; if(sl == NULL) return 1;
break; break;
case 1: case 1:
if (strlen(state.devicename) == 0) { sl = stlink_v1_open(NULL, state.logging_level);
const int DevNumMax = 99; if(sl == NULL) return 1;
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);
}
break; break;
} }

Wyświetl plik

@ -967,8 +967,7 @@ stlink_backend_t _stlink_sg_backend = {
_stlink_sg_force_debug _stlink_sg_force_debug
}; };
static stlink_t* stlink_open(const char *dev_name, const int verbose) { static stlink_t* stlink_open(const int verbose) {
DLOG("*** stlink_open [%s] ***\n", dev_name);
stlink_t *sl = malloc(sizeof (stlink_t)); stlink_t *sl = malloc(sizeof (stlink_t));
struct stlink_libsg *slsg = malloc(sizeof (struct stlink_libsg)); 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); ugly_init(verbose);
stlink_t *sl = stlink_open(dev_name, verbose); stlink_t *sl = stlink_open(verbose);
if (sl == NULL) { if (sl == NULL) {
fputs("Error: could not open stlink device\n", stderr); fputs("Error: could not open stlink device\n", stderr);
return NULL; return NULL;
} }
stlink_version(sl); 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)) { 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", ugly_log(UERROR, LOG_TAG,
dev_name); "WTF? successfully opened, but unable to read version details. BROKEN!\n");
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);
return NULL; return NULL;
} }
@ -1116,7 +1110,7 @@ stlink_t* stlink_v1_open(const char *dev_name, const int verbose) {
delay(5000); delay(5000);
DLOG("Attempting to reopen the stlink...\n"); DLOG("Attempting to reopen the stlink...\n");
sl = stlink_open(dev_name, verbose); sl = stlink_open(verbose);
if (sl == NULL) { if (sl == NULL) {
fputs("Error: could not open stlink device\n", stderr); fputs("Error: could not open stlink device\n", stderr);
return NULL; return NULL;

Wyświetl plik

@ -57,12 +57,13 @@ extern "C" {
uint32_t q_addr; uint32_t q_addr;
// Sense (error information) data // Sense (error information) data
// obsolete, this was fed to the scsi tools
unsigned char sense_buf[SENSE_BUF_LEN]; unsigned char sense_buf[SENSE_BUF_LEN];
reg reg; reg reg;
}; };
stlink_t* stlink_v1_open(const char *dev_name, const int verbose); stlink_t* stlink_v1_open(const int verbose);
#ifdef __cplusplus #ifdef __cplusplus
} }

Wyświetl plik

@ -10,33 +10,26 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// set scpi lib debug level: 0 for no debug info, 10 for lots // set scpi lib debug level: 0 for no debug info, 10 for lots
char *dev_name;
switch (argc) { switch (argc) {
case 1: case 1:
fputs( 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" "\n*** Notice: The stlink firmware violates the USB standard.\n"
"*** If you plug-in the discovery's stlink, wait a several\n" "*** Because we just use libusb, we can just tell the kernel's\n"
"*** minutes to let the kernel driver swallow the broken device.\n" "*** driver to simply ignore the device...\n"
"*** Watch:\ntail -f /var/log/messages\n"
"*** This command sequence can shorten the waiting time and fix some issues.\n"
"*** Unplug the stlink and execute once as root:\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); stderr);
return EXIT_FAILURE; return EXIT_FAILURE;
case 2:
dev_name = argv[1];
break;
default: default:
fprintf(stderr, "bzzt\n"); break;
return EXIT_FAILURE;
} }
stlink_t *sl = stlink_v1_open(dev_name, 99); stlink_t *sl = stlink_v1_open(99);
if (sl == NULL) if (sl == NULL)
return EXIT_FAILURE; return EXIT_FAILURE;
// we are in mass mode, go to swd // we are in mass mode, go to swd
stlink_enter_swd_mode(sl); stlink_enter_swd_mode(sl);
stlink_current_mode(sl); stlink_current_mode(sl);