|
|
@@ -51,13 +51,12 @@ enum {
|
|
|
#endif
|
|
|
|
|
|
#include "elist.h"
|
|
|
-#include "fpgautils.h"
|
|
|
#include "logging.h"
|
|
|
#include "miner.h"
|
|
|
+#include "fpgautils.h"
|
|
|
|
|
|
#ifdef HAVE_LIBUDEV
|
|
|
-int
|
|
|
-serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
|
|
|
+int serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
|
|
|
{
|
|
|
struct udev *udev = udev_new();
|
|
|
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
|
|
|
@@ -87,15 +86,13 @@ serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
|
|
|
return found;
|
|
|
}
|
|
|
#else
|
|
|
-int
|
|
|
-serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
|
|
|
+int serial_autodetect_udev(__maybe_unused detectone_func_t detectone, __maybe_unused const char*prodname)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-int
|
|
|
-serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
|
|
|
+int serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
|
|
|
{
|
|
|
#ifndef WIN32
|
|
|
DIR *D;
|
|
|
@@ -208,32 +205,35 @@ int serial_autodetect_ftdi(__maybe_unused detectone_func_t detectone, __maybe_un
|
|
|
|
|
|
struct device_api *serial_claim(const char *devpath, struct device_api *api);
|
|
|
|
|
|
-int
|
|
|
-_serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
|
|
|
+int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
|
|
|
{
|
|
|
struct string_elist *iter, *tmp;
|
|
|
- const char*s, *p;
|
|
|
+ const char *dev, *colon;
|
|
|
bool inhibitauto = false;
|
|
|
char found = 0;
|
|
|
bool forceauto = flags & 1;
|
|
|
bool hasname;
|
|
|
- size_t dnamel = strlen(dname);
|
|
|
+ size_t namel = strlen(api->name);
|
|
|
+ size_t dnamel = strlen(api->dname);
|
|
|
|
|
|
list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
|
|
|
- s = iter->string;
|
|
|
- if ((p = strchr(s, ':')) && p[1] != '\0') {
|
|
|
- size_t plen = p - s;
|
|
|
- if (plen != dnamel || strncasecmp(s, dname, plen))
|
|
|
+ dev = iter->string;
|
|
|
+ if ((colon = strchr(dev, ':')) && colon[1] != '\0') {
|
|
|
+ size_t idlen = colon - dev;
|
|
|
+
|
|
|
+ // allow either name:device or dname:device
|
|
|
+ if ((idlen != namel || strncasecmp(dev, api->name, idlen))
|
|
|
+ && (idlen != dnamel || strncasecmp(dev, api->dname, idlen)))
|
|
|
continue;
|
|
|
- s = p + 1;
|
|
|
+
|
|
|
+ dev = colon + 1;
|
|
|
hasname = true;
|
|
|
}
|
|
|
else
|
|
|
hasname = false;
|
|
|
- if (!strcmp(s, "auto"))
|
|
|
+ if (!strcmp(dev, "auto"))
|
|
|
forceauto = true;
|
|
|
- else
|
|
|
- if (!strcmp(s, "noauto"))
|
|
|
+ else if (!strcmp(dev, "noauto"))
|
|
|
inhibitauto = true;
|
|
|
else
|
|
|
if ((flags & 2) && !hasname)
|
|
|
@@ -242,13 +242,12 @@ _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t aut
|
|
|
if (!detectone)
|
|
|
{} // do nothing
|
|
|
else
|
|
|
- if (serial_claim(s, NULL))
|
|
|
+ if (serial_claim(dev, NULL))
|
|
|
{
|
|
|
- applog(LOG_DEBUG, "%s is already claimed... skipping probes", s);
|
|
|
+ applog(LOG_DEBUG, "%s is already claimed... skipping probes", dev);
|
|
|
string_elist_del(iter);
|
|
|
}
|
|
|
- else
|
|
|
- if (detectone(s)) {
|
|
|
+ else if (detectone(dev)) {
|
|
|
string_elist_del(iter);
|
|
|
inhibitauto = true;
|
|
|
++found;
|
|
|
@@ -482,8 +481,7 @@ void termios_debug(const char *devpath, struct termios *my_termios, const char *
|
|
|
/* NOTE: Linux only supports uint8_t (decisecond) timeouts; limiting it in
|
|
|
* this interface buys us warnings when bad constants are passed in.
|
|
|
*/
|
|
|
-int
|
|
|
-serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge)
|
|
|
+int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge)
|
|
|
{
|
|
|
#ifdef WIN32
|
|
|
HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
@@ -600,8 +598,7 @@ serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-ssize_t
|
|
|
-_serial_read(int fd, char *buf, size_t bufsiz, char *eol)
|
|
|
+ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
|
|
|
{
|
|
|
ssize_t len, tlen = 0;
|
|
|
while (bufsiz) {
|
|
|
@@ -617,8 +614,7 @@ _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
|
|
|
return tlen;
|
|
|
}
|
|
|
|
|
|
-static FILE*
|
|
|
-_open_bitstream(const char*path, const char*subdir, const char*filename)
|
|
|
+static FILE *_open_bitstream(const char *path, const char *subdir, const char *filename)
|
|
|
{
|
|
|
char fullpath[PATH_MAX];
|
|
|
strcpy(fullpath, path);
|
|
|
@@ -642,8 +638,7 @@ _open_bitstream(const char*path, const char*subdir, const char*filename)
|
|
|
_open_bitstream(path, NULL); \
|
|
|
} while(0)
|
|
|
|
|
|
-FILE*
|
|
|
-open_bitstream(const char*dname, const char*filename)
|
|
|
+FILE *open_bitstream(const char *dname, const char *filename)
|
|
|
{
|
|
|
FILE *f;
|
|
|
|