Export reused components of bitfury management into a libbitfury and use for bab and bitfury drivers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
diff --git a/Makefile.am b/Makefile.am
index 63aacfd..11ff5bc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,6 +51,10 @@ if WANT_USBUTILS
cgminer_SOURCES += usbutils.c usbutils.h
endif
+if WANT_LIBBITFURY
+cgminer_SOURCES += libbitfury.c libbitfury.h
+endif
+
# Device drivers
if HAS_AVALON
cgminer_SOURCES += driver-avalon.c driver-avalon.h
diff --git a/configure.ac b/configure.ac
index 862d940..e0f6ffa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -288,8 +288,15 @@ else
want_usbutils=false
fi
+if test x$bab$bitfury != xnono; then
+ want_libbitfury = true
+else
+ want_libbitfury = false
+fi
+
AM_CONDITIONAL([NEED_FPGAUTILS], [test x$modminer != xno])
AM_CONDITIONAL([WANT_USBUTILS], [test x$want_usbutils != xfalse])
+AM_CONDITIONAL([WANT_LIBBITFURY], [test x$want_libbitfury != xfalse])
AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue])
diff --git a/driver-bab.c b/driver-bab.c
index 7db3df1..d40bf47 100644
--- a/driver-bab.c
+++ b/driver-bab.c
@@ -15,6 +15,7 @@
#include "compat.h"
#include "miner.h"
#include "sha2.h"
+#include "libbitfury.h"
/*
* Tested on RPi running both Raspbian and Arch
@@ -1323,42 +1324,6 @@ static void bab_flush_work(struct cgpu_info *babcgpu)
mutex_unlock(&(babinfo->did_lock));
}
-static void ms3steps(uint32_t *p)
-{
- uint32_t a, b, c, d, e, f, g, h, new_e, new_a;
- int i;
-
- a = p[0];
- b = p[1];
- c = p[2];
- d = p[3];
- e = p[4];
- f = p[5];
- g = p[6];
- h = p[7];
- for (i = 0; i < 3; i++) {
- new_e = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) + d;
- new_a = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) +
- SHA256_F1(a) + MAJ(a,b,c);
- d = c;
- c = b;
- b = a;
- a = new_a;
- h = g;
- g = f;
- f = e;
- e = new_e;
- }
- p[15] = a;
- p[14] = b;
- p[13] = c;
- p[12] = d;
- p[11] = e;
- p[10] = f;
- p[9] = g;
- p[8] = h;
-}
-
#define DATA_MERKLE7 16
#define DATA_NTIME 17
#define DATA_BITS 18
@@ -1369,31 +1334,6 @@ static void ms3steps(uint32_t *p)
#define WORK_BITS (18*4)
#define WORK_NONCE (19*4)
-static uint32_t decnonce(uint32_t in)
-{
- uint32_t out;
-
- /* First part load */
- out = (in & 0xFF) << 24;
- in >>= 8;
-
- /* Byte reversal */
- in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
- in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
- in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
-
- out |= (in >> 2) & 0x3FFFFF;
-
- /* Extraction */
- if (in & 1)
- out |= (1 << 23);
- if (in & 2)
- out |= (1 << 22);
-
- out -= 0x800004;
- return out;
-}
-
/*
* Find the matching work item by checking the nonce against each work
* item for the chip
diff --git a/driver-bitfury.c b/driver-bitfury.c
index bbfc343..b59b082 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -13,6 +13,7 @@
#include "driver-bitfury.h"
#include "sha2.h"
#include "mcp2210.h"
+#include "libbitfury.h"
int opt_bxf_temp_target = BXF_TEMP_TARGET / 10;
@@ -691,28 +692,6 @@ static bool bitfury_prepare(struct thr_info *thr)
}
}
-static uint32_t decnonce(uint32_t in)
-{
- uint32_t out;
-
- /* First part load */
- out = (in & 0xFF) << 24; in >>= 8;
-
- /* Byte reversal */
- in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
- in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
- in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
-
- out |= (in >> 2)&0x3FFFFF;
-
- /* Extraction */
- if (in & 1) out |= (1 << 23);
- if (in & 2) out |= (1 << 22);
-
- out -= 0x800004;
- return out;
-}
-
#define BT_OFFSETS 3
const uint32_t bf_offsets[] = {-0x800000, 0, -0x400000};
diff --git a/libbitfury.c b/libbitfury.c
new file mode 100644
index 0000000..aa066b1
--- /dev/null
+++ b/libbitfury.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2014 Con Kolivas
+ * Copyright 2013 Andrew Smith
+ * Copyright 2013 bitfury
+ *
+ * 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 3 of the License, or (at your option)
+ * any later version. See COPYING for more details.
+ */
+
+#include "sha2.h"
+void ms3steps(uint32_t *p)
+{
+ uint32_t a, b, c, d, e, f, g, h, new_e, new_a;
+ int i;
+
+ a = p[0];
+ b = p[1];
+ c = p[2];
+ d = p[3];
+ e = p[4];
+ f = p[5];
+ g = p[6];
+ h = p[7];
+ for (i = 0; i < 3; i++) {
+ new_e = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) + d;
+ new_a = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) +
+ SHA256_F1(a) + MAJ(a,b,c);
+ d = c;
+ c = b;
+ b = a;
+ a = new_a;
+ h = g;
+ g = f;
+ f = e;
+ e = new_e;
+ }
+ p[15] = a;
+ p[14] = b;
+ p[13] = c;
+ p[12] = d;
+ p[11] = e;
+ p[10] = f;
+ p[9] = g;
+ p[8] = h;
+}
+
+uint32_t decnonce(uint32_t in)
+{
+ uint32_t out;
+
+ /* First part load */
+ out = (in & 0xFF) << 24;
+ in >>= 8;
+
+ /* Byte reversal */
+ in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
+ in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
+ in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
+
+ out |= (in >> 2) & 0x3FFFFF;
+
+ /* Extraction */
+ if (in & 1)
+ out |= (1 << 23);
+ if (in & 2)
+ out |= (1 << 22);
+
+ out -= 0x800004;
+ return out;
+}
diff --git a/libbitfury.h b/libbitfury.h
new file mode 100644
index 0000000..e4cef89
--- /dev/null
+++ b/libbitfury.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2014 Con Kolivas
+ *
+ * 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 3 of the License, or (at your option)
+ * any later version. See COPYING for more details.
+ */
+
+#ifndef LIBBITFURY_H
+#define LIBBITFURY_H
+void ms3steps(uint32_t *p);
+uint32_t decnonce(uint32_t in);
+
+#endif /* LIBBITFURY_H */