cgminer/patches/0001-add-Icarus-support-to-autoreconf-system.patch |
| 1 | From 75e27968a62025d1ac3655275e8f52b879092255 Mon Sep 17 00:00:00 2001 |
| 2 | From: Xiangfu <xiangfu@openmobilefree.net> |
| 3 | Date: Mon, 13 Feb 2012 16:04:13 +0800 |
| 4 | Subject: [PATCH 1/6] add Icarus support to autoreconf system |
| 5 | |
| 6 | |
| 7 | Signed-off-by: Xiangfu <xiangfu@openmobilefree.net> |
| 8 | --- |
| 9 | Makefile.am | 3 +++ |
| 10 | configure.ac | 21 +++++++++++++++++++-- |
| 11 | 2 files changed, 22 insertions(+), 2 deletions(-) |
| 12 | |
| 13 | diff --git a/Makefile.am b/Makefile.am |
| 14 | index 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 |
| 23 | diff --git a/configure.ac b/configure.ac |
| 24 | index 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 | -- |
| 74 | 1.7.5.4 |
| 75 | |
cgminer/patches/0002-add-icarus.c-base-on-bitforce.c.patch |
| 1 | From 80451867b6eeeb79e02d639171999d99069bb27f Mon Sep 17 00:00:00 2001 |
| 2 | From: Xiangfu <xiangfu@openmobilefree.net> |
| 3 | Date: Mon, 13 Feb 2012 16:04:34 +0800 |
| 4 | Subject: [PATCH 2/6] add icarus.c, base on bitforce.c |
| 5 | |
| 6 | |
| 7 | Signed-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 | |
| 13 | diff --git a/icarus.c b/icarus.c |
| 14 | new file mode 100644 |
| 15 | index 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 | -- |
| 287 | 1.7.5.4 |
| 288 | |
cgminer/patches/0003-add-icarus-to-cgminer.c.patch |
| 1 | From fdcf21974b9b9d1b2d92ccad6b16eadf023515fc Mon Sep 17 00:00:00 2001 |
| 2 | From: Xiangfu <xiangfu@openmobilefree.net> |
| 3 | Date: Mon, 13 Feb 2012 16:09:45 +0800 |
| 4 | Subject: [PATCH 3/6] add icarus to cgminer.c |
| 5 | |
| 6 | |
| 7 | Signed-off-by: Xiangfu <xiangfu@openmobilefree.net> |
| 8 | --- |
| 9 | cgminer.c | 17 ++++++++++++++--- |
| 10 | 1 files changed, 14 insertions(+), 3 deletions(-) |
| 11 | |
| 12 | diff --git a/cgminer.c b/cgminer.c |
| 13 | index 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 | -- |
| 75 | 1.7.5.4 |
| 76 | |
cgminer/patches/0006-add-shortcut-to-description-for-easy-grep.patch |
| 1 | From 867a939c012ffcdbff018625c76571a588642662 Mon Sep 17 00:00:00 2001 |
| 2 | From: Xiangfu <xiangfu@openmobilefree.net> |
| 3 | Date: Wed, 15 Feb 2012 12:43:25 +0800 |
| 4 | Subject: [PATCH 6/6] add shortcut to description for easy grep |
| 5 | |
| 6 | |
| 7 | Signed-off-by: Xiangfu <xiangfu@openmobilefree.net> |
| 8 | --- |
| 9 | README | 16 ++++++++-------- |
| 10 | 1 files changed, 8 insertions(+), 8 deletions(-) |
| 11 | |
| 12 | diff --git a/README b/README |
| 13 | index 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 | -- |
| 39 | 1.7.5.4 |
| 40 | |