1
0
mirror of git://projects.qi-hardware.com/openwrt-packages.git synced 2024-12-22 12:11:09 +02:00

cgminer: add Icarus support

This commit is contained in:
Xiangfu Liu 2012-02-15 12:58:39 +08:00
parent e114a4e891
commit 622aa44c2c
8 changed files with 565 additions and 3 deletions

View File

@ -9,8 +9,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=cgminer
PKG_VERSION:=20120210
PKG_REV:=6e3ad7ad250b5d63be2472d9dc56325d143d7ace
PKG_VERSION:=20120215
PKG_REV:=9a0e4f8facababf54cf6dcac7bf93a0e6099047e
PKG_RELEASE:=1
PKG_INSTALL:=1
@ -37,7 +37,7 @@ endef
define Package/cgminer/description
endef
CONFIGURE_ARGS += --enable-bitforce --disable-opencl --disable-adl --enable-cpumining
CONFIGURE_ARGS += --disable-opencl --disable-adl --enable-icarus
TARGET_CFLAGS +=
TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib

View File

@ -0,0 +1,77 @@
From 75e27968a62025d1ac3655275e8f52b879092255 Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Mon, 13 Feb 2012 16:04:13 +0800
Subject: [PATCH 1/6] add Icarus support to autoreconf system
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
Makefile.am | 3 +++
configure.ac | 21 +++++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 4249d51..5262d52 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -70,3 +70,6 @@ if HAS_BITFORCE
cgminer_SOURCES += bitforce.c
endif
+if HAS_ICARUS
+cgminer_SOURCES += icarus.c
+endif
diff --git a/configure.ac b/configure.ac
index ee665aa..a931867 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,6 +196,17 @@ if test "x$bitforce" = xyes; then
fi
AM_CONDITIONAL([HAS_BITFORCE], [test x$bitforce = xyes])
+icarus="no"
+
+AC_ARG_ENABLE([icarus],
+ [AC_HELP_STRING([--enable-icarus],[Compile support for Icarus (default disabled)])],
+ [icarus=$enableval]
+ )
+if test "x$icarus" = xyes; then
+ AC_DEFINE([USE_ICARUS], [1], [Defined to 1 if Icarus support is wanted])
+fi
+AM_CONDITIONAL([HAS_ICARUS], [test x$icarus = xyes])
+
AC_SEARCH_LIBS(addstr, ncurses pdcurses, ,
AC_MSG_ERROR([Could not find curses library - please install libncurses-dev or pdcurses-dev]))
@@ -338,13 +349,13 @@ if test "x$opencl" != xno; then
echo " OpenCL...............: FOUND. GPU mining support enabled"
else
echo " OpenCL...............: NOT FOUND. GPU mining support DISABLED"
- if test "x$cpumining$bitforce" = xnono; then
+ if test "x$cpumining$bitforce$icarus" = xnonono; then
AC_MSG_ERROR([No mining configured in])
fi
fi
else
echo " OpenCL...............: Detection overrided. GPU mining support DISABLED"
- if test "x$cpumining$bitforce" = xnono; then
+ if test "x$cpumining$bitforce$icarus" = xnonono; then
AC_MSG_ERROR([No mining configured in])
fi
fi
@@ -366,6 +377,12 @@ else
echo " BitForce.FPGAs.......: Disabled"
fi
+if test "x$icarus" = xyes; then
+ echo " Icarus.FPGAs.........: Enabled"
+else
+ echo " Icarus.FPGAs.........: Disabled"
+fi
+
echo
if test "x$cpumining" = xyes; then
echo " CPU Mining...........: Enabled"
--
1.7.5.4

View File

@ -0,0 +1,289 @@
From 80451867b6eeeb79e02d639171999d99069bb27f Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Mon, 13 Feb 2012 16:04:34 +0800
Subject: [PATCH 2/6] add icarus.c, base on bitforce.c
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
icarus.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 268 insertions(+), 0 deletions(-)
create mode 100644 icarus.c
diff --git a/icarus.c b/icarus.c
new file mode 100644
index 0000000..141d639
--- /dev/null
+++ b/icarus.c
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2012 Luke Dashjr
+ * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version. See COPYING for more details.
+ */
+
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
+#ifndef WIN32
+ #include <termios.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #ifndef O_CLOEXEC
+ #define O_CLOEXEC 0
+ #endif
+#else
+ #include <windows.h>
+ #include <io.h>
+#endif
+
+#include "elist.h"
+#include "miner.h"
+
+#define ICARUS_READ_FAULT_COUNT (8)
+
+struct device_api icarus_api;
+
+static void rev(char *s, ssize_t l)
+{
+ int i, j;
+ char t;
+
+ for(i = 0, j = l - 1; i < j; i++, j--) {
+ t = s[i];
+ s[i] = s[j];
+ s[j] = t;
+ }
+}
+
+static int icarus_open(const char *devpath)
+{
+#ifndef WIN32
+ struct termios my_termios;
+
+ int serialfd = open(devpath, O_RDWR | O_CLOEXEC | O_NOCTTY);
+
+ if(serialfd == -1)
+ return -1;
+
+ tcgetattr(serialfd, &my_termios);
+ my_termios.c_cflag = B115200;
+ my_termios.c_cflag |= CS8;
+ my_termios.c_cflag |= CREAD;
+ my_termios.c_cflag |= CLOCAL;
+ my_termios.c_cflag &= ~(CSIZE | PARENB);
+
+ my_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ my_termios.c_oflag &= ~OPOST;
+ my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ my_termios.c_cc[VTIME] = 10; /* block 1 second */
+ my_termios.c_cc[VMIN] = 0;
+ tcsetattr(serialfd, TCSANOW, &my_termios);
+
+ tcflush(serialfd, TCOFLUSH);
+ tcflush(serialfd, TCIFLUSH);
+
+ return serialfd;
+#else
+ HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+ if (unlikely(hSerial == INVALID_HANDLE_VALUE))
+ return -1;
+ return _open_osfhandle((LONG)hSerial, 0);
+#endif
+}
+
+static void icarus_gets(char *buf, size_t bufLen, int fd)
+{
+ int ret = 0, count = 0;
+
+ while (bufLen) {
+ ret = read(fd, buf, 1);
+ if(ret == 1) {
+ bufLen--;
+ buf++;
+ }
+ count++;
+ if(count == ICARUS_READ_FAULT_COUNT)
+ break;
+ }
+}
+
+static void icarus_write(int fd, const void *buf, size_t bufLen)
+{
+ ssize_t ret = write(fd, buf, bufLen);
+ if (unlikely(ret != bufLen))
+ quit(1, "icarus_write failed");
+}
+
+#define icarus_close(fd) close(fd)
+
+static bool icarus_detect_one(const char *devpath)
+{
+ static int i = 0;
+
+ const char ob[128] =
+"ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8";
+ const char nonce[] = "8e0b31c5";
+ char ob_bin[64];
+ char pdevbuf[4];
+ int fdDev;
+ char *nonce_hex;
+
+ if (total_devices == MAX_DEVICES)
+ return false;
+
+ fdDev = icarus_open(devpath);
+ if (unlikely(fdDev == -1)) {
+ applog(LOG_ERR, "Icarus Detect: Failed to open %s", devpath);
+ return false;
+ }
+
+ hex2bin(ob_bin, ob, sizeof(ob_bin));
+ icarus_write(fdDev, ob_bin, sizeof(ob_bin));
+
+ memset(pdevbuf, 0, sizeof(pdevbuf));
+ icarus_gets(pdevbuf, sizeof(pdevbuf), fdDev);
+
+ icarus_close(fdDev);
+
+ nonce_hex = bin2hex(pdevbuf, sizeof(pdevbuf));
+ if(strncmp(nonce_hex, nonce, 8)) {
+ applog(LOG_DEBUG, "Icarus Detect: Test failed at %s : get %s, should: %s",
+ devpath, nonce_hex, nonce);
+ return false;
+ }
+ free(nonce_hex);
+
+ /* We have a real Icarus! */
+ struct cgpu_info *icarus;
+ icarus = calloc(1, sizeof(*icarus));
+ devices[total_devices++] = icarus;
+ icarus->api = &icarus_api;
+ icarus->device_id = i++;
+ icarus->device_path = strdup(devpath);
+ icarus->enabled = true;
+ icarus->threads = 1;
+
+ return true;
+}
+
+static void icarus_detect_auto()
+{
+#ifndef WIN32
+ DIR *D;
+ struct dirent *de;
+ const char udevdir[] = "/dev/serial/by-id";
+ char devpath[sizeof(udevdir) + 1 + NAME_MAX];
+ char *devfile = devpath + sizeof(udevdir);
+
+ D = opendir(udevdir);
+ if (!D)
+ return;
+ memcpy(devpath, udevdir, sizeof(udevdir) - 1);
+ devpath[sizeof(udevdir) - 1] = '/';
+ while ( (de = readdir(D)) ) {
+ /* Icarus using a PL2303 usb-serial chip */
+ if (!strstr(de->d_name, "Prolific_Technology_Inc"))
+ continue;
+ strcpy(devfile, de->d_name);
+ icarus_detect_one(devpath);
+ }
+ closedir(D);
+#endif
+}
+
+static void icarus_detect()
+{
+ struct string_elist *iter, *tmp;
+
+ list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
+ if (icarus_detect_one(iter->string))
+ string_elist_del(iter);
+ }
+
+ icarus_detect_auto();
+}
+
+static pthread_mutex_t hash_lock;
+
+static bool icarus_thread_prepare(struct thr_info *thr)
+{
+ struct cgpu_info *icarus = thr->cgpu;
+
+ struct timeval now;
+
+ int fdDev = icarus_open(icarus->device_path);
+ if (unlikely(-1 == fdDev)) {
+ applog(LOG_ERR, "Failed to open Icarus on %s", icarus->device_path);
+ return false;
+ }
+
+ icarus->device_fd = fdDev;
+
+ applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
+ gettimeofday(&now, NULL);
+ get_datestamp(icarus->init, &now);
+
+ mutex_init(&hash_lock);
+ return true;
+}
+
+static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, uint64_t max_nonce)
+{
+ struct cgpu_info *icarus = thr->cgpu;
+ int fdDev = icarus->device_fd;
+
+ char pdevbuf[4];
+ unsigned char ob[64];
+ uint32_t nonce;
+ char *ob_hex, *nonce_hex;
+
+ mutex_lock(&hash_lock);
+
+ memcpy(ob, work->midstate, 32);
+ memcpy(ob + 32, work->data + 64, 32);
+ rev(ob, 32);
+ rev(ob + 32, 32);
+
+ icarus_write(fdDev, ob, sizeof(ob));
+
+ ob_hex = bin2hex(ob, sizeof(ob));
+ applog(LOG_DEBUG, "Icarus Send: %s", ob_hex);
+ free(ob_hex);
+
+ memset(pdevbuf, 0, sizeof(pdevbuf));
+ icarus_gets(pdevbuf, sizeof(pdevbuf), fdDev);
+
+ nonce_hex = bin2hex(pdevbuf, sizeof(pdevbuf));
+ applog(LOG_DEBUG, "Icarus Return: %s", nonce_hex);
+ free(nonce_hex);
+
+ work->blk.nonce = 0xffffffff;
+
+ memcpy((char *)&nonce, pdevbuf, sizeof(pdevbuf));
+#ifndef __BIG_ENDIAN__
+ nonce = swab32(nonce);
+#endif
+ submit_nonce(thr, work, nonce);
+
+ mutex_unlock(&hash_lock);
+ return 0xffffffff;
+}
+
+struct device_api icarus_api = {
+ .name = "Icarus",
+ .api_detect = icarus_detect,
+ .thread_prepare = icarus_thread_prepare,
+ .scanhash = icarus_scanhash,
+};
--
1.7.5.4

View File

@ -0,0 +1,77 @@
From fdcf21974b9b9d1b2d92ccad6b16eadf023515fc Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Mon, 13 Feb 2012 16:09:45 +0800
Subject: [PATCH 3/6] add icarus to cgminer.c
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
cgminer.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/cgminer.c b/cgminer.c
index 596a21a..cea6f59 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -400,7 +400,7 @@ static char *set_int_1_to_10(const char *arg, int *i)
return set_int_range(arg, i, 1, 10);
}
-#ifdef USE_BITFORCE
+#if defined(USE_BITFORCE) || defined(USE_ICARUS)
static char *add_serial(char *arg)
{
string_elist_add(arg, &scan_devices);
@@ -662,7 +662,7 @@ static struct opt_table opt_config_table[] = {
OPT_WITHOUT_ARG("--disable-gpu|-G",
opt_set_bool, &opt_nogpu,
"Disable GPU mining even if suitable devices exist"),
-#if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_BITFORCE))
+#if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_BITFORCE) || defined(USE_ICARUS))
OPT_WITHOUT_ARG("--enable-cpu|-C",
opt_set_bool, &opt_usecpu,
"Enable CPU mining with other mining (default: no CPU mining if other devices exist)"),
@@ -777,7 +777,7 @@ static struct opt_table opt_config_table[] = {
OPT_WITHOUT_ARG("--round-robin",
set_rr, &pool_strategy,
"Change multipool strategy from failover to round robin on failure"),
-#ifdef USE_BITFORCE
+#if defined(USE_BITFORCE) || (defined(USE_ICARUS) && defined(WIN32))
OPT_WITH_ARG("--scan-serial|-S",
add_serial, NULL, NULL,
"Serial port to probe for BitForce device"),
@@ -962,6 +962,9 @@ static char *opt_verusage_and_exit(const char *extra)
#ifdef USE_BITFORCE
"bitforce "
#endif
+#ifdef USE_ICARUS
+ "icarus "
+#endif
"mining support.\n"
, packagename);
printf("%s", opt_usage(opt_argv0, extra));
@@ -4117,6 +4120,10 @@ struct device_api cpu_api = {
extern struct device_api bitforce_api;
#endif
+#ifdef USE_ICARUS
+extern struct device_api icarus_api;
+#endif
+
static int cgminer_id_count = 0;
@@ -4271,6 +4278,10 @@ int main (int argc, char *argv[])
bitforce_api.api_detect();
#endif
+#ifdef USE_ICARUS
+ icarus_api.api_detect();
+#endif
+
#ifdef WANT_CPUMINE
cpu_api.api_detect();
#endif
--
1.7.5.4

View File

@ -0,0 +1,27 @@
From aed89bc1d85f6d4dc0834f850730894571ed9e71 Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Tue, 14 Feb 2012 00:02:06 +0800
Subject: [PATCH 4/6] update the message fit both bitforce and Icarus
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
cgminer.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/cgminer.c b/cgminer.c
index cea6f59..bfb8399 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -780,7 +780,7 @@ static struct opt_table opt_config_table[] = {
#if defined(USE_BITFORCE) || (defined(USE_ICARUS) && defined(WIN32))
OPT_WITH_ARG("--scan-serial|-S",
add_serial, NULL, NULL,
- "Serial port to probe for BitForce device"),
+ "Serial port to probe for FPGA Mining device"),
#endif
OPT_WITH_ARG("--scan-time|-s",
set_int_0_to_9999, opt_show_intval, &opt_scantime,
--
1.7.5.4

View File

@ -0,0 +1,38 @@
From 5ae847013d58990a1686d2875b768945c65a2f6e Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Tue, 14 Feb 2012 00:01:20 +0800
Subject: [PATCH 5/6] update README for Icarus
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
README | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/README b/README
index f3c0a26..0ef1b9f 100644
--- a/README
+++ b/README
@@ -50,6 +50,7 @@ CGMiner specific configuration options:
--disable-opencl Override detection and disable building with opencl
--disable-adl Override detection and disable building with adl
--enable-bitforce Compile support for BitForce FPGAs(default disabled)
+ --enable-icarus Compile support for Icarus Board(default disabled)
Basic *nix build instructions:
To build with GPU mining support:
@@ -198,6 +199,11 @@ BitForce only options:
--scan-serial|-S <arg> Serial port to probe for BitForce device
+Icarus only options(only under Windows system):
+
+--scan-serial|-S <arg> Serial port to probe for Icarus device
+
+
CPU only options:
--algo|-a <arg> Specify sha256 implementation for CPU mining:
--
1.7.5.4

View File

@ -0,0 +1,41 @@
From 867a939c012ffcdbff018625c76571a588642662 Mon Sep 17 00:00:00 2001
From: Xiangfu <xiangfu@openmobilefree.net>
Date: Wed, 15 Feb 2012 12:43:25 +0800
Subject: [PATCH 6/6] add shortcut to description for easy grep
Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
---
README | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/README b/README
index 0ef1b9f..174882a 100644
--- a/README
+++ b/README
@@ -320,14 +320,14 @@ The output line shows the following:
(5s):1713.6 (avg):1707.8 Mh/s | Q:301 A:729 R:8 HW:0 E:242% U:22.53/m
Each column is as follows:
-A 5 second exponentially decaying average hash rate
-An all time average hash rate
-The number of requested (Queued) work items from the pools
-The number of Accepted shares
-The number of Rejected shares
-The number of HardWare errors
-The Efficiency defined as number of shares returned / work item
-The Utility defined as the number of shares / minute
+5s: A 5 second exponentially decaying average hash rate
+avg: An all time average hash rate
+Q: The number of requested (Queued) work items from the pools
+A: The number of Accepted shares
+R: The number of Rejected shares
+HW: The number of HardWare errors
+E: The Efficiency defined as number of shares returned / work item
+U: The Utility defined as the number of shares / minute
GPU 1: 73.5C 2551RPM | 427.3/443.0Mh/s | A:8 R:0 HW:0 U:4.39/m
--
1.7.5.4

View File

@ -0,0 +1,13 @@
diff --git a/icarus.c b/icarus.c
index 141d639..2e89a86 100644
--- a/icarus.c
+++ b/icarus.c
@@ -251,7 +251,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, uint64_
work->blk.nonce = 0xffffffff;
memcpy((char *)&nonce, pdevbuf, sizeof(pdevbuf));
-#ifndef __BIG_ENDIAN__
+#if !defined (__BIG_ENDIAN__) && !defined(MIPSEB)
nonce = swab32(nonce);
#endif
submit_nonce(thr, work, nonce);