Date:2012-02-15 05:58:39 (9 years 10 days ago)
Author:Xiangfu Liu
Commit:622aa44c2c240f72463fefd693a29b6a0e3cd49c
Message:cgminer: add Icarus support

Files: cgminer/Makefile (2 diffs)
cgminer/patches/0001-add-Icarus-support-to-autoreconf-system.patch (1 diff)
cgminer/patches/0002-add-icarus.c-base-on-bitforce.c.patch (1 diff)
cgminer/patches/0003-add-icarus-to-cgminer.c.patch (1 diff)
cgminer/patches/0004-update-the-message-fit-both-bitforce-and-Icarus.patch (1 diff)
cgminer/patches/0005-update-README-for-Icarus.patch (1 diff)
cgminer/patches/0006-add-shortcut-to-description-for-easy-grep.patch (1 diff)
cgminer/patches/0007-add-MIPSED-to-icarus-for-BIG_ENDIAN.patch (1 diff)

Change Details

cgminer/Makefile
99include $(TOPDIR)/rules.mk
1010
1111PKG_NAME:=cgminer
12PKG_VERSION:=20120210
13PKG_REV:=6e3ad7ad250b5d63be2472d9dc56325d143d7ace
12PKG_VERSION:=20120215
13PKG_REV:=9a0e4f8facababf54cf6dcac7bf93a0e6099047e
1414PKG_RELEASE:=1
1515PKG_INSTALL:=1
1616
...... 
3737define Package/cgminer/description
3838endef
3939
40CONFIGURE_ARGS += --enable-bitforce --disable-opencl --disable-adl --enable-cpumining
40CONFIGURE_ARGS += --disable-opencl --disable-adl --enable-icarus
4141TARGET_CFLAGS +=
4242TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib
4343
cgminer/patches/0001-add-Icarus-support-to-autoreconf-system.patch
1From 75e27968a62025d1ac3655275e8f52b879092255 Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Mon, 13 Feb 2012 16:04:13 +0800
4Subject: [PATCH 1/6] add Icarus support to autoreconf system
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 Makefile.am | 3 +++
10 configure.ac | 21 +++++++++++++++++++--
11 2 files changed, 22 insertions(+), 2 deletions(-)
12
13diff --git a/Makefile.am b/Makefile.am
14index 4249d51..5262d52 100644
15--- a/Makefile.am
16@@ -70,3 +70,6 @@ if HAS_BITFORCE
17 cgminer_SOURCES += bitforce.c
18 endif
19
20+if HAS_ICARUS
21+cgminer_SOURCES += icarus.c
22+endif
23diff --git a/configure.ac b/configure.ac
24index ee665aa..a931867 100644
25--- a/configure.ac
26@@ -196,6 +196,17 @@ if test "x$bitforce" = xyes; then
27 fi
28 AM_CONDITIONAL([HAS_BITFORCE], [test x$bitforce = xyes])
29
30+icarus="no"
31+
32+AC_ARG_ENABLE([icarus],
33+ [AC_HELP_STRING([--enable-icarus],[Compile support for Icarus (default disabled)])],
34+ [icarus=$enableval]
35+ )
36+if test "x$icarus" = xyes; then
37+ AC_DEFINE([USE_ICARUS], [1], [Defined to 1 if Icarus support is wanted])
38+fi
39+AM_CONDITIONAL([HAS_ICARUS], [test x$icarus = xyes])
40+
41 AC_SEARCH_LIBS(addstr, ncurses pdcurses, ,
42         AC_MSG_ERROR([Could not find curses library - please install libncurses-dev or pdcurses-dev]))
43
44@@ -338,13 +349,13 @@ if test "x$opencl" != xno; then
45         echo " OpenCL...............: FOUND. GPU mining support enabled"
46     else
47         echo " OpenCL...............: NOT FOUND. GPU mining support DISABLED"
48- if test "x$cpumining$bitforce" = xnono; then
49+ if test "x$cpumining$bitforce$icarus" = xnonono; then
50             AC_MSG_ERROR([No mining configured in])
51         fi
52     fi
53 else
54     echo " OpenCL...............: Detection overrided. GPU mining support DISABLED"
55- if test "x$cpumining$bitforce" = xnono; then
56+ if test "x$cpumining$bitforce$icarus" = xnonono; then
57         AC_MSG_ERROR([No mining configured in])
58     fi
59 fi
60@@ -366,6 +377,12 @@ else
61     echo " BitForce.FPGAs.......: Disabled"
62 fi
63
64+if test "x$icarus" = xyes; then
65+ echo " Icarus.FPGAs.........: Enabled"
66+else
67+ echo " Icarus.FPGAs.........: Disabled"
68+fi
69+
70 echo
71 if test "x$cpumining" = xyes; then
72     echo " CPU Mining...........: Enabled"
73--
741.7.5.4
75
cgminer/patches/0002-add-icarus.c-base-on-bitforce.c.patch
1From 80451867b6eeeb79e02d639171999d99069bb27f Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Mon, 13 Feb 2012 16:04:34 +0800
4Subject: [PATCH 2/6] add icarus.c, base on bitforce.c
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 icarus.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 1 files changed, 268 insertions(+), 0 deletions(-)
11 create mode 100644 icarus.c
12
13diff --git a/icarus.c b/icarus.c
14new file mode 100644
15index 0000000..141d639
16--- /dev/null
17@@ -0,0 +1,268 @@
18+/*
19+ * Copyright 2012 Luke Dashjr
20+ * Copyright 2012 Xiangfu <xiangfu@openmobilefree.com>
21+ *
22+ * This program is free software; you can redistribute it and/or modify it
23+ * under the terms of the GNU General Public License as published by the Free
24+ * Software Foundation; either version 2 of the License, or (at your option)
25+ * any later version. See COPYING for more details.
26+ */
27+
28+#include <limits.h>
29+#include <pthread.h>
30+#include <stdio.h>
31+#include <sys/time.h>
32+#include <sys/types.h>
33+#include <dirent.h>
34+#include <unistd.h>
35+#ifndef WIN32
36+ #include <termios.h>
37+ #include <sys/stat.h>
38+ #include <fcntl.h>
39+ #ifndef O_CLOEXEC
40+ #define O_CLOEXEC 0
41+ #endif
42+#else
43+ #include <windows.h>
44+ #include <io.h>
45+#endif
46+
47+#include "elist.h"
48+#include "miner.h"
49+
50+#define ICARUS_READ_FAULT_COUNT (8)
51+
52+struct device_api icarus_api;
53+
54+static void rev(char *s, ssize_t l)
55+{
56+ int i, j;
57+ char t;
58+
59+ for(i = 0, j = l - 1; i < j; i++, j--) {
60+ t = s[i];
61+ s[i] = s[j];
62+ s[j] = t;
63+ }
64+}
65+
66+static int icarus_open(const char *devpath)
67+{
68+#ifndef WIN32
69+ struct termios my_termios;
70+
71+ int serialfd = open(devpath, O_RDWR | O_CLOEXEC | O_NOCTTY);
72+
73+ if(serialfd == -1)
74+ return -1;
75+
76+ tcgetattr(serialfd, &my_termios);
77+ my_termios.c_cflag = B115200;
78+ my_termios.c_cflag |= CS8;
79+ my_termios.c_cflag |= CREAD;
80+ my_termios.c_cflag |= CLOCAL;
81+ my_termios.c_cflag &= ~(CSIZE | PARENB);
82+
83+ my_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
84+ my_termios.c_oflag &= ~OPOST;
85+ my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
86+ my_termios.c_cc[VTIME] = 10; /* block 1 second */
87+ my_termios.c_cc[VMIN] = 0;
88+ tcsetattr(serialfd, TCSANOW, &my_termios);
89+
90+ tcflush(serialfd, TCOFLUSH);
91+ tcflush(serialfd, TCIFLUSH);
92+
93+ return serialfd;
94+#else
95+ HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
96+ if (unlikely(hSerial == INVALID_HANDLE_VALUE))
97+ return -1;
98+ return _open_osfhandle((LONG)hSerial, 0);
99+#endif
100+}
101+
102+static void icarus_gets(char *buf, size_t bufLen, int fd)
103+{
104+ int ret = 0, count = 0;
105+
106+ while (bufLen) {
107+ ret = read(fd, buf, 1);
108+ if(ret == 1) {
109+ bufLen--;
110+ buf++;
111+ }
112+ count++;
113+ if(count == ICARUS_READ_FAULT_COUNT)
114+ break;
115+ }
116+}
117+
118+static void icarus_write(int fd, const void *buf, size_t bufLen)
119+{
120+ ssize_t ret = write(fd, buf, bufLen);
121+ if (unlikely(ret != bufLen))
122+ quit(1, "icarus_write failed");
123+}
124+
125+#define icarus_close(fd) close(fd)
126+
127+static bool icarus_detect_one(const char *devpath)
128+{
129+ static int i = 0;
130+
131+ const char ob[128] =
132+"ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8";
133+ const char nonce[] = "8e0b31c5";
134+ char ob_bin[64];
135+ char pdevbuf[4];
136+ int fdDev;
137+ char *nonce_hex;
138+
139+ if (total_devices == MAX_DEVICES)
140+ return false;
141+
142+ fdDev = icarus_open(devpath);
143+ if (unlikely(fdDev == -1)) {
144+ applog(LOG_ERR, "Icarus Detect: Failed to open %s", devpath);
145+ return false;
146+ }
147+
148+ hex2bin(ob_bin, ob, sizeof(ob_bin));
149+ icarus_write(fdDev, ob_bin, sizeof(ob_bin));
150+
151+ memset(pdevbuf, 0, sizeof(pdevbuf));
152+ icarus_gets(pdevbuf, sizeof(pdevbuf), fdDev);
153+
154+ icarus_close(fdDev);
155+
156+ nonce_hex = bin2hex(pdevbuf, sizeof(pdevbuf));
157+ if(strncmp(nonce_hex, nonce, 8)) {
158+ applog(LOG_DEBUG, "Icarus Detect: Test failed at %s : get %s, should: %s",
159+ devpath, nonce_hex, nonce);
160+ return false;
161+ }
162+ free(nonce_hex);
163+
164+ /* We have a real Icarus! */
165+ struct cgpu_info *icarus;
166+ icarus = calloc(1, sizeof(*icarus));
167+ devices[total_devices++] = icarus;
168+ icarus->api = &icarus_api;
169+ icarus->device_id = i++;
170+ icarus->device_path = strdup(devpath);
171+ icarus->enabled = true;
172+ icarus->threads = 1;
173+
174+ return true;
175+}
176+
177+static void icarus_detect_auto()
178+{
179+#ifndef WIN32
180+ DIR *D;
181+ struct dirent *de;
182+ const char udevdir[] = "/dev/serial/by-id";
183+ char devpath[sizeof(udevdir) + 1 + NAME_MAX];
184+ char *devfile = devpath + sizeof(udevdir);
185+
186+ D = opendir(udevdir);
187+ if (!D)
188+ return;
189+ memcpy(devpath, udevdir, sizeof(udevdir) - 1);
190+ devpath[sizeof(udevdir) - 1] = '/';
191+ while ( (de = readdir(D)) ) {
192+ /* Icarus using a PL2303 usb-serial chip */
193+ if (!strstr(de->d_name, "Prolific_Technology_Inc"))
194+ continue;
195+ strcpy(devfile, de->d_name);
196+ icarus_detect_one(devpath);
197+ }
198+ closedir(D);
199+#endif
200+}
201+
202+static void icarus_detect()
203+{
204+ struct string_elist *iter, *tmp;
205+
206+ list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
207+ if (icarus_detect_one(iter->string))
208+ string_elist_del(iter);
209+ }
210+
211+ icarus_detect_auto();
212+}
213+
214+static pthread_mutex_t hash_lock;
215+
216+static bool icarus_thread_prepare(struct thr_info *thr)
217+{
218+ struct cgpu_info *icarus = thr->cgpu;
219+
220+ struct timeval now;
221+
222+ int fdDev = icarus_open(icarus->device_path);
223+ if (unlikely(-1 == fdDev)) {
224+ applog(LOG_ERR, "Failed to open Icarus on %s", icarus->device_path);
225+ return false;
226+ }
227+
228+ icarus->device_fd = fdDev;
229+
230+ applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path);
231+ gettimeofday(&now, NULL);
232+ get_datestamp(icarus->init, &now);
233+
234+ mutex_init(&hash_lock);
235+ return true;
236+}
237+
238+static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, uint64_t max_nonce)
239+{
240+ struct cgpu_info *icarus = thr->cgpu;
241+ int fdDev = icarus->device_fd;
242+
243+ char pdevbuf[4];
244+ unsigned char ob[64];
245+ uint32_t nonce;
246+ char *ob_hex, *nonce_hex;
247+
248+ mutex_lock(&hash_lock);
249+
250+ memcpy(ob, work->midstate, 32);
251+ memcpy(ob + 32, work->data + 64, 32);
252+ rev(ob, 32);
253+ rev(ob + 32, 32);
254+
255+ icarus_write(fdDev, ob, sizeof(ob));
256+
257+ ob_hex = bin2hex(ob, sizeof(ob));
258+ applog(LOG_DEBUG, "Icarus Send: %s", ob_hex);
259+ free(ob_hex);
260+
261+ memset(pdevbuf, 0, sizeof(pdevbuf));
262+ icarus_gets(pdevbuf, sizeof(pdevbuf), fdDev);
263+
264+ nonce_hex = bin2hex(pdevbuf, sizeof(pdevbuf));
265+ applog(LOG_DEBUG, "Icarus Return: %s", nonce_hex);
266+ free(nonce_hex);
267+
268+ work->blk.nonce = 0xffffffff;
269+
270+ memcpy((char *)&nonce, pdevbuf, sizeof(pdevbuf));
271+#ifndef __BIG_ENDIAN__
272+ nonce = swab32(nonce);
273+#endif
274+ submit_nonce(thr, work, nonce);
275+
276+ mutex_unlock(&hash_lock);
277+ return 0xffffffff;
278+}
279+
280+struct device_api icarus_api = {
281+ .name = "Icarus",
282+ .api_detect = icarus_detect,
283+ .thread_prepare = icarus_thread_prepare,
284+ .scanhash = icarus_scanhash,
285+};
286--
2871.7.5.4
288
cgminer/patches/0003-add-icarus-to-cgminer.c.patch
1From fdcf21974b9b9d1b2d92ccad6b16eadf023515fc Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Mon, 13 Feb 2012 16:09:45 +0800
4Subject: [PATCH 3/6] add icarus to cgminer.c
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 cgminer.c | 17 ++++++++++++++---
10 1 files changed, 14 insertions(+), 3 deletions(-)
11
12diff --git a/cgminer.c b/cgminer.c
13index 596a21a..cea6f59 100644
14--- a/cgminer.c
15@@ -400,7 +400,7 @@ static char *set_int_1_to_10(const char *arg, int *i)
16     return set_int_range(arg, i, 1, 10);
17 }
18
19-#ifdef USE_BITFORCE
20+#if defined(USE_BITFORCE) || defined(USE_ICARUS)
21 static char *add_serial(char *arg)
22 {
23     string_elist_add(arg, &scan_devices);
24@@ -662,7 +662,7 @@ static struct opt_table opt_config_table[] = {
25     OPT_WITHOUT_ARG("--disable-gpu|-G",
26             opt_set_bool, &opt_nogpu,
27             "Disable GPU mining even if suitable devices exist"),
28-#if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_BITFORCE))
29+#if defined(WANT_CPUMINE) && (defined(HAVE_OPENCL) || defined(USE_BITFORCE) || defined(USE_ICARUS))
30     OPT_WITHOUT_ARG("--enable-cpu|-C",
31             opt_set_bool, &opt_usecpu,
32             "Enable CPU mining with other mining (default: no CPU mining if other devices exist)"),
33@@ -777,7 +777,7 @@ static struct opt_table opt_config_table[] = {
34     OPT_WITHOUT_ARG("--round-robin",
35              set_rr, &pool_strategy,
36              "Change multipool strategy from failover to round robin on failure"),
37-#ifdef USE_BITFORCE
38+#if defined(USE_BITFORCE) || (defined(USE_ICARUS) && defined(WIN32))
39     OPT_WITH_ARG("--scan-serial|-S",
40              add_serial, NULL, NULL,
41              "Serial port to probe for BitForce device"),
42@@ -962,6 +962,9 @@ static char *opt_verusage_and_exit(const char *extra)
43 #ifdef USE_BITFORCE
44         "bitforce "
45 #endif
46+#ifdef USE_ICARUS
47+ "icarus "
48+#endif
49         "mining support.\n"
50         , packagename);
51     printf("%s", opt_usage(opt_argv0, extra));
52@@ -4117,6 +4120,10 @@ struct device_api cpu_api = {
53 extern struct device_api bitforce_api;
54 #endif
55
56+#ifdef USE_ICARUS
57+extern struct device_api icarus_api;
58+#endif
59+
60
61 static int cgminer_id_count = 0;
62
63@@ -4271,6 +4278,10 @@ int main (int argc, char *argv[])
64     bitforce_api.api_detect();
65 #endif
66
67+#ifdef USE_ICARUS
68+ icarus_api.api_detect();
69+#endif
70+
71 #ifdef WANT_CPUMINE
72     cpu_api.api_detect();
73 #endif
74--
751.7.5.4
76
cgminer/patches/0004-update-the-message-fit-both-bitforce-and-Icarus.patch
1From aed89bc1d85f6d4dc0834f850730894571ed9e71 Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Tue, 14 Feb 2012 00:02:06 +0800
4Subject: [PATCH 4/6] update the message fit both bitforce and Icarus
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 cgminer.c | 2 +-
10 1 files changed, 1 insertions(+), 1 deletions(-)
11
12diff --git a/cgminer.c b/cgminer.c
13index cea6f59..bfb8399 100644
14--- a/cgminer.c
15@@ -780,7 +780,7 @@ static struct opt_table opt_config_table[] = {
16 #if defined(USE_BITFORCE) || (defined(USE_ICARUS) && defined(WIN32))
17     OPT_WITH_ARG("--scan-serial|-S",
18              add_serial, NULL, NULL,
19- "Serial port to probe for BitForce device"),
20+ "Serial port to probe for FPGA Mining device"),
21 #endif
22     OPT_WITH_ARG("--scan-time|-s",
23              set_int_0_to_9999, opt_show_intval, &opt_scantime,
24--
251.7.5.4
26
cgminer/patches/0005-update-README-for-Icarus.patch
1From 5ae847013d58990a1686d2875b768945c65a2f6e Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Tue, 14 Feb 2012 00:01:20 +0800
4Subject: [PATCH 5/6] update README for Icarus
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 README | 6 ++++++
10 1 files changed, 6 insertions(+), 0 deletions(-)
11
12diff --git a/README b/README
13index f3c0a26..0ef1b9f 100644
14--- a/README
15@@ -50,6 +50,7 @@ CGMiner specific configuration options:
16     --disable-opencl Override detection and disable building with opencl
17     --disable-adl Override detection and disable building with adl
18     --enable-bitforce Compile support for BitForce FPGAs(default disabled)
19+ --enable-icarus Compile support for Icarus Board(default disabled)
20
21 Basic *nix build instructions:
22     To build with GPU mining support:
23@@ -198,6 +199,11 @@ BitForce only options:
24 --scan-serial|-S <arg> Serial port to probe for BitForce device
25
26
27+Icarus only options(only under Windows system):
28+
29+--scan-serial|-S <arg> Serial port to probe for Icarus device
30+
31+
32 CPU only options:
33
34 --algo|-a <arg> Specify sha256 implementation for CPU mining:
35--
361.7.5.4
37
cgminer/patches/0006-add-shortcut-to-description-for-easy-grep.patch
1From 867a939c012ffcdbff018625c76571a588642662 Mon Sep 17 00:00:00 2001
2From: Xiangfu <xiangfu@openmobilefree.net>
3Date: Wed, 15 Feb 2012 12:43:25 +0800
4Subject: [PATCH 6/6] add shortcut to description for easy grep
5
6
7Signed-off-by: Xiangfu <xiangfu@openmobilefree.net>
8---
9 README | 16 ++++++++--------
10 1 files changed, 8 insertions(+), 8 deletions(-)
11
12diff --git a/README b/README
13index 0ef1b9f..174882a 100644
14--- a/README
15@@ -320,14 +320,14 @@ The output line shows the following:
16 (5s):1713.6 (avg):1707.8 Mh/s | Q:301 A:729 R:8 HW:0 E:242% U:22.53/m
17
18 Each column is as follows:
19-A 5 second exponentially decaying average hash rate
20-An all time average hash rate
21-The number of requested (Queued) work items from the pools
22-The number of Accepted shares
23-The number of Rejected shares
24-The number of HardWare errors
25-The Efficiency defined as number of shares returned / work item
26-The Utility defined as the number of shares / minute
27+5s: A 5 second exponentially decaying average hash rate
28+avg: An all time average hash rate
29+Q: The number of requested (Queued) work items from the pools
30+A: The number of Accepted shares
31+R: The number of Rejected shares
32+HW: The number of HardWare errors
33+E: The Efficiency defined as number of shares returned / work item
34+U: The Utility defined as the number of shares / minute
35
36  GPU 1: 73.5C 2551RPM | 427.3/443.0Mh/s | A:8 R:0 HW:0 U:4.39/m
37
38--
391.7.5.4
40
cgminer/patches/0007-add-MIPSED-to-icarus-for-BIG_ENDIAN.patch
1diff --git a/icarus.c b/icarus.c
2index 141d639..2e89a86 100644
3--- a/icarus.c
4@@ -251,7 +251,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, uint64_
5     work->blk.nonce = 0xffffffff;
6
7     memcpy((char *)&nonce, pdevbuf, sizeof(pdevbuf));
8-#ifndef __BIG_ENDIAN__
9+#if !defined (__BIG_ENDIAN__) && !defined(MIPSEB)
10     nonce = swab32(nonce);
11 #endif
12     submit_nonce(thr, work, nonce);

Archive Download the corresponding diff file



interactive