mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-11 07:17:58 +00:00
Use libudev to autodetect BitFORCE GPUs, if available
This commit is contained in:
parent
aff55fab32
commit
ae99714241
@ -22,6 +22,7 @@ bin_SCRIPTS = *.cl
|
|||||||
cgminer_LDFLAGS = $(PTHREAD_FLAGS)
|
cgminer_LDFLAGS = $(PTHREAD_FLAGS)
|
||||||
cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
|
cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
|
||||||
@OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
|
@OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
|
||||||
|
@UDEV_LIBS@ \
|
||||||
@MATH_LIBS@ lib/libgnu.a ccan/libccan.a
|
@MATH_LIBS@ lib/libgnu.a ccan/libccan.a
|
||||||
cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@
|
cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@
|
||||||
|
|
||||||
|
61
bitforce.c
61
bitforce.c
@ -28,6 +28,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBUDEV
|
||||||
|
#include <libudev.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "elist.h"
|
#include "elist.h"
|
||||||
#include "miner.h"
|
#include "miner.h"
|
||||||
|
|
||||||
@ -121,7 +127,43 @@ static bool bitforce_detect_one(const char *devpath)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bitforce_detect_auto()
|
static bool bitforce_detect_auto_udev()
|
||||||
|
{
|
||||||
|
#ifdef HAVE_LIBUDEV
|
||||||
|
struct udev *udev = udev_new();
|
||||||
|
struct udev_enumerate *enumerate = udev_enumerate_new(udev);
|
||||||
|
struct udev_list_entry *list_entry;
|
||||||
|
bool foundany = false;
|
||||||
|
|
||||||
|
udev_enumerate_add_match_subsystem(enumerate, "tty");
|
||||||
|
udev_enumerate_add_match_property(enumerate, "ID_MODEL", "BitFORCE*SHA256");
|
||||||
|
udev_enumerate_scan_devices(enumerate);
|
||||||
|
udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
|
||||||
|
struct udev_device *device = udev_device_new_from_syspath(
|
||||||
|
udev_enumerate_get_udev(enumerate),
|
||||||
|
udev_list_entry_get_name(list_entry)
|
||||||
|
);
|
||||||
|
if (!device)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const char *devpath = udev_device_get_devnode(device);
|
||||||
|
if (devpath) {
|
||||||
|
foundany = true;
|
||||||
|
bitforce_detect_one(devpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
udev_device_unref(device);
|
||||||
|
}
|
||||||
|
udev_enumerate_unref(enumerate);
|
||||||
|
udev_unref(udev);
|
||||||
|
|
||||||
|
return foundany;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool bitforce_detect_auto_devserial()
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
DIR *D;
|
DIR *D;
|
||||||
@ -129,22 +171,35 @@ static void bitforce_detect_auto()
|
|||||||
const char udevdir[] = "/dev/serial/by-id";
|
const char udevdir[] = "/dev/serial/by-id";
|
||||||
char devpath[sizeof(udevdir) + 1 + NAME_MAX];
|
char devpath[sizeof(udevdir) + 1 + NAME_MAX];
|
||||||
char *devfile = devpath + sizeof(udevdir);
|
char *devfile = devpath + sizeof(udevdir);
|
||||||
|
bool foundany = false;
|
||||||
|
|
||||||
D = opendir(udevdir);
|
D = opendir(udevdir);
|
||||||
if (!D)
|
if (!D)
|
||||||
return;
|
return false;
|
||||||
memcpy(devpath, udevdir, sizeof(udevdir) - 1);
|
memcpy(devpath, udevdir, sizeof(udevdir) - 1);
|
||||||
devpath[sizeof(udevdir) - 1] = '/';
|
devpath[sizeof(udevdir) - 1] = '/';
|
||||||
while ( (de = readdir(D)) ) {
|
while ( (de = readdir(D)) ) {
|
||||||
if (!strstr(de->d_name, "BitFORCE_SHA256"))
|
if (!strstr(de->d_name, "BitFORCE_SHA256"))
|
||||||
continue;
|
continue;
|
||||||
|
foundany = true;
|
||||||
strcpy(devfile, de->d_name);
|
strcpy(devfile, de->d_name);
|
||||||
bitforce_detect_one(devpath);
|
bitforce_detect_one(devpath);
|
||||||
}
|
}
|
||||||
closedir(D);
|
closedir(D);
|
||||||
|
|
||||||
|
return foundany;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bitforce_detect_auto()
|
||||||
|
{
|
||||||
|
bitforce_detect_auto_udev() ?:
|
||||||
|
bitforce_detect_auto_devserial() ?:
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
|
||||||
static void bitforce_detect()
|
static void bitforce_detect()
|
||||||
{
|
{
|
||||||
struct string_elist *iter, *tmp;
|
struct string_elist *iter, *tmp;
|
||||||
|
27
configure.ac
27
configure.ac
@ -260,6 +260,26 @@ fi
|
|||||||
|
|
||||||
AM_CONDITIONAL([HAS_YASM], [test x$has_yasm = xtrue])
|
AM_CONDITIONAL([HAS_YASM], [test x$has_yasm = xtrue])
|
||||||
|
|
||||||
|
if test "x$bitforce" != xno; then
|
||||||
|
AC_ARG_WITH([libudev], [AC_HELP_STRING([--with-libudev], [Autodetect FPGAs using libudev])],
|
||||||
|
[libudev=$enableval],
|
||||||
|
[libudev=auto]
|
||||||
|
)
|
||||||
|
if test "x$libudev" != "xno"; then
|
||||||
|
AC_CHECK_LIB([udev], [udev_device_get_devnode], [
|
||||||
|
libudev=yes
|
||||||
|
UDEV_LIBS=-ludev
|
||||||
|
AC_DEFINE([HAVE_LIBUDEV], [1], [Defined to 1 if libudev is wanted])
|
||||||
|
], [
|
||||||
|
if test "x$libudev" = "xyes"; then
|
||||||
|
AC_MSG_ERROR([libudev not found])
|
||||||
|
fi
|
||||||
|
libudev=no
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL([HAVE_LIBUDEV], [test x$libudev != xno])
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG()
|
PKG_PROG_PKG_CONFIG()
|
||||||
|
|
||||||
PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.15.6], [AC_DEFINE([CURL_HAS_SOCKOPT], [1], [Defined if version of curl supports sockopts.])],
|
PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.15.6], [AC_DEFINE([CURL_HAS_SOCKOPT], [1], [Defined if version of curl supports sockopts.])],
|
||||||
@ -320,6 +340,7 @@ AC_SUBST(NCURSES_LIBS)
|
|||||||
AC_SUBST(PDCURSES_LIBS)
|
AC_SUBST(PDCURSES_LIBS)
|
||||||
AC_SUBST(WS2_LIBS)
|
AC_SUBST(WS2_LIBS)
|
||||||
AC_SUBST(MATH_LIBS)
|
AC_SUBST(MATH_LIBS)
|
||||||
|
AC_SUBST(UDEV_LIBS)
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
@ -383,6 +404,10 @@ else
|
|||||||
echo " Icarus.FPGAs.........: Disabled"
|
echo " Icarus.FPGAs.........: Disabled"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "x$bitforce" != xno; then
|
||||||
|
echo " libudev.detection....: $libudev"
|
||||||
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
if test "x$cpumining" = xyes; then
|
if test "x$cpumining" = xyes; then
|
||||||
echo " CPU Mining...........: Enabled"
|
echo " CPU Mining...........: Enabled"
|
||||||
@ -396,7 +421,7 @@ echo "Compilation............: make (or gmake)"
|
|||||||
echo " CPPFLAGS.............: $CPPFLAGS"
|
echo " CPPFLAGS.............: $CPPFLAGS"
|
||||||
echo " CFLAGS...............: $CFLAGS"
|
echo " CFLAGS...............: $CFLAGS"
|
||||||
echo " LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS"
|
echo " LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS"
|
||||||
echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS"
|
echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS"
|
||||||
echo
|
echo
|
||||||
echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
|
echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
|
||||||
echo " prefix...............: $prefix"
|
echo " prefix...............: $prefix"
|
||||||
|
Loading…
Reference in New Issue
Block a user