├── .gitignore ├── .gitmodules ├── .travis.deps ├── .travis.script ├── .travis.yml ├── 70-bfgminer.rules.in ├── ADL ├── adl_defines.h ├── adl_sdk.h └── adl_structures.h ├── AUTHORS ├── CL ├── cl.h └── cl_platform.h ├── COPYING ├── ChangeLog ├── HACKING ├── LICENSE ├── Makefile.am ├── NEWS ├── README ├── README.ASIC ├── README.CPU ├── README.FPGA ├── README.GPU ├── README.OpenWrt ├── README.RPC ├── README.scrypt ├── adl.c ├── adl.h ├── adl_functions.h ├── api-example.c ├── api-example.php ├── api-example.py ├── api-example.rb ├── api.c ├── arg-nonnull.h ├── autogen.sh ├── avalonhost-raminst ├── binloader.c ├── binloader.h ├── bitstreams └── .gitignore ├── c++defs.h ├── ccan.bfg └── Makefile.am ├── compat.h ├── configure.ac ├── debian ├── bfgminer.docs ├── changelog ├── compat ├── control ├── copyright ├── rules └── source │ └── format ├── deviceapi.c ├── deviceapi.h ├── driver-aan.c ├── driver-aan.h ├── driver-alchemist.c ├── driver-antminer.c ├── driver-avalon.c ├── driver-avalon.h ├── driver-avalonmm.c ├── driver-bfsb.c ├── driver-bfx.c ├── driver-bifury.c ├── driver-bigpic.c ├── driver-bigpic.h ├── driver-bitforce.c ├── driver-bitfury.c ├── driver-bitfury.h ├── driver-bitmain.c ├── driver-bitmain.h ├── driver-cairnsmore.c ├── driver-cointerra.c ├── driver-cointerra.h ├── driver-cpu.c ├── driver-cpu.h ├── driver-drillbit.c ├── driver-dualminer.c ├── driver-erupter.c ├── driver-getwork.c ├── driver-gridseed.c ├── driver-hashbuster.c ├── driver-hashbusteravalon.c ├── driver-hashbusterusb.c ├── driver-hashfast.c ├── driver-icarus.c ├── driver-icarus.h ├── driver-jingtian.c ├── driver-klondike.c ├── driver-klondike.h ├── driver-knc.c ├── driver-kncasic.c ├── driver-littlefury.c ├── driver-metabank.c ├── driver-minergate.c ├── driver-minion.c ├── driver-modminer.c ├── driver-nanofury.c ├── driver-opencl.c ├── driver-opencl.h ├── driver-proxy.c ├── driver-proxy.h ├── driver-rockminer.c ├── driver-stratum.c ├── driver-titan.c ├── driver-twinfury.c ├── driver-twinfury.h ├── driver-x6500.c ├── driver-zeusminer.c ├── driver-ztex.c ├── dynclock.c ├── dynclock.h ├── example.conf ├── findnonce.c ├── findnonce.h ├── gc3355.c ├── gc3355.h ├── gen-version.sh ├── httpsrv.c ├── httpsrv.h ├── iospeeds.h ├── iospeeds_posix.h ├── jtag.c ├── jtag.h ├── lib ├── Makefile.am ├── dummy.c ├── memchr.c ├── memchr.valgrind ├── memmem.c ├── sig-handler.h ├── sigaction.c ├── signal.in.h ├── sigprocmask.c ├── stddef.in.h ├── stdint.in.h ├── str-two-way.h ├── string.in.h └── strtok_r.c ├── libbitfury.c ├── libbitfury.h ├── libztex.c ├── libztex.h ├── linux-usb-bfgminer ├── logging.c ├── logging.h ├── lowl-ftdi.c ├── lowl-ftdi.h ├── lowl-hid.c ├── lowl-hid.h ├── lowl-mswin.c ├── lowl-mswin.h ├── lowl-pci.c ├── lowl-pci.h ├── lowl-spi.c ├── lowl-spi.h ├── lowl-usb.c ├── lowl-usb.h ├── lowl-vcom.c ├── lowl-vcom.h ├── lowlevel.c ├── lowlevel.h ├── m4 ├── 00gnulib.m4 ├── bundled_lib.m4 ├── custom_subdirs.m4 ├── extensions.m4 ├── gnulib-cache.m4 ├── gnulib-common.m4 ├── gnulib-comp.m4 ├── gnulib-tool.m4 ├── include_next.m4 ├── longlong.m4 ├── memchr.m4 ├── memmem.m4 ├── mmap-anon.m4 ├── multiarch.m4 ├── onceonly.m4 ├── sigaction.m4 ├── signal_h.m4 ├── signalblocking.m4 ├── stddef_h.m4 ├── stdint.m4 ├── string_h.m4 ├── strtok_r.m4 ├── warn-on-use.m4 └── wchar_t.m4 ├── make-release ├── malgo ├── keccak.c ├── scrypt.c ├── scrypt.h └── sha256d.c ├── mcp2210.c ├── mcp2210.h ├── miner.c ├── miner.h ├── miner.php ├── ocl.c ├── ocl.h ├── opencl ├── diablo.cl ├── diakgcn.cl ├── keccak.cl ├── phatk.cl ├── poclbm.cl ├── psw.cl ├── scrypt.cl └── zuikkis.cl ├── openwrt ├── .gitignore ├── bfgminer │ └── Makefile └── multibuild.sh ├── setup-vfio ├── sha2.c ├── sha2.h ├── sha256_4way.c ├── sha256_altivec_4way.c ├── sha256_cryptopp.c ├── sha256_generic.c ├── sha256_sse2_amd64.c ├── sha256_sse2_i386.c ├── sha256_sse4_amd64.c ├── sha256_via.c ├── start-bfgminer.sh ├── test-bfgminer.sh ├── titan-asic.c ├── titan-asic.h ├── tm_i2c.c ├── tm_i2c.h ├── todo_ztex.txt ├── usbtest.py ├── util.c ├── util.h ├── version.c ├── warn-on-use.h ├── windows-build.txt ├── winhacks.h ├── work2d.c ├── work2d.h ├── x86_32 ├── .gitignore ├── Makefile.am └── sha256_xmm.asm └── x86_64 ├── .gitignore ├── Makefile.am ├── sha256_sse4_amd64.asm └── sha256_xmm_amd64.asm /.gitignore: -------------------------------------------------------------------------------- 1 | bfgminer 2 | bfgminer.exe 3 | bfgminer-rpc 4 | bfgminer-rpc.exe 5 | bitforce-firmware-flash 6 | cgminer 7 | cgminer.exe 8 | minerd 9 | minerd.exe 10 | *.o 11 | *.bin 12 | 13 | autom4te.cache 14 | .deps 15 | 16 | Makefile 17 | Makefile.in 18 | INSTALL 19 | aclocal.m4 20 | configure 21 | depcomp 22 | missing 23 | install-sh 24 | stamp-h1 25 | cpuminer-config.h* 26 | compile 27 | config.log 28 | config.status 29 | config.guess 30 | config.sub 31 | 70-bfgminer.rules 32 | 33 | mingw32-config.cache 34 | 35 | *~ 36 | *.orig 37 | *.rej 38 | *.swp 39 | *.kate-swp 40 | 41 | ext_deps 42 | config.h.in 43 | config.h 44 | 45 | ccan*/libccan.a 46 | lib/arg-nonnull.h 47 | lib/c++defs.h 48 | lib/libgnu.a 49 | lib/signal.h 50 | lib/string.h 51 | lib/stdint.h 52 | lib/warn-on-use.h 53 | iospeeds_local.h 54 | version.h 55 | version.h.new 56 | 57 | mkinstalldirs 58 | 59 | .pc 60 | bfgminer-bitforce.conf 61 | 62 | vgcore.* 63 | core* 64 | *.log 65 | *.json 66 | *.patch 67 | *.zip 68 | *.tbz2 69 | *.bz2 70 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libblkmaker"] 2 | path = libblkmaker 3 | url = git://github.com/bitcoin/libblkmaker.git 4 | [submodule "ccan"] 5 | path = ccan-upstream 6 | url = git://git.ozlabs.org/~ccan/ccan 7 | [submodule "libbase58"] 8 | path = libbase58 9 | url = git://github.com/luke-jr/libbase58.git 10 | [submodule "knc-asic"] 11 | path = knc-asic 12 | url = git://github.com/KnCMiner/knc-asic 13 | -------------------------------------------------------------------------------- /.travis.deps: -------------------------------------------------------------------------------- 1 | test "x$1" = "xI-am-okay-with-destroying-my-system" || exit 1 2 | set -ex 3 | 4 | # Upgrading GCC triggers locale rebuild, so just do the one in use 5 | sudo rm /var/lib/locales/supported.d/* 6 | echo $LANG UTF-8 | sudo tee /var/lib/locales/supported.d/en 7 | 8 | echo -e 'deb http://ftp.us.debian.org/debian/ wheezy main\ndeb http://security.debian.org/ wheezy/updates main' | sudo tee '/etc/apt/sources.list' 9 | sudo rm -r /etc/apt/sources.list.d 10 | curl https://ftp-master.debian.org/keys/archive-key-7.0.asc | sudo apt-key add - 11 | sudo apt-get update -qq 12 | if [ -z "$CROSS_BINPKGS" ]; then 13 | DEV_DEPS='libcurl4-gnutls-dev libjansson-dev uthash-dev' 14 | fi 15 | sudo apt-get install -y build-essential autoconf automake libtool $DEV_DEPS $EXTRA_DEPS 16 | 17 | if [ -n "$UBUNTU_DEPS" ]; then 18 | cat <<\EOF | sudo tee '/etc/apt/sources.list' 19 | deb http://gb.archive.ubuntu.com/ubuntu/ trusty main restricted universe 20 | deb http://gb.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe 21 | deb http://gb.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe 22 | deb http://security.ubuntu.com/ubuntu trusty-security main restricted universe 23 | EOF 24 | sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 25 | sudo apt-get update -qq 26 | sudo apt-get install -y $UBUNTU_DEPS 27 | fi 28 | 29 | if [ -n "$CROSS_BINPKGS" ]; then 30 | wget "https://github.com/luke-jr/cross-binpkgs/archive/${CROSS_BINPKGS}.zip" 31 | unzip "${CROSS_BINPKGS}.zip" 32 | for f in "cross-binpkgs-${CROSS_BINPKGS/+/-}"/*/*; do 33 | sudo tar -C "/usr/${CROSS_BINPKGS/+*/}/" -xjvpf "$f" 34 | done 35 | fi 36 | -------------------------------------------------------------------------------- /.travis.script: -------------------------------------------------------------------------------- 1 | test "x$1" = "xI-am-okay-with-destroying-my-system" || exit 1 2 | set -ex 3 | 4 | if [ -n "$CROSS_BINPKGS" ]; then 5 | CROSS_BINPKGS="${CROSS_BINPKGS/+*/}" 6 | myCC="${CROSS_BINPKGS}-gcc" 7 | CC_ARGS="-I/usr/${CROSS_BINPKGS}/usr/include" 8 | export LDFLAGS="-L/usr/${CROSS_BINPKGS}/usr/lib -L/usr/${CROSS_BINPKGS}/usr/bin" 9 | export PKG_CONFIG_PATH="/usr/${CROSS_BINPKGS}/usr/lib/pkgconfig/" 10 | export PKG_CONFIG_SYSROOT_DIR="/usr/${CROSS_BINPKGS}" 11 | fi 12 | 13 | export CC="$(which "$myCC") $CC_ARGS" 14 | $CC --version 15 | 16 | ./autogen.sh 17 | ./configure $GLOBAL_CONFIGURE_ARGS $CONFIGURE_ARGS 18 | make CFLAGS="$GLOBAL_CFLAGS $BUILD_CFLAGS" $MAKEOPTS 19 | if [ -z "$CROSS_BINPKGS" ]; then 20 | make check 21 | sudo make install 22 | fi 23 | -------------------------------------------------------------------------------- /70-bfgminer.rules.in: -------------------------------------------------------------------------------- 1 | # do not edit this file, it will be overwritten on update 2 | 3 | ACTION=="add", SUBSYSTEMS=="usb", GOTO="bfgminer_start" 4 | GOTO="bfgminer_end" 5 | LABEL="bfgminer_start" 6 | 7 | @USE_BIFURY_TRUE@ENV{ID_MODEL}=="*bi•fury*", GOTO="bfgminer_add" 8 | @USE_BIGPIC_TRUE@ENV{ID_MODEL}=="*Bitfury*BF1*", GOTO="bfgminer_add" 9 | @USE_BITFORCE_TRUE@ENV{ID_MODEL}=="*BitFORCE*SHA256*", GOTO="bfgminer_add" 10 | @USE_COINTERRA_TRUE@ENV{ID_MODEL}=="*GoldStrike*", GOTO="bfgminer_add" 11 | @USE_DRILLBIT_TRUE@ENV{manufacturer}=="*Drillbit*", GOTO="bfgminer_add" 12 | @USE_ICARUS_TRUE@ENV{ID_MODEL}=="*Antminer*", GOTO="bfgminer_add" 13 | @USE_ICARUS_TRUE@ENV{ID_MODEL}=="*Cairnsmore1*", GOTO="bfgminer_add" 14 | @USE_ICARUS_TRUE@ENV{ID_MODEL}=="*Compac*Bitcoin*", GOTO="bfgminer_add" 15 | @USE_ICARUS_TRUE@ENV{ID_MODEL}=="*Block*Erupter*", GOTO="bfgminer_add" 16 | @USE_HASHBUSTER_TRUE@ENV{ID_MODEL}=="*HashBuster*", GOTO="bfgminer_add" 17 | @USE_HASHBUSTERUSB_TRUE@ENV{ID_MODEL}=="*HashBuster*", GOTO="bfgminer_add" 18 | @USE_HASHFAST_TRUE@ENV{idVendor}=="297c", ENV{manufacturer}=="*HashFast*", GOTO="bfgminer_add" 19 | @USE_HASHFAST_TRUE@ENV{ID_MODEL}=="*GoldenNonce*", GOTO="bfgminer_add" 20 | @USE_KLONDIKE_TRUE@ENV{idVendor}=="04d8", ENV{idProduct}=="f60a", ENV{manufacturer}=="*Klondike*", GOTO="bfgminer_add" 21 | @USE_KLONDIKE_TRUE@ENV{idVendor}=="fa05", ENV{idProduct}=="0001", ENV{manufacturer}=="*HashBuster*", GOTO="bfgminer_add" 22 | @USE_LITTLEFURY_TRUE@ENV{ID_MODEL}=="*LittleFury*", GOTO="bfgminer_add" 23 | @USE_MODMINER_TRUE@ENV{ID_MODEL}=="*ModMiner*", GOTO="bfgminer_add" 24 | @USE_NANOFURY_TRUE@ENV{idVendor}=="04d8", ENV{idProduct}=="00de", ENV{ID_MODEL}=="*NanoFury*", GOTO="bfgminer_add" 25 | @USE_ROCKMINER_TRUE@ENV{ID_MODEL}=="*R-BOX miner*", GOTO="bfgminer_add" 26 | @USE_ROCKMINER_TRUE@ENV{ID_MODEL}=="*RX-BOX miner*", GOTO="bfgminer_add" 27 | @USE_TWINFURY_TRUE@ENV{ID_MODEL}=="*Twinfury*", GOTO="bfgminer_add" 28 | @USE_X6500_TRUE@ENV{idVendor}=="0403", ENV{idProduct}=="6001", ENV{ID_MODEL}=="*X6500 FPGA Miner*", GOTO="bfgminer_add" 29 | @USE_ZTEX_TRUE@ENV{ID_MODEL}=="*btcminer for ZTEX*", GOTO="bfgminer_add" 30 | 31 | # The below are broad udev rules that may match devices other than the miners expected. 32 | # You can uncomment them with the --enable-broad-udevrules configure option. 33 | 34 | # Avalon1 35 | @BROAD_UDEVRULES_TRUE@@USE_AVALON_TRUE@ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GOTO="bfgminer_add" 36 | # AvalonMM 37 | @BROAD_UDEVRULES_TRUE@@USE_AVALONMM_TRUE@ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GOTO="bfgminer_add" 38 | # DualMiner 39 | @BROAD_UDEVRULES_TRUE@@USE_DUALMINER_TRUE@ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", GOTO="bfgminer_add" 40 | # GridSeed 41 | @BROAD_UDEVRULES_TRUE@@USE_GRIDSEED_TRUE@ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", GOTO="bfgminer_add" 42 | # Icarus 43 | @BROAD_UDEVRULES_TRUE@@USE_ICARUS_TRUE@ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GOTO="bfgminer_add" 44 | # Cairnsmore1 45 | @BROAD_UDEVRULES_TRUE@@USE_ICARUS_TRUE@ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", GOTO="bfgminer_add" 46 | @BROAD_UDEVRULES_TRUE@@USE_ICARUS_TRUE@ATTRS{idVendor}=="0403", ATTRS{idProduct}=="8350", GOTO="bfgminer_add" 47 | # Block Erupter and Antminer U* 48 | @BROAD_UDEVRULES_TRUE@@USE_ICARUS_TRUE@ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GOTO="bfgminer_add" 49 | # ZeusMiner 50 | @BROAD_UDEVRULES_TRUE@@USE_ZEUSMINER_TRUE@ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GOTO="bfgminer_add" 51 | # Possibly unprogrammed ZTEX 52 | @BROAD_UDEVRULES_TRUE@@USE_ZTEX_TRUE@ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", GOTO="bfgminer_add" 53 | # BFx2 54 | @BROAD_UDEVRULES_TRUE@@USE_BFX_TRUE@ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", GOTO="bfgminer_add" 55 | # RockMiner 56 | @BROAD_UDEVRULES_TRUE@@USE_ROCKMINER_TRUE@ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GOTO="bfgminer_add" 57 | 58 | GOTO="bfgminer_end" 59 | 60 | LABEL="bfgminer_add" 61 | 62 | @USE_UDEVRULES_GROUP_TRUE@GROUP="@UDEVRULES_GROUP@" 63 | ENV{ID_MM_DEVICE_IGNORE}="1" 64 | 65 | LABEL="bfgminer_end" 66 | -------------------------------------------------------------------------------- /ADL/adl_sdk.h: -------------------------------------------------------------------------------- 1 | /* The statements-of-fact provided herein are intended to be compatible with 2 | * AMD ADL's library. AMD is the creator and copyright holder of the ADL 3 | * library this interface describes, and therefore also defined this interface 4 | * originally. 5 | * These free interfaces were created by Luke Dashjr 6 | * As interfaces/APIs cannot be copyrighted, there is no license needed in the 7 | * USA and probably many other jurisdictions. 8 | * If your jurisdiction rules otherwise, the header is offered by Luke Dashjr 9 | * under the MIT license, but you are responsible for determining who your 10 | * jurisdiction considers to be the copyright holder in such a case. 11 | * 12 | * THE INFORMATION IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 16 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 | * CONNECTION WITH THE INFORMATION OR THE USE OR OTHER DEALINGS IN THE 18 | * INFORMATION. 19 | */ 20 | 21 | #ifndef ADL_SDK_H_ 22 | #define ADL_SDK_H_ 23 | 24 | #include "adl_structures.h" 25 | 26 | typedef void*( 27 | #ifdef __stdcall 28 | __stdcall 29 | #endif 30 | *ADL_MAIN_MALLOC_CALLBACK)(int); 31 | 32 | #endif /* ADL_SDK_H_ */ 33 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | CURRENT MAINTAINERS: 2 | 3 | Luke Dashjr 1QATWksNFGeUJCWBrN4g6hGM178Lovm7Wh 4 | John Stefanopoulos 5 | 6 | Debian packaging: Dmitry Smirnov 7 | 8 | --- 9 | 10 | PAST MAINTAINERS: 11 | 12 | Anatoly Legkodymov 13 | Andreas Auer 14 | Andrew Smith 1Jjk2LmktEQKnv8r2cZ9MvLiZwZ9gxabKm 15 | Con Kolivas 15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ 16 | Jeff Garzik 17 | Nate Woolls 1JnZoFeCVYJgaKbKwDUxSkTZWWpBmwWTgV 18 | Nelisky 19 | Pelle Nilsson 20 | Vitalii Demianets 21 | Xiangfu 22 | 23 | --- 24 | 25 | CONTRIBUTORS: 26 | 27 | Abracadabra 28 | anajavi 29 | Andrew McDonald 30 | Ang Iongchun 31 | ArtForz 32 | BFL_Jonathon 33 | Bitfury 34 | blinkier 35 | bluemurder 36 | capa66 37 | Christian Berendt 38 | Colin Percival 39 | Daniel Mack 40 | Denis Ahrens 41 | Dmitriy Korniychuk 42 | Dmitry Sorokin 43 | Dualminer Team 44 | fleger 45 | Glenn Francis Murray 46 | gluk 47 | Graeme Humphries 48 | GridSeed Team 49 | HashBuster team 50 | Huang Le <4tarhl@gmail.com> 51 | Isidoro Ghezzi 52 | James Hilliard 53 | James Morris 54 | Jason Hughes 55 | Jason Snell 56 | Jean-Luc Cooke 57 | Jonathan Lynch 58 | Josh Lehan 59 | Kiyoaki Matsugae 60 | Lauri Kasanen 61 | Lingchao Xu 62 | Luke Mitchell 63 | Mark Crichton 64 | Martin Danielsen 65 | Michael Kedzierski 66 | Mr O 67 | mtrlt 68 | Neil Kettle 69 | Nico Oelgart 70 | Olivier Gay 71 | Paul Sheppard 72 | Paul Wouters 73 | Pavel Semjanov 74 | Peter Stuge 75 | Phateus 76 | Philip Kaufmann 77 | pontus 78 | pooler 79 | Raulo 80 | Red_Wolf_2 81 | Ricardo Iván Vieitez Parra 82 | Ronny Van Keer 83 | Rusty Russell 84 | Серёга 85 | slax0r 86 | Teemu Suikki 87 | Thorsten Gilling 88 | Tim Bartletts 89 | Tydus 90 | Ufasoft 91 | Vladimir Strinski 92 | Zefir Kurtisi 93 | ZeusMiner Team 94 | Znort 987 95 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See git repository ('git log') for full changelog. 2 | 3 | Git repo can be found at: 4 | https://github.com/luke-jr/bfgminer 5 | 6 | The NEWS file contains most of the changelog 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BFGMiner is available under the terms of the GNU Public License version 3. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /README.CPU: -------------------------------------------------------------------------------- 1 | EXECUTIVE SUMMARY ON CPU USAGE: 2 | 3 | By default, BFGMiner will NOT mine on CPUs unless it is explicitly compiled with 4 | support and told to do so. CPU mining for bitcoin is generally considered to be 5 | obsolete as it requires considerably more power per hash computed than either 6 | GPU, FPGA or ASIC based mining. If you still wish to mine using CPUs you will 7 | need to build a custom binary with support enabled (refer to the build notes in 8 | README for further information). 9 | 10 | The following CPU mining options are available: 11 | 12 | --algo Specify sha256 implementation for CPU mining: 13 | fastauto* Quick benchmark at startup to pick a working algorithm 14 | auto Benchmark at startup and pick fastest algorithm 15 | c Linux kernel sha256, implemented in C 16 | 4way tcatm's 4-way SSE2 implementation 17 | via VIA padlock implementation 18 | cryptopp Crypto++ C/C++ implementation 19 | cryptopp_asm32 Crypto++ 32-bit assembler implementation 20 | sse2_32 SSE2 32 bit implementation for i386 machines 21 | sse2_64 SSE2 64 bit implementation for x86_64 machines 22 | sse4_64 SSE4.1 64 bit implementation for x86_64 machines 23 | altivec_4way Altivec implementation for PowerPC G4 and G5 machines 24 | --cpu-threads Number of miner CPU threads (default: -1) 25 | 26 | CPU FAQ: 27 | 28 | Q: What happened to CPU mining? 29 | A: Being increasingly irrelevant for most users, and a maintenance issue, it is 30 | no longer under active development and will not be supported unless someone 31 | steps up to help maintain it. No binary builds supporting CPU mining will be 32 | released for Windows but CPU mining can be built into BFGMiner when it is 33 | compiled. For builds which do support CPU mining, it is still disabled by 34 | default, and must be enabled using the -S cpu:auto option. 35 | 36 | Q: So, should I even try CPU mining? 37 | A: No, it honestly will waste more power and time than it is worth at this stage. 38 | If you really wish to mine, you are better off getting a suitable ASIC instead. 39 | 40 | Q: But, if the computers aren't mine and I'm not paying for the power? 41 | A: If you are trying to use computers that aren't yours, you really should 42 | reconsider. Attempting to mine with a large number of devices will often impact 43 | negatively on many pools and will likely pay almost nothing due to the small 44 | number of successful shares submitted. Apart from that, you will probably get 45 | into trouble with someone down the track for misusing the computers. 46 | -------------------------------------------------------------------------------- /README.OpenWrt: -------------------------------------------------------------------------------- 1 | First, look at /etc/openwrt_release (on your router). You will see a bunch of 2 | attributes for the OpenWrt system. The DISTRIB_RELEASE attribute is your 3 | OpenWrt version, the first part of DISTRIB_TARGET (before the slash) is the 4 | router's platform, and (only on newer versions) DISTRIB_ARCH is the package 5 | architecture. Older versions of OpenWrt (up to 15.05) use the router's 6 | platform for packages instead of the package architecture. 7 | 8 | Now, open up /etc/opkg.conf (again, on your router) in your favourite editor. 9 | Add a new line at the bottom, similar to this: 10 | src/gz bfgminer http://luke.dashjr.org/programs/bitcoin/files/bfgminer/latest/openwrt/17.01/mips_24kc 11 | In this example, 17.01 is the version of OpenWrt, and mips_24kc is the package 12 | architecture. Be sure to change those to match your router! You can also change 13 | "latest" to "stable" or "testing" to get better-tested versions. 14 | 15 | Next, save the file and exit your editor. Tell opkg to reload its package lists 16 | by running the command: 17 | opkg update 18 | If you get a "404 Not Found" error, then your router may not be supported. If 19 | you open an issue for your router's platform, it may be possible to add 20 | support. 21 | 22 | If all went well updating your package list, you can now install BFGMiner and 23 | any drivers you might need: 24 | opkg install bfgminer 25 | opkg install kmod-usb-serial-ftdi 26 | opkg install kmod-usb-serial-cp210x 27 | opkg install kmod-usb-serial-pl2303 28 | -------------------------------------------------------------------------------- /adl.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_ADL_H 2 | #define BFG_ADL_H 3 | #ifdef HAVE_ADL 4 | 5 | #include 6 | 7 | extern bool adl_active; 8 | extern bool opt_reorder; 9 | extern const int opt_targettemp; 10 | extern const int opt_overheattemp; 11 | void init_adl(int nDevs); 12 | float gpu_temp(int gpu); 13 | int gpu_engineclock(int gpu); 14 | int gpu_memclock(int gpu); 15 | float gpu_vddc(int gpu); 16 | int gpu_activity(int gpu); 17 | int gpu_fanspeed(int gpu); 18 | int gpu_fanpercent(int gpu); 19 | bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, 20 | int *activity, int *fanspeed, int *fanpercent, int *powertune); 21 | void change_gpusettings(int gpu); 22 | void gpu_autotune(int gpu, enum dev_enable *denable); 23 | void clear_adl(int nDevs); 24 | #else /* HAVE_ADL */ 25 | #define adl_active (0) 26 | static inline void init_adl(__maybe_unused int nDevs) {} 27 | static inline void change_gpusettings(__maybe_unused int gpu) { } 28 | static inline void clear_adl(__maybe_unused int nDevs) {} 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /api-example.php: -------------------------------------------------------------------------------- 1 | 0) 71 | { 72 | $items = explode(',', $obj); 73 | $item = $items[0]; 74 | $id = explode('=', $items[0], 2); 75 | if (count($id) == 1 or !ctype_digit($id[1])) 76 | $name = $id[0]; 77 | else 78 | $name = $id[0].$id[1]; 79 | 80 | if (strlen($name) == 0) 81 | $name = 'null'; 82 | 83 | if (isset($data[$name])) 84 | { 85 | $num = 1; 86 | while (isset($data[$name.$num])) 87 | $num++; 88 | $name .= $num; 89 | } 90 | 91 | $counter = 0; 92 | foreach ($items as $item) 93 | { 94 | $id = explode('=', $item, 2); 95 | if (count($id) == 2) 96 | $data[$name][$id[0]] = $id[1]; 97 | else 98 | $data[$name][$counter] = $id[0]; 99 | 100 | $counter++; 101 | } 102 | } 103 | } 104 | 105 | return $data; 106 | } 107 | 108 | return null; 109 | } 110 | # 111 | if (isset($argv) and count($argv) > 1) 112 | $r = request($argv[1]); 113 | else 114 | $r = request('summary'); 115 | # 116 | echo print_r($r, true)."\n"; 117 | # 118 | ?> 119 | -------------------------------------------------------------------------------- /api-example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2013 Christian Berendt 3 | # Copyright 2013 Luke Dashjr 4 | # 5 | # This program is free software; you can redistribute it and/or modify it under 6 | # the terms of the GNU General Public License as published by the Free Software 7 | # Foundation; either version 3 of the License, or (at your option) any later 8 | # version. See COPYING for more details. 9 | 10 | import argparse 11 | import json 12 | import logging 13 | import pprint 14 | import socket 15 | 16 | logging.basicConfig( 17 | format='%(asctime)s %(levelname)s %(message)s', 18 | level=logging.DEBUG 19 | ) 20 | 21 | parser = argparse.ArgumentParser() 22 | parser.add_argument("command", default="summary", nargs='?') 23 | parser.add_argument("parameter", default="", nargs='?') 24 | parser.add_argument("--hostname", default="localhost") 25 | parser.add_argument("--port", type=int, default=4028) 26 | args = parser.parse_args() 27 | 28 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 29 | 30 | try: 31 | s.connect((args.hostname, args.port)) 32 | except socket.error, e: 33 | logging.error(e) 34 | 35 | try: 36 | s.send("{\"command\" : \"%s\", \"parameter\" : \"%s\"}" 37 | % (args.command, args.parameter) 38 | ) 39 | except socket.error, e: 40 | logging.error(e) 41 | 42 | 43 | data = '' 44 | while True: 45 | try: 46 | newdata = s.recv(1024) 47 | if newdata: 48 | data += newdata 49 | else: 50 | break 51 | except socket.error, e: 52 | break 53 | 54 | try: 55 | s.close() 56 | except socket.error,e: 57 | logging.error(e) 58 | 59 | if data: 60 | data = json.loads(data.replace('\x00', '')) 61 | pp = pprint.PrettyPrinter() 62 | pp.pprint(data) 63 | -------------------------------------------------------------------------------- /api-example.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # Copyright 2014 James Hilliard 4 | # 5 | # This program is free software; you can redistribute it and/or modify it under 6 | # the terms of the GNU General Public License as published by the Free Software 7 | # Foundation; either version 3 of the License, or (at your option) any later 8 | # version. See COPYING for more details. 9 | 10 | require 'socket' 11 | require 'json' 12 | 13 | api_command = ARGV[0].split(":") 14 | 15 | if ARGV.length == 3 16 | api_ip = ARGV[1] 17 | api_port = ARGV[2] 18 | elsif ARGV.length == 2 19 | api_ip = ARGV[1] 20 | api_port = 4028 21 | else 22 | api_ip = "127.0.0.1" 23 | api_port = 4028 24 | end 25 | 26 | s = TCPSocket.open(api_ip, api_port) 27 | 28 | if api_command.count == 2 29 | s.write({ :command => api_command[0], :parameter => api_command[1]}.to_json) 30 | else 31 | s.write({ :command => api_command[0]}.to_json) 32 | end 33 | 34 | response = s.read.strip 35 | response = JSON.parse(response) 36 | 37 | puts response 38 | s.close 39 | -------------------------------------------------------------------------------- /arg-nonnull.h: -------------------------------------------------------------------------------- 1 | /* A C macro for declaring that specific arguments must not be NULL. 2 | Copyright (C) 2009-2011 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published 6 | by the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools 18 | that the values passed as arguments n, ..., m must be non-NULL pointers. 19 | n = 1 stands for the first argument, n = 2 for the second argument etc. */ 20 | #ifndef _GL_ARG_NONNULL 21 | # if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 22 | # define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) 23 | # else 24 | # define _GL_ARG_NONNULL(params) 25 | # endif 26 | #endif 27 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # Written by Luke Dashjr in 2012-2014 3 | # This program is released under the terms of the Creative Commons "CC0 1.0 Universal" license and/or copyright waiver. 4 | 5 | bs_dir="$(dirname "$0")" 6 | 7 | if test -z "$NOSUBMODULES" ; then 8 | echo 'Getting submodules...' 9 | 10 | # Older versions had INSTALL in git; remove it so git can update cleanly 11 | rm -f libblkmaker/INSTALL 12 | 13 | ( 14 | cd "${bs_dir}" 15 | git submodule update --init 16 | ) 17 | fi 18 | 19 | echo 'Running autoreconf -if...' 20 | ( 21 | cd "${bs_dir}" 22 | rm -rf autom4te.cache 23 | rm -f aclocal.m4 ltmain.sh 24 | autoreconf -if ${AC_FLAGS} 25 | ) 26 | 27 | echo 'Updating version.h...' 28 | if ./gen-version.sh >version.h.new; then 29 | cmp version.h version.h.new && rm version.h.new || mv version.h.new version.h 30 | fi 31 | -------------------------------------------------------------------------------- /avalonhost-raminst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright 2013 Luke Dashjr 3 | # 4 | # This program is free software; you can redistribute it and/or modify it under 5 | # the terms of the GNU General Public License as published by the Free Software 6 | # Foundation; either version 3 of the License, or (at your option) any later 7 | # version. See COPYING for more details. 8 | 9 | set -e 10 | if test "$#" -lt 2; then 11 | echo "Usage: $0 " 12 | echo "Example: $0 testing bfgminer screen" 13 | echo "Installs to RAM, on an Avalon-host router" 14 | echo "Version can be 'stable', 'testing', or any 3-digit version; eg '3.1.0'" 15 | echo "Do NOT attempt to reverse (uninstall) except by rebooting" 16 | echo "Do NOT attempt to use this script more than once per boot" 17 | exit 1 18 | fi 19 | die() { 20 | echo "$@" 21 | echo 'ABORTING' 22 | exit 1 23 | } 24 | if ! grep TL-WR703N /proc/cpuinfo; then 25 | die 'This doesn'\''t seem to be an Avalon host system' 26 | fi 27 | if test "$USER" != "root"; then 28 | die "Must be run as root" 29 | fi 30 | echo "WARNING: If anything fails other than opkg and crontab, reboot ASAP" 31 | source /lib/functions.sh 32 | mkdir -p /tmp/root/.oldroot 33 | mount -o noatime,lowerdir=/rom,upperdir=/tmp/root -t overlayfs "overlayfs:/tmp/root" /mnt 34 | pivot /mnt /.oldroot 35 | mount -o noatime,move /.oldroot/rom /rom 36 | sed -i 's/\(^option[[:space:]]\+overlay_root[[:space:]]\+\).*//;T;d' /etc/opkg.conf 37 | { 38 | echo 'option overlay_root /' 39 | echo "src/gz bfgminer http://luke.dashjr.org/programs/bitcoin/files/bfgminer/$1/openwrt/12.09/ar71xx" 40 | } >> /etc/opkg.conf 41 | shift 42 | set +e 43 | opkg update 44 | opkg install "$@" 45 | crontab -r # disabled cgminer-monitor 46 | set -e 47 | mount -o noatime,lowerdir=/,upperdir=/overlay -t overlayfs "overlayfs:/overlay" /mnt 48 | pivot /mnt /.oldroot 49 | mount -o noatime,move /.oldroot/rom /rom 50 | -------------------------------------------------------------------------------- /binloader.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_BINLOADER_H 2 | #define BFG_BINLOADER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "util.h" 8 | 9 | extern void _bitstream_not_found(const char *repr, const char *fn); 10 | extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len); 11 | extern bool load_bitstream_intelhex(bytes_t *out, const char *dname, const char *repr, const char *fn); 12 | extern bool load_bitstream_bytes(bytes_t *out, const char *dname, const char *repr, const char *fileprefix); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /bitstreams/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luke-jr/bfgminer/866fd36f3a77d181805b899d5d306bd87b01f704/bitstreams/.gitignore -------------------------------------------------------------------------------- /ccan.bfg/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libccan.a 2 | 3 | libccan_a_SOURCES = \ 4 | ../ccan-upstream/ccan/build_assert/build_assert.h \ 5 | ../ccan-upstream/ccan/cast/cast.h \ 6 | ../ccan-upstream/ccan/compiler/compiler.h \ 7 | ../ccan-upstream/ccan/opt/helpers.c \ 8 | ../ccan-upstream/ccan/opt/opt.c \ 9 | ../ccan-upstream/ccan/opt/opt.h \ 10 | ../ccan-upstream/ccan/opt/parse.c \ 11 | ../ccan-upstream/ccan/opt/private.h \ 12 | ../ccan-upstream/ccan/opt/usage.c \ 13 | ../ccan-upstream/ccan/typesafe_cb/typesafe_cb.h 14 | libccan_a_CPPFLAGS = -I$(top_srcdir)/ccan-upstream 15 | -------------------------------------------------------------------------------- /debian/bfgminer.docs: -------------------------------------------------------------------------------- 1 | api-example.c 2 | api-example.php 3 | api-example.py 4 | AUTHORS 5 | ChangeLog 6 | COPYING 7 | example.conf 8 | LICENSE 9 | NEWS 10 | README 11 | README.ASIC 12 | README.Debian 13 | README.FPGA 14 | README.RPC 15 | README.scrypt 16 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: bfgminer 2 | Priority: optional 3 | Section: net 4 | Maintainer: Luke Dashjr 5 | Standards-Version: 5.5.0 6 | Build-Depends: build-essential, debhelper, autoconf, automake, libtool 7 | ,libbase58-dev 8 | ,libblkmaker-0.1-dev 9 | ,libcurl4-gnutls-dev | libcurl-ssl-dev 10 | ,libevent-dev 11 | ,libjansson-dev 12 | ,libmicrohttpd-dev 13 | ,libncursesw5-dev 14 | ,libsensors4-dev [!hurd-any] 15 | ,libudev-dev [!kfreebsd-any] 16 | ,libusb-1.0-0-dev 17 | ,pkgconf | pkg-config 18 | ,uthash-dev 19 | ,yasm 20 | ,wget 21 | ,unzip 22 | ,git 23 | ,quilt 24 | ,libhidapi-dev 25 | Homepage: https://github.com/luke-jr/bfgminer 26 | 27 | Package: bfgminer 28 | Architecture: any 29 | Depends: ${shlibs:Depends}, ${misc:Depends} 30 | Suggests: ocl-icd-libopencl1, opencl-icd 31 | ,libhidapi-libusb0 | libhidapi-hidraw0 32 | Description: multi-threaded, multi-blockchain, multi-pool ASIC, FPGA, GPU and CPU 33 | miner with dynamic clocking, monitoring, and fanspeed support for bitcoin. 34 | . 35 | Bitcoin uses peer-to-peer technology to operate with no central authority or 36 | banks; managing transactions and the issuing of bitcoins is carried out 37 | collectively by the network. 38 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Nick Bushor on 2 | Sat, 05 May 2012 12:08:35 -0500. 3 | 4 | It was downloaded from https://github.com/luke-jr/bfgminer 5 | 6 | Upstream Author: Luke Dashjr 7 | 8 | 9 | Distributed under the terms of the GNU General Public License. 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | 25 | On Debian GNU/Linux systems, the complete text of the GNU General 26 | Public License can be found in the /usr/share/common-licenses/GPL file. 27 | 28 | 29 | Redistribution and use in source and binary forms, with or without 30 | modification, are permitted provided that the following conditions 31 | are met: 32 | 1. Redistributions of source code must retain the above copyright 33 | notice, this list of conditions and the following disclaimer. 34 | 2. Redistributions in binary form must reproduce the above copyright 35 | notice, this list of conditions and the following disclaimer in 36 | the documentation and/or other materials provided with the 37 | distribution. 38 | 3. The names of the authors may not be used to endorse or promote 39 | products derived from this software without specific prior 40 | written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 43 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 44 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 45 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DH_VERBOSE=1 4 | 5 | %: 6 | dh $@ 7 | 8 | 9 | override_dh_auto_configure: 10 | NOSUBMODULES=1 ./autogen.sh 11 | dh_auto_configure -- --enable-other-drivers --enable-keccak --enable-scrypt --with-system-libblkmaker --disable-knc 12 | 13 | override_dh_auto_install: 14 | $(MAKE) DESTDIR=$(CURDIR)/debian/bfgminer install 15 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /driver-aan.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_AAN 2 | #define BFG_DRIVER_AAN 3 | 4 | #include 5 | #include 6 | 7 | #include "lowl-spi.h" 8 | #include "miner.h" 9 | 10 | #define AAN_ALL_CHIPS 0 11 | #define AAN_MAX_JOBID 4 12 | 13 | struct aan_hooks { 14 | void (*precmd)(struct spi_port *); 15 | bool (*read_reg)(struct spi_port *, uint8_t chip, void *out_buf, const struct timeval *tvp_timeout); 16 | }; 17 | 18 | struct aan_board_data { 19 | struct spi_port *spi; 20 | struct timeval tv_next_poll; 21 | struct cgpu_info *master_dev; 22 | 23 | // Master board only 24 | int queues_empty; 25 | }; 26 | 27 | struct aan_chip_data { 28 | uint8_t chipid; 29 | int8_t last_jobid; 30 | struct work *works[AAN_MAX_JOBID]; 31 | float desired_nonce_pdiff; 32 | float current_nonce_pdiff; 33 | uint16_t desired_pllreg; 34 | uint16_t current_pllreg; 35 | }; 36 | 37 | extern int aan_detect_spi(int *out_chipcount, struct spi_port * const *spi_a, int spi_n); 38 | extern bool aan_read_reg_direct(struct spi_port *, uint8_t chip, void *out_buf, const struct timeval *tvp_timeout); 39 | extern bool aan_init(struct thr_info *); 40 | extern bool aan_queue_append(struct thr_info *, struct work *); 41 | extern void aan_queue_flush(struct thr_info *); 42 | extern struct cgpu_info *aan_proc_for_chipid(struct cgpu_info *, int chipid); 43 | extern void aan_poll(struct thr_info *); 44 | 45 | extern const char *aan_set_diff(struct cgpu_info *, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *); 46 | extern const struct bfg_set_device_definition aan_set_device_funcs[]; 47 | 48 | extern struct api_data *aan_api_device_status(struct cgpu_info *); 49 | 50 | extern void aan_wlogprint_status(struct cgpu_info *proc); 51 | extern void aan_tui_wlogprint_choices(struct cgpu_info *proc); 52 | extern const char *aan_tui_handle_choice(struct cgpu_info *proc, int input); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /driver-avalon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Avalon project 3 | * Copyright 2013 Con Kolivas 4 | * Copyright 2014 Luke Dashjr 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 3 of the License, or (at your option) 9 | * any later version. See COPYING for more details. 10 | */ 11 | 12 | #ifndef AVALON_H 13 | #define AVALON_H 14 | 15 | #ifdef USE_AVALON 16 | 17 | #include 18 | 19 | #define AVALON_TIME_FACTOR 10 20 | #define AVALON_RESET_FAULT_DECISECONDS 1 21 | #define AVALON_MINER_THREADS 1 22 | 23 | #define AVALON_IO_SPEED 115200 24 | #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32) 25 | #define AVALON_RESET_PITCH (300*1000*1000) 26 | 27 | #define AVALON_FAN_FACTOR 120 28 | #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */ 29 | #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */ 30 | 31 | #define AVALON_DEFAULT_TIMEOUT 0x32 32 | #define AVALON_DEFAULT_FREQUENCY 256 33 | #define AVALON_DEFAULT_MINER_NUM 0x20 34 | #define AVALON_DEFAULT_MINER_NUM_S "32" 35 | #define AVALON_DEFAULT_ASIC_NUM 0xA 36 | #define AVALON_DEFAULT_ASIC_NUM_S "10" 37 | 38 | #define AVALON_FTDI_READSIZE 512 39 | 40 | struct avalon_task { 41 | uint8_t reset :1; 42 | uint8_t flush_fifo :1; 43 | uint8_t fan_eft :1; 44 | uint8_t timer_eft :1; 45 | uint8_t asic_num :4; 46 | uint8_t fan_pwm_data; 47 | uint8_t timeout_data; 48 | uint8_t miner_num; 49 | 50 | uint8_t nonce_elf :1; 51 | uint8_t gate_miner_elf :1; 52 | uint8_t asic_pll :1; 53 | uint8_t gate_miner :1; 54 | uint8_t _pad0 :4; 55 | uint8_t _pad1[3]; 56 | uint32_t _pad2; 57 | 58 | uint8_t midstate[32]; 59 | uint8_t data[12]; 60 | } __attribute__((packed, aligned(4))); 61 | 62 | struct avalon_result { 63 | uint32_t nonce; 64 | uint8_t data[12]; 65 | uint8_t midstate[32]; 66 | 67 | uint8_t fan0; 68 | uint8_t fan1; 69 | uint8_t fan2; 70 | uint8_t temp0; 71 | uint8_t temp1; 72 | uint8_t temp2; 73 | uint8_t _pad0[2]; 74 | 75 | uint16_t fifo_wp; 76 | uint16_t fifo_rp; 77 | uint8_t chip_num; 78 | uint8_t pwm_data; 79 | uint8_t timeout; 80 | uint8_t miner_num; 81 | } __attribute__((packed, aligned(4))); 82 | 83 | struct avalon_info { 84 | int read_count; 85 | 86 | int baud; 87 | int miner_count; 88 | int asic_count; 89 | int timeout; 90 | 91 | int fan0; 92 | int fan1; 93 | int fan2; 94 | 95 | int temp0; 96 | int temp1; 97 | int temp2; 98 | int temp_max; 99 | int temp_history_count; 100 | int temp_history_index; 101 | int temp_sum; 102 | int temp_old; 103 | int fan_pwm; 104 | 105 | int no_matching_work; 106 | int matching_work[AVALON_DEFAULT_MINER_NUM]; 107 | 108 | int frequency; 109 | }; 110 | 111 | #define AVALON_WRITE_SIZE (sizeof(struct avalon_task)) 112 | #define AVALON_READ_SIZE (sizeof(struct avalon_result)) 113 | #define AVALON_ARRAY_SIZE 4 114 | 115 | #define AVA_GETS_ERROR -1 116 | #define AVA_GETS_OK 0 117 | #define AVA_GETS_RESTART 1 118 | #define AVA_GETS_TIMEOUT 2 119 | 120 | #define AVA_SEND_ERROR -1 121 | #define AVA_SEND_OK 0 122 | #define AVA_SEND_BUFFER_EMPTY 1 123 | #define AVA_SEND_BUFFER_FULL 2 124 | 125 | #define AVA_BUFFER_FULL 0 126 | #define AVA_BUFFER_EMPTY 1 127 | 128 | #define avalon_open2(devpath, baud, purge) serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge) 129 | #define avalon_open(devpath, baud) avalon_open2(devpath, baud, true) 130 | #define avalon_close(fd) close(fd) 131 | 132 | #define avalon_buffer_full(fd) (get_serial_cts(fd) != BGV_LOW) 133 | 134 | #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud)) 135 | #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1] 136 | ASSERT1(sizeof(uint32_t) == 4); 137 | 138 | extern struct avalon_info **avalon_info; 139 | 140 | #endif /* USE_AVALON */ 141 | #endif /* AVALON_H */ 142 | -------------------------------------------------------------------------------- /driver-bigpic.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_BIGPIC_H 2 | #define BFG_DRIVER_BIGPIC_H 3 | 4 | #include 5 | 6 | #define BPM_BAUD 115200 7 | 8 | struct bigpic_identity 9 | { 10 | uint8_t version; 11 | char product[8]; 12 | uint32_t serial; 13 | } __attribute__((packed)); 14 | 15 | struct bigpic_state 16 | { 17 | uint8_t state; 18 | uint8_t switched; 19 | uint32_t nonce; 20 | } __attribute__((packed)); 21 | 22 | struct bigpic_info 23 | { 24 | uint32_t baud; 25 | 26 | struct bigpic_identity id; 27 | 28 | char tx_buffer[45]; 29 | char rx_buffer[1024]; 30 | uint32_t rx_len; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /driver-bitfury.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_BITFURY_H 2 | #define BFG_DRIVER_BITFURY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "miner.h" 8 | 9 | #define BITFURY_MAX_OSC6_BITS 60 10 | #define BITFURY_MAX_OSC6_BITS_S "60" 11 | 12 | extern const struct bfg_set_device_definition bitfury_set_device_funcs[]; 13 | extern const struct bfg_set_device_definition *bitfury_set_device_funcs_probe; 14 | extern const char *bitfury_set_baud(struct cgpu_info *, const char *, const char *, char *, enum bfg_set_device_replytype *); 15 | extern const char *bitfury_set_osc6_bits(struct cgpu_info *, const char *, const char *, char *, enum bfg_set_device_replytype *); 16 | 17 | extern bool bitfury_prepare(struct thr_info *); 18 | extern bool bitfury_init_chip(struct cgpu_info *); 19 | extern void bitfury_init_freq_stat(struct freq_stat *, int osc6_min, int osc6_max); 20 | extern void bitfury_clean_freq_stat(struct freq_stat *); 21 | 22 | extern bool bitfury_job_prepare(struct thr_info *, struct work *, uint64_t max_nonce); 23 | extern void bitfury_noop_job_start(struct thr_info *); 24 | extern void bitfury_do_io(struct thr_info *); 25 | extern int64_t bitfury_job_process_results(struct thr_info *, struct work *, bool stopping); 26 | extern struct api_data *bitfury_api_device_detail(struct cgpu_info *); 27 | extern struct api_data *bitfury_api_device_status(struct cgpu_info *); 28 | extern void bitfury_tui_wlogprint_choices(struct cgpu_info *); 29 | extern const char *bitfury_tui_handle_choice(struct cgpu_info *, int input); 30 | extern void bitfury_wlogprint_status(struct cgpu_info *); 31 | 32 | extern void bitfury_disable(struct thr_info *); 33 | extern void bitfury_enable(struct thr_info *); 34 | extern void bitfury_shutdown(struct thr_info *); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /driver-cpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Luke Dashjr 3 | * Copyright 2011-2012 Con Kolivas 4 | * Copyright 2011 Mark Crichton 5 | * Copyright 2010 Jeff Garzik 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 3 of the License, or (at your option) 10 | * any later version. See COPYING for more details. 11 | */ 12 | 13 | #ifndef BFG_DRIVER_CPU_H 14 | #define BFG_DRIVER_CPU_H 15 | 16 | #include "miner.h" 17 | 18 | #include "config.h" 19 | #include 20 | 21 | #ifndef OPT_SHOW_LEN 22 | #define OPT_SHOW_LEN 80 23 | #endif 24 | 25 | #ifdef USE_SHA256D 26 | 27 | #if defined(__i386__) && defined(HAVE_SSE2) 28 | #define WANT_SSE2_4WAY 1 29 | #endif 30 | 31 | #ifdef __ALTIVEC__ 32 | #define WANT_ALTIVEC_4WAY 1 33 | #endif 34 | 35 | #if defined(__i386__) && defined(HAVE_YASM) && defined(HAVE_SSE2) 36 | #define WANT_X8632_SSE2 1 37 | #endif 38 | 39 | #ifdef __i386__ 40 | #define WANT_VIA_PADLOCK 1 41 | #endif 42 | 43 | #if defined(__x86_64__) && defined(HAVE_YASM) 44 | #define WANT_X8664_SSE2 1 45 | #endif 46 | 47 | #if defined(__x86_64__) && defined(HAVE_YASM) 48 | #define WANT_X8664_SSE4 1 49 | #endif 50 | 51 | #endif /* USE_SHA256D */ 52 | 53 | #ifdef USE_SCRYPT 54 | #define WANT_SCRYPT 55 | #endif 56 | 57 | enum sha256_algos { 58 | #ifdef USE_SHA256D 59 | ALGO_C, /* plain C */ 60 | ALGO_4WAY, /* parallel SSE2 */ 61 | ALGO_VIA, /* VIA padlock */ 62 | ALGO_CRYPTOPP, /* Crypto++ (C) */ 63 | ALGO_CRYPTOPP_ASM32, /* Crypto++ 32-bit assembly */ 64 | ALGO_SSE2_32, /* SSE2 for x86_32 */ 65 | ALGO_SSE2_64, /* SSE2 for x86_64 */ 66 | ALGO_SSE4_64, /* SSE4 for x86_64 */ 67 | ALGO_ALTIVEC_4WAY, /* parallel Altivec */ 68 | #endif 69 | #ifdef USE_SCRYPT 70 | ALGO_SCRYPT, /* scrypt */ 71 | #endif 72 | 73 | #ifdef USE_SHA256D 74 | ALGO_FASTAUTO, /* fast autodetect */ 75 | ALGO_AUTO, /* autodetect */ 76 | #endif 77 | 78 | CUSTOM_CPU_MINING_ALGOS_COUNT, 79 | }; 80 | 81 | extern const char *algo_names[]; 82 | extern struct device_drv cpu_drv; 83 | 84 | extern const uint32_t hash1_init[]; 85 | 86 | extern char *set_algo(const char *arg, enum sha256_algos *algo); 87 | extern void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo); 88 | extern char *force_nthreads_int(const char *arg, int *i); 89 | extern void init_max_name_len(); 90 | extern double bench_algo_stage3(enum sha256_algos algo); 91 | extern void set_scrypt_algo(enum sha256_algos *algo); 92 | 93 | #endif /* __DEVICE_CPU_H__ */ 94 | -------------------------------------------------------------------------------- /driver-erupter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | 14 | #include "miner.h" 15 | #include "driver-icarus.h" 16 | #include "lowlevel.h" 17 | #include "lowl-vcom.h" 18 | 19 | #define ERUPTER_IO_SPEED 115200 20 | #define ERUPTER_HASH_TIME 0.0000000029761 21 | 22 | BFG_REGISTER_DRIVER(erupter_drv) 23 | BFG_REGISTER_DRIVER(erupter_drv_emerald) 24 | 25 | static bool _erupter_detect_one(const char *devpath, struct device_drv *drv) 26 | { 27 | struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO)); 28 | if (unlikely(!info)) 29 | quit(1, "Failed to malloc ICARUS_INFO"); 30 | 31 | *info = (struct ICARUS_INFO){ 32 | .baud = ERUPTER_IO_SPEED, 33 | .Hs = ERUPTER_HASH_TIME, 34 | .timing_mode = MODE_DEFAULT, 35 | .continue_search = true, 36 | }; 37 | 38 | if (!icarus_detect_custom(devpath, drv, info)) { 39 | free(info); 40 | return false; 41 | } 42 | return true; 43 | } 44 | 45 | static 46 | bool erupter_emerald_lowl_match(const struct lowlevel_device_info * const info) 47 | { 48 | return lowlevel_match_product(info, "Block", "Erupter", "Emerald"); 49 | } 50 | 51 | static bool erupter_emerald_detect_one(const char *devpath) 52 | { 53 | // For detection via BEE:* 54 | return _erupter_detect_one(devpath, &erupter_drv_emerald); 55 | } 56 | 57 | static 58 | bool erupter_emerald_lowl_probe(const struct lowlevel_device_info * const info) 59 | { 60 | return vcom_lowl_probe_wrapper(info, erupter_emerald_detect_one); 61 | } 62 | 63 | static 64 | bool erupter_lowl_match(const struct lowlevel_device_info * const info) 65 | { 66 | return lowlevel_match_lowlproduct(info, &lowl_vcom, "Block", "Erupter"); 67 | } 68 | 69 | static bool erupter_detect_one(const char *devpath) 70 | { 71 | struct device_drv *drv = &erupter_drv; 72 | 73 | // For autodetection 74 | if (unlikely(detectone_meta_info.product && strstr(detectone_meta_info.product, "Emerald"))) 75 | drv = &erupter_drv_emerald; 76 | 77 | return _erupter_detect_one(devpath, drv); 78 | } 79 | 80 | static 81 | bool erupter_lowl_probe(const struct lowlevel_device_info * const info) 82 | { 83 | return vcom_lowl_probe_wrapper(info, erupter_detect_one); 84 | } 85 | 86 | static bool erupter_identify(struct cgpu_info *erupter) 87 | { 88 | struct thr_info *thr = erupter->thr[0]; 89 | struct icarus_state *state = thr->cgpu_data; 90 | state->identify = true; 91 | return true; 92 | } 93 | 94 | static void erupter_drv_init() 95 | { 96 | erupter_drv = icarus_drv; 97 | erupter_drv.dname = "erupter"; 98 | erupter_drv.name = "BES"; 99 | erupter_drv.lowl_match = erupter_lowl_match; 100 | erupter_drv.lowl_probe = erupter_lowl_probe; 101 | erupter_drv.identify_device = erupter_identify; 102 | erupter_drv.probe_priority = -120; 103 | 104 | erupter_drv_emerald = erupter_drv; 105 | erupter_drv_emerald.name = "BEE"; 106 | erupter_drv_emerald.lowl_match = erupter_emerald_lowl_match; 107 | erupter_drv_emerald.lowl_probe = erupter_emerald_lowl_probe; 108 | erupter_drv_emerald.probe_priority = -119; 109 | } 110 | 111 | struct device_drv erupter_drv = { 112 | .drv_init = erupter_drv_init, 113 | }; 114 | 115 | struct device_drv erupter_drv_emerald = { 116 | .drv_init = erupter_drv_init, 117 | }; 118 | -------------------------------------------------------------------------------- /driver-hashbusteravalon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | #include 14 | 15 | #include "deviceapi.h" 16 | #include "driver-klondike.h" 17 | #include "logging.h" 18 | #include "lowlevel.h" 19 | 20 | BFG_REGISTER_DRIVER(hashbusteravalon_drv) 21 | 22 | static 23 | bool hashbusteravalon_lowl_match(const struct lowlevel_device_info * const info) 24 | { 25 | if (!lowlevel_match_id(info, &lowl_usb, 0xfa05, 0x0001)) 26 | return false; 27 | return (info->manufacturer && strstr(info->manufacturer, "HashBuster")); 28 | } 29 | 30 | static 31 | bool hashbusteravalon_lowl_probe(const struct lowlevel_device_info * const info) 32 | { 33 | struct klondike_info * const klninfo = malloc(sizeof(*klninfo)); 34 | if (unlikely(!klninfo)) 35 | applogr(false, LOG_ERR, "%s: Failed to malloc klninfo", __func__); 36 | 37 | *klninfo = (struct klondike_info){ 38 | .clock = 2425, 39 | .max_work_count = 0x20, 40 | .old_work_ms = 30000, 41 | .reply_wait_time = 5, 42 | }; 43 | 44 | return klondike_lowl_probe_custom(info, &hashbusteravalon_drv, klninfo); 45 | } 46 | 47 | static void hashbusteravalon_drv_init() 48 | { 49 | hashbusteravalon_drv = klondike_drv; 50 | hashbusteravalon_drv.dname = "hashbusteravalon"; 51 | hashbusteravalon_drv.name = "HBA"; 52 | hashbusteravalon_drv.lowl_match = hashbusteravalon_lowl_match; 53 | hashbusteravalon_drv.lowl_probe = hashbusteravalon_lowl_probe; 54 | } 55 | 56 | struct device_drv hashbusteravalon_drv = { 57 | .drv_init = hashbusteravalon_drv_init, 58 | }; 59 | -------------------------------------------------------------------------------- /driver-klondike.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_KLONDIKE_H 2 | #define BFG_DRIVER_KLONDIKE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "lowlevel.h" 11 | #include "miner.h" 12 | 13 | struct klondike_info { 14 | pthread_rwlock_t stat_lock; 15 | struct thr_info replies_thr; 16 | cglock_t klist_lock; 17 | struct klist *used; 18 | struct klist *free; 19 | int kline_count; 20 | int used_count; 21 | int block_seq; 22 | struct klist *status; 23 | struct device_info *devinfo; 24 | struct klist *cfg; 25 | struct jobque *jobque; 26 | int noncecount; 27 | uint64_t hashcount; 28 | uint64_t errorcount; 29 | uint64_t noisecount; 30 | int incorrect_slave_sequential; 31 | int16_t nonce_offset; 32 | 33 | // us Delay from USB reply to being processed 34 | double delay_count; 35 | double delay_total; 36 | double delay_min; 37 | double delay_max; 38 | 39 | struct timeval tv_last_nonce_received; 40 | 41 | // Time from recieving one nonce to the next 42 | double nonce_count; 43 | double nonce_total; 44 | double nonce_min; 45 | double nonce_max; 46 | 47 | int wque_size; 48 | int wque_cleared; 49 | 50 | int clock; 51 | bool initialised; 52 | 53 | struct libusb_device_handle *usbdev_handle; 54 | 55 | // TODO: 56 | bool usbinfo_nodev; 57 | 58 | int max_work_count; 59 | int old_work_ms; 60 | int reply_wait_time; 61 | }; 62 | 63 | extern bool klondike_lowl_probe_custom(const struct lowlevel_device_info * const info, struct device_drv * const drv, struct klondike_info * const klninfo); 64 | 65 | extern struct device_drv klondike_drv; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /driver-opencl.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_OPENCL 2 | #define BFG_DRIVER_OPENCL 3 | 4 | #include 5 | #include 6 | 7 | #include "CL/cl.h" 8 | #ifdef HAVE_SENSORS 9 | #include 10 | #endif 11 | 12 | #include "miner.h" 13 | 14 | enum opencl_binary_usage { 15 | OBU_DEFAULT = 0, 16 | OBU_LOAD = 1, 17 | OBU_SAVE = 2, 18 | OBU_LOADSAVE = 3, 19 | OBU_NONE = 4, 20 | }; 21 | 22 | static const float intensity_not_set = FLT_MAX; 23 | 24 | struct opencl_kernel_info; 25 | struct _clState; 26 | 27 | typedef cl_int (*queue_kernel_parameters_func_t)(const struct opencl_kernel_info *, struct _clState *, struct work *, cl_uint); 28 | 29 | struct opencl_kernel_info { 30 | char *file; 31 | bool loaded; 32 | cl_program program; 33 | cl_kernel kernel; 34 | bool goffset; 35 | enum cl_kernels interface; 36 | size_t wsize; 37 | queue_kernel_parameters_func_t queue_kernel_parameters; 38 | }; 39 | 40 | struct opencl_device_data { 41 | bool mapped; 42 | int virtual_gpu; 43 | int virtual_adl; 44 | unsigned long oclthreads; 45 | float intensity; 46 | char *_init_intensity; 47 | bool dynamic; 48 | 49 | enum bfg_tristate use_goffset; 50 | cl_uint vwidth; 51 | size_t work_size; 52 | cl_ulong max_alloc; 53 | 54 | struct opencl_kernel_info kernelinfo[POW_ALGORITHM_COUNT]; 55 | 56 | enum opencl_binary_usage opt_opencl_binaries; 57 | #ifdef USE_SCRYPT 58 | int lookup_gap; 59 | size_t thread_concurrency; 60 | size_t shaders; 61 | #endif 62 | struct timeval tv_gpustart; 63 | int intervals; 64 | 65 | #ifdef HAVE_ADL 66 | bool has_adl; 67 | struct gpu_adl adl; 68 | 69 | int gpu_engine; 70 | int min_engine; 71 | int gpu_fan; 72 | int min_fan; 73 | int gpu_memclock; 74 | int gpu_memdiff; 75 | int gpu_powertune; 76 | float gpu_vddc; 77 | #endif 78 | 79 | #ifdef HAVE_SENSORS 80 | const sensors_chip_name *sensor; 81 | #endif 82 | }; 83 | 84 | extern float opencl_proc_get_intensity(struct cgpu_info *, const char **iunit); 85 | extern unsigned long xintensity_to_oclthreads(double xintensity, cl_uint max_compute_units); 86 | extern bool opencl_set_intensity_from_str(struct cgpu_info *, const char *newvalue); 87 | 88 | #ifdef USE_SHA256D 89 | struct opencl_work_data { 90 | cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d; 91 | cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h; 92 | cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d; 93 | cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h; 94 | cl_uint merkle; cl_uint ntime; cl_uint nbits; 95 | cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15; 96 | cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2; 97 | cl_uint W16; cl_uint W17; cl_uint W2; 98 | cl_uint PreVal4; cl_uint T1; 99 | cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2; 100 | cl_uint PreVal4addT1; cl_uint T1substate0; 101 | cl_uint PreVal4_2; 102 | cl_uint PreVal0; 103 | cl_uint PreW18; 104 | cl_uint PreW19; 105 | cl_uint PreW31; 106 | cl_uint PreW32; 107 | 108 | /* For diakgcn */ 109 | cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17; 110 | cl_uint zeroA, zeroB; 111 | cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA; 112 | }; 113 | #endif 114 | 115 | extern void opencl_early_init(); 116 | extern char *print_ndevs_and_exit(int *ndevs); 117 | extern void *reinit_gpu(void *userdata); 118 | extern char *set_gpu_map(char *arg); 119 | extern const char *set_gpu_engine(char *arg); 120 | extern const char *set_gpu_fan(char *arg); 121 | extern const char *set_gpu_memclock(char *arg); 122 | extern const char *set_gpu_memdiff(char *arg); 123 | extern const char *set_gpu_powertune(char *arg); 124 | extern const char *set_gpu_threads(char *arg); 125 | extern const char *set_gpu_vddc(char *arg); 126 | extern const char *set_temp_overheat(char *arg); 127 | extern const char *set_intensity(char *arg); 128 | extern const char *set_vector(char *arg); 129 | extern const char *set_worksize(char *arg); 130 | #ifdef USE_SCRYPT 131 | extern const char *set_shaders(char *arg); 132 | extern const char *set_lookup_gap(char *arg); 133 | extern const char *set_thread_concurrency(char *arg); 134 | #endif 135 | extern enum cl_kernels select_kernel(const char *); 136 | extern const char *opencl_get_kernel_interface_name(const enum cl_kernels); 137 | extern const char *opencl_get_default_kernel_filename(const enum cl_kernels); 138 | extern const char *set_kernel(char *arg); 139 | extern void write_config_opencl(FILE *); 140 | void manage_gpu(void); 141 | extern void opencl_dynamic_cleanup(); 142 | extern void pause_dynamic_threads(int gpu); 143 | 144 | extern bool have_opencl; 145 | extern int opt_platform_id; 146 | extern bool opt_opencl_binaries; 147 | 148 | extern struct device_drv opencl_api; 149 | 150 | #endif /* __DEVICE_GPU_H__ */ 151 | -------------------------------------------------------------------------------- /driver-proxy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include "deviceapi.h" 19 | #include "driver-proxy.h" 20 | #include "miner.h" 21 | #include "util.h" 22 | 23 | BFG_REGISTER_DRIVER(proxy_drv) 24 | static const struct bfg_set_device_definition proxy_set_device_funcs[]; 25 | 26 | static 27 | struct proxy_client *proxy_clients; 28 | static 29 | pthread_mutex_t proxy_clients_mutex = PTHREAD_MUTEX_INITIALIZER; 30 | 31 | static 32 | void prune_worklog() 33 | { 34 | struct proxy_client *client, *tmp; 35 | struct work *work, *tmp2; 36 | struct timeval tv_now; 37 | 38 | timer_set_now(&tv_now); 39 | 40 | mutex_lock(&proxy_clients_mutex); 41 | HASH_ITER(hh, proxy_clients, client, tmp) 42 | { 43 | HASH_ITER(hh, client->work, work, tmp2) 44 | { 45 | if (timer_elapsed(&work->tv_work_start, &tv_now) <= opt_expiry) 46 | break; 47 | HASH_DEL(client->work, work); 48 | free_work(work); 49 | } 50 | } 51 | mutex_unlock(&proxy_clients_mutex); 52 | } 53 | 54 | static 55 | pthread_t prune_worklog_pth; 56 | 57 | static 58 | void *prune_worklog_thread(void *userdata) 59 | { 60 | struct cgpu_info *cgpu = userdata; 61 | 62 | pthread_detach(pthread_self()); 63 | RenameThread("PXY_pruner"); 64 | 65 | while (!cgpu->shutdown) 66 | { 67 | prune_worklog(); 68 | sleep(60); 69 | } 70 | return NULL; 71 | } 72 | 73 | static 74 | float proxy_min_nonce_diff(struct cgpu_info * const proc, const struct mining_algorithm * const malgo) 75 | { 76 | return minimum_pdiff; 77 | } 78 | 79 | static 80 | void proxy_first_client(struct cgpu_info *cgpu) 81 | { 82 | pthread_create(&prune_worklog_pth, NULL, prune_worklog_thread, cgpu); 83 | } 84 | 85 | struct proxy_client *proxy_find_or_create_client(const char *username) 86 | { 87 | struct proxy_client *client; 88 | struct cgpu_info *cgpu; 89 | char *user; 90 | int b; 91 | 92 | if (!username) 93 | return NULL; 94 | 95 | mutex_lock(&proxy_clients_mutex); 96 | HASH_FIND_STR(proxy_clients, username, client); 97 | if (!client) 98 | { 99 | user = strdup(username); 100 | cgpu = malloc(sizeof(*cgpu)); 101 | client = malloc(sizeof(*client)); 102 | *cgpu = (struct cgpu_info){ 103 | .drv = &proxy_drv, 104 | .set_device_funcs = proxy_set_device_funcs, 105 | .threads = 0, 106 | .device_data = client, 107 | .device_path = user, 108 | }; 109 | timer_set_now(&cgpu->cgminer_stats.start_tv); 110 | if (unlikely(!create_new_cgpus(add_cgpu_live, cgpu))) 111 | { 112 | free(client); 113 | free(cgpu); 114 | free(user); 115 | return NULL; 116 | } 117 | *client = (struct proxy_client){ 118 | .username = user, 119 | .cgpu = cgpu, 120 | .desired_share_pdiff = 0., 121 | }; 122 | 123 | b = HASH_COUNT(proxy_clients); 124 | HASH_ADD_KEYPTR(hh, proxy_clients, client->username, strlen(user), client); 125 | mutex_unlock(&proxy_clients_mutex); 126 | 127 | if (!b) 128 | proxy_first_client(cgpu); 129 | 130 | cgpu_set_defaults(cgpu); 131 | } 132 | else 133 | { 134 | mutex_unlock(&proxy_clients_mutex); 135 | cgpu = client->cgpu; 136 | } 137 | thread_reportin(cgpu->thr[0]); 138 | return client; 139 | } 140 | 141 | // See also, stratumsrv_init_diff in driver-stratum.c 142 | static 143 | const char *proxy_set_diff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const success) 144 | { 145 | struct proxy_client * const client = proc->device_data; 146 | double nv = atof(newvalue); 147 | if (nv < 0) 148 | return "Invalid difficulty"; 149 | 150 | if (nv <= minimum_pdiff) 151 | nv = minimum_pdiff; 152 | client->desired_share_pdiff = nv; 153 | 154 | #ifdef USE_LIBEVENT 155 | stratumsrv_client_changed_diff(client); 156 | #endif 157 | 158 | return NULL; 159 | } 160 | 161 | #ifdef HAVE_CURSES 162 | static 163 | void proxy_wlogprint_status(struct cgpu_info *cgpu) 164 | { 165 | struct proxy_client *client = cgpu->device_data; 166 | wlogprint("Username: %s\n", client->username); 167 | } 168 | #endif 169 | 170 | static const struct bfg_set_device_definition proxy_set_device_funcs[] = { 171 | {"diff", proxy_set_diff, "desired share difficulty for clients"}, 172 | {NULL}, 173 | }; 174 | 175 | struct device_drv proxy_drv = { 176 | .dname = "proxy", 177 | .name = "PXY", 178 | .drv_min_nonce_diff = proxy_min_nonce_diff, 179 | #ifdef HAVE_CURSES 180 | .proc_wlogprint_status = proxy_wlogprint_status, 181 | #endif 182 | }; 183 | -------------------------------------------------------------------------------- /driver-proxy.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_PROXY_H 2 | #define BFG_DRIVER_PROXY_H 3 | 4 | #include 5 | 6 | #include "miner.h" 7 | 8 | #ifdef USE_LIBEVENT 9 | struct stratumsrv_conn_userlist; 10 | #endif 11 | 12 | extern struct device_drv proxy_drv; 13 | 14 | struct proxy_client { 15 | char *username; 16 | struct cgpu_info *cgpu; 17 | struct work *work; 18 | struct timeval tv_hashes_done; 19 | float desired_share_pdiff; 20 | 21 | #ifdef USE_LIBEVENT 22 | struct stratumsrv_conn_userlist *stratumsrv_connlist; 23 | #endif 24 | 25 | UT_hash_handle hh; 26 | }; 27 | 28 | extern struct proxy_client *proxy_find_or_create_client(const char *user); 29 | 30 | #ifdef USE_LIBEVENT 31 | extern void stratumsrv_client_changed_diff(struct proxy_client *); 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /driver-twinfury.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_DRIVER_TWINFURY_H 2 | #define BFG_DRIVER_TWINFURY_H 3 | 4 | #define BPM_BAUD 115200 5 | 6 | #define NUM_BITFURY_CHIPS 2 7 | 8 | struct twinfury_identity 9 | { 10 | uint8_t version; 11 | char product[16]; 12 | char serial[23]; 13 | } __attribute__((packed)); 14 | 15 | struct twinfury_state 16 | { 17 | uint8_t chip; 18 | uint8_t state; 19 | uint8_t switched; 20 | uint32_t nonce; 21 | } __attribute__((packed)); 22 | 23 | struct twinfury_info 24 | { 25 | uint32_t baud; 26 | 27 | struct work *prev_work; 28 | struct work *work; 29 | bool work_sent; 30 | struct twinfury_identity id; 31 | 32 | uint8_t tx_buffer[46]; 33 | uint8_t rx_buffer[1024]; 34 | int16_t rx_len; 35 | 36 | uint32_t voltage; 37 | bool send_voltage; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /dynclock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Luke Dashjr 3 | * Copyright 2012 nelisky 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 3 of the License, or (at your option) 8 | * any later version. See COPYING for more details. 9 | */ 10 | 11 | #include "config.h" 12 | 13 | #include 14 | #include 15 | 16 | #include "dynclock.h" 17 | #include "miner.h" 18 | 19 | void dclk_prepare(struct dclk_data *data) 20 | { 21 | *data = (struct dclk_data){ 22 | // after 275 sample periods 23 | .minGoodSamples = 150., 24 | .freqMinM = 1, 25 | }; 26 | } 27 | 28 | void dclk_msg_freqchange(const char *repr, int oldFreq, int newFreq, const char *tail) 29 | { 30 | applog(LOG_NOTICE, "%"PRIpreprv": Frequency %s from %u to %u MHz%s", 31 | repr, 32 | (oldFreq > newFreq ? "dropped" : "raised "), 33 | oldFreq, newFreq, 34 | tail ?: "" 35 | ); 36 | } 37 | 38 | bool dclk_updateFreq(struct dclk_data *data, dclk_change_clock_func_t changeclock, struct thr_info *thr) 39 | { 40 | struct cgpu_info *cgpu = thr->cgpu; 41 | uint8_t freqMDefault = data->freqMDefault; 42 | int i, maxM, bestM; 43 | double bestR, r; 44 | bool rv = true; 45 | 46 | if (freqMDefault > data->freqMaxM) 47 | // This occurs when the device in question adjusts its MaxM down due to temperature or similar reasons 48 | freqMDefault = data->freqMaxM; 49 | 50 | for (i = 0; i < data->freqMaxM; i++) 51 | if (data->maxErrorRate[i + 1] * i < data->maxErrorRate[i] * (i + 20)) 52 | data->maxErrorRate[i + 1] = data->maxErrorRate[i] * (1.0 + 20.0 / i); 53 | 54 | maxM = 0; 55 | // Use max mulitplier up to the default as far as possible without hitting the max error rate 56 | while (maxM < freqMDefault && data->maxErrorRate[maxM + 1] < DCLK_MAXMAXERRORRATE) 57 | maxM++; 58 | // Use max mulitplier beyond the default if it's never hit the max error rate, and our current max has collected sufficient samples 59 | while (maxM < data->freqMaxM && data->maxErrorRate[maxM + 1] < DCLK_MAXMAXERRORRATE && data->errorWeight[maxM] >= data->minGoodSamples) 60 | maxM++; 61 | 62 | // Find the multiplier that gives the best hashrate 63 | bestM = data->freqMinM; 64 | bestR = 0; 65 | for (i = bestM; i <= maxM; i++) { 66 | // Hashrate is weighed on a linear scale 67 | r = (i + 1); 68 | 69 | // The currently selected frequency gets a small "bonus" in comparison, as hysteresis 70 | if (i == data->freqM) 71 | r += DCLK_ERRORHYSTERESIS; 72 | 73 | // Adjust for measured error rate 74 | r *= (1 - data->maxErrorRate[i]); 75 | 76 | // If it beats the current best, update best* 77 | if (r > bestR) { 78 | bestM = i; 79 | bestR = r; 80 | } 81 | } 82 | 83 | // Actually change the clock if the best multiplier is not currently selected 84 | if (bestM != data->freqM) { 85 | rv = changeclock(thr, bestM); 86 | } 87 | 88 | // Find the highest multiplier that we've taken a reasonable sampling of 89 | maxM = freqMDefault; 90 | while (maxM < data->freqMaxM && data->errorWeight[maxM + 1] > 100) 91 | maxM++; 92 | // If the new multiplier is some fraction of the highest we've used long enough to get a good sample, assume there is something wrong and instruct the driver to shut it off 93 | if ((bestM < (1.0 - DCLK_OVERHEATTHRESHOLD) * maxM) && bestM < maxM - 1) { 94 | applog(LOG_ERR, "%"PRIpreprv": frequency drop of %.1f%% detect. This may be caused by overheating. FPGA is shut down to prevent damage.", 95 | cgpu->proc_repr, 96 | (1.0 - 1.0 * bestM / maxM) * 100); 97 | return false; 98 | } 99 | return rv; 100 | } 101 | 102 | void dclk_gotNonces(struct dclk_data *data) 103 | { 104 | data->errorCount[data->freqM] *= 0.995; 105 | data->errorWeight[data->freqM] = data->errorWeight[data->freqM] * 0.995 + 1.0; 106 | } 107 | 108 | void dclk_errorCount(struct dclk_data *data, double portion) 109 | { 110 | data->errorCount[data->freqM] += portion; 111 | } 112 | 113 | void dclk_preUpdate(struct dclk_data *data) 114 | { 115 | data->errorRate[data->freqM] = data->errorCount[data->freqM] / data->errorWeight[data->freqM]; 116 | // errorWeight 100 begins after sample period 137; before then, we minimize the effect of measured errorRate 117 | if (data->errorWeight[data->freqM] < 100) 118 | data->errorRate[data->freqM] /= 100; 119 | 120 | if (data->errorRate[data->freqM] > data->maxErrorRate[data->freqM]) 121 | data->maxErrorRate[data->freqM] = data->errorRate[data->freqM]; 122 | } 123 | -------------------------------------------------------------------------------- /dynclock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2013 Luke Dashjr 3 | * Copyright 2012 nelisky 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 3 of the License, or (at your option) 8 | * any later version. See COPYING for more details. 9 | */ 10 | 11 | #ifndef DYNCLOCK_H 12 | #define DYNCLOCK_H 13 | 14 | #include 15 | #include 16 | 17 | struct thr_info; 18 | 19 | #define DCLK_MAXMAXERRORRATE 0.05 20 | #define DCLK_ERRORHYSTERESIS 0.1 21 | #define DCLK_OVERHEATTHRESHOLD 0.4 22 | 23 | struct dclk_data { 24 | // Current frequency multiplier 25 | uint8_t freqM; 26 | 27 | // Minimum frequency multiplier to consider (set by driver) 28 | uint8_t freqMinM; 29 | 30 | // Maximum frequency multiplier to consider (set by driver) 31 | uint8_t freqMaxM; 32 | 33 | // "Default" frequency multiplier to work with (set by driver) 34 | uint8_t freqMDefault; 35 | 36 | // Threshold before errorWeight is considered reasonably constant 37 | // NOTE: This is not a mere number of sampling periods (but related) 38 | uint8_t minGoodSamples; 39 | 40 | // Numerator of errorWeight after dclk_errorCount 41 | double errorCount[256]; 42 | 43 | // Approaches 200 44 | double errorWeight[256]; 45 | 46 | // Error rate (0.0 - 1.0) as of end of last sampling period 47 | double errorRate[256]; 48 | 49 | // Highest error rate (0.0 - 1.0) encountered 50 | double maxErrorRate[256]; 51 | }; 52 | 53 | typedef bool (*dclk_change_clock_func_t)(struct thr_info *, int multiplier); 54 | 55 | // Standard applog message called by driver frequency-change functions 56 | extern void dclk_msg_freqchange(const char *, int oldFreq, int newFreq, const char *tail); 57 | 58 | // Called to initialize dclk_data at startup 59 | extern void dclk_prepare(struct dclk_data *data); 60 | 61 | // Called to start a sampling period 62 | extern void dclk_gotNonces(struct dclk_data *); 63 | 64 | // Called to increment the current sampling period's error rate (1.0 "portion" is 100% errors) 65 | extern void dclk_errorCount(struct dclk_data *, double portion); 66 | 67 | // Called after a sampling period is completed to update actual error rate 68 | extern void dclk_preUpdate(struct dclk_data *data); 69 | 70 | // Called after a sampling period is completed, and error rate updated, to make actual clock adjustments 71 | extern bool dclk_updateFreq(struct dclk_data *, dclk_change_clock_func_t changeclock, struct thr_info *); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /example.conf: -------------------------------------------------------------------------------- 1 | { 2 | "pools" : [ 3 | { 4 | "url" : "http://url1:8332", 5 | "user" : "user1", 6 | "pass" : "pass1" 7 | }, 8 | { 9 | "url" : "http://url2:8344", 10 | "pool-proxy" : "socks5://127.0.0.1:1080", 11 | "user" : "user2", 12 | "pass" : "pass2" 13 | }, 14 | { 15 | "url" : "http://url3:8332", 16 | "user" : "user3", 17 | "pass" : "pass3" 18 | } 19 | ], 20 | 21 | "intensity" : "d,9,9,9", 22 | "gpu-engine" : "0-985,0-950,0-960,0-1000", 23 | "gpu-fan" : "0-85,0-85,0-85,0-85", 24 | "gpu-memclock" : "860,825,835,875", 25 | "gpu-powertune" : "20,20,20,20", 26 | "temp-cutoff" : "95,95,95,95", 27 | "temp-overheat" : "85,85,85,85", 28 | "temp-target" : "75,75,75,75", 29 | 30 | "auto-fan" : true, 31 | "auto-gpu" : true, 32 | "expiry" : 120, 33 | "failover-only" : true, 34 | "gpu-threads" : 2, 35 | "log" : 5, 36 | "queue" : 1, 37 | "scan-time" : 60, 38 | "temp-hysteresis" : 3, 39 | 40 | "scan-serial" : [ 41 | "/dev/ttyUSB0", 42 | "/dev/ttyUSB1", 43 | "/dev/ttyUSB2", 44 | "/dev/ttyUSB3" 45 | ], 46 | 47 | "kernel-path" : "/usr/local/bin" 48 | } 49 | -------------------------------------------------------------------------------- /findnonce.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_FINDNONCE_H 2 | #define BFG_FINDNONCE_H 3 | 4 | #include 5 | 6 | #include "driver-opencl.h" 7 | #include "miner.h" 8 | #include "config.h" 9 | 10 | #define MAXTHREADS (0xFFFFFFFEULL) 11 | #define MAXBUFFERS (0x10) 12 | #define BUFFERSIZE (sizeof(uint32_t) * MAXBUFFERS) 13 | #define FOUND (0x0F) 14 | 15 | #ifdef USE_SCRYPT 16 | #define SCRYPT_MAXBUFFERS (0x100) 17 | #define SCRYPT_BUFFERSIZE (sizeof(uint32_t) * SCRYPT_MAXBUFFERS) 18 | #define SCRYPT_FOUND (0xFF) 19 | 20 | #define OPENCL_MAX_BUFFERSIZE SCRYPT_BUFFERSIZE 21 | #else 22 | #define OPENCL_MAX_BUFFERSIZE BUFFERSIZE 23 | #endif 24 | 25 | #ifdef USE_SHA256D 26 | extern void precalc_hash(struct opencl_work_data *blk, uint32_t *state, uint32_t *data); 27 | #endif 28 | extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res, enum cl_kernels); 29 | 30 | #endif /*__FINDNONCE_H__*/ 31 | -------------------------------------------------------------------------------- /gc3355.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Nate Woolls 3 | * Copyright 2014 GridSeed Team 4 | * Copyright 2014 Dualminer Team 5 | * Copyright 2014 Luke Dashjr 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 3 of the License, or (at your option) 10 | * any later version. See COPYING for more details. 11 | */ 12 | 13 | #ifndef bfgminer_gc3355_h 14 | #define bfgminer_gc3355_h 15 | 16 | #include 17 | #include 18 | 19 | #include "miner.h" 20 | 21 | // options configurable by the end-user 22 | 23 | extern int opt_sha2_units; 24 | 25 | extern 26 | int opt_pll_freq; 27 | 28 | // GridSeed common code begins here 29 | 30 | #define GC3355_ORB_DEFAULT_CHIPS 5 31 | #define GC3355_BLADE_DEFAULT_CHIPS 40 32 | #define GC3355_READ_SIZE 12 33 | 34 | struct gc3355_info 35 | { 36 | uint16_t freq; 37 | unsigned chips; 38 | }; 39 | 40 | #define gc3355_open(path) serial_open(path, 115200, 1, true) 41 | #define gc3355_close(fd) serial_close(fd) 42 | 43 | extern ssize_t gc3355_read(int fd, char *buf, size_t size); 44 | extern ssize_t gc3355_write(int fd, const void * const buf, const size_t size); 45 | 46 | extern void gc3355_init_miner(int fd, int pll_freq); 47 | extern void gc3355_init_dualminer(int fd, int pll_freq, bool scrypt_only, bool detect_only, bool scrypt); 48 | 49 | extern void gc3355_scrypt_reset(int fd); 50 | extern void gc3355_scrypt_only_reset(int fd); 51 | 52 | extern void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *); 53 | extern void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *); 54 | 55 | extern int64_t gc3355_get_firmware_version(int fd); 56 | extern void gc3355_set_pll_freq(int fd, int pll_freq); 57 | 58 | #define gc3355_get_cts_status(fd) ((get_serial_cts(fd) == BGV_LOW) ? 1 : 0) 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /gen-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | gitdesc= 3 | if [ -e .git ]; then 4 | # Some versions of git require `git diff` to scan and update dirty-or-not status 5 | git diff >/dev/null 2>/dev/null 6 | 7 | gitdesc=$(git describe) 8 | fi 9 | if [ -z "$gitdesc" ]; then 10 | current=$(sed 's/^\#define[[:space:]]\+BFG_GIT_DESCRIBE[[:space:]]\+\"\(.*\)\"$/\1/;t;d' version.h) 11 | if [ -z "$current" ]; then 12 | gitdesc='"PACKAGE_VERSION"-unknown' 13 | else 14 | gitdesc="$current" 15 | fi 16 | fi 17 | version=$(echo "$gitdesc" | sed 's/^bfgminer-//') 18 | cat < 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #ifndef WIN32 23 | #include 24 | #include 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #include "logging.h" 31 | #include "miner.h" 32 | #include "util.h" 33 | 34 | static struct MHD_Daemon *httpsrv; 35 | 36 | extern int handle_getwork(struct MHD_Connection *, bytes_t *); 37 | 38 | void httpsrv_prepare_resp(struct MHD_Response *resp) 39 | { 40 | MHD_add_response_header(resp, MHD_HTTP_HEADER_SERVER, bfgminer_name_slash_ver); 41 | } 42 | 43 | static 44 | int httpsrv_handle_req(struct MHD_Connection *conn, const char *url, const char *method, bytes_t *upbuf) 45 | { 46 | return handle_getwork(conn, upbuf); 47 | } 48 | 49 | static 50 | #if MHD_VERSION < 0x00097002 51 | int 52 | #else 53 | enum MHD_Result 54 | #endif 55 | httpsrv_handle_access(void *cls, struct MHD_Connection *conn, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) 56 | { 57 | bytes_t *upbuf; 58 | 59 | if (!*con_cls) 60 | { 61 | *con_cls = upbuf = malloc(sizeof(bytes_t)); 62 | bytes_init(upbuf); 63 | return MHD_YES; 64 | } 65 | 66 | upbuf = *con_cls; 67 | if (*upload_data_size) 68 | { 69 | bytes_append(upbuf, upload_data, *upload_data_size); 70 | *upload_data_size = 0; 71 | return MHD_YES; 72 | } 73 | return httpsrv_handle_req(conn, url, method, *con_cls); 74 | } 75 | 76 | static 77 | void httpsrv_cleanup_request(void *cls, struct MHD_Connection *conn, void **con_cls, enum MHD_RequestTerminationCode toe) 78 | { 79 | if (*con_cls) 80 | { 81 | bytes_t *upbuf = *con_cls; 82 | bytes_free(upbuf); 83 | free(upbuf); 84 | *con_cls = NULL; 85 | } 86 | } 87 | 88 | static 89 | void httpsrv_log(void *arg, const char *fmt, va_list ap) 90 | { 91 | if (!opt_debug) 92 | return; 93 | 94 | char tmp42[LOGBUFSIZ] = "HTTPSrv: "; 95 | vsnprintf(&tmp42[9], sizeof(tmp42)-9, fmt, ap); 96 | _applog(LOG_DEBUG, tmp42); 97 | } 98 | 99 | void httpsrv_start(unsigned short port) 100 | { 101 | httpsrv = MHD_start_daemon( 102 | MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 103 | port, NULL, NULL, 104 | &httpsrv_handle_access, NULL, 105 | MHD_OPTION_NOTIFY_COMPLETED, &httpsrv_cleanup_request, NULL, 106 | MHD_OPTION_EXTERNAL_LOGGER, &httpsrv_log, NULL, 107 | MHD_OPTION_END); 108 | if (httpsrv) 109 | applog(LOG_NOTICE, "HTTP server listening on port %d", (int)port); 110 | else 111 | applog(LOG_ERR, "Failed to start HTTP server on port %d", (int)port); 112 | } 113 | 114 | void httpsrv_stop() 115 | { 116 | if (!httpsrv) 117 | return; 118 | 119 | applog(LOG_DEBUG, "Stopping HTTP server"); 120 | MHD_stop_daemon(httpsrv); 121 | httpsrv = NULL; 122 | } 123 | -------------------------------------------------------------------------------- /httpsrv.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_HTTPSRV_H 2 | #define BFG_HTTPSRV_H 3 | 4 | #include 5 | 6 | extern void httpsrv_start(unsigned short port); 7 | extern void httpsrv_prepare_resp(struct MHD_Response *); 8 | extern void httpsrv_stop(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /iospeeds.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | IOSPEED(57600) 4 | IOSPEED(115200) 5 | IOSPEED(230400) 6 | IOSPEED(460800) 7 | IOSPEED(921600) 8 | 9 | IOSPEED(576000) 10 | IOSPEED(1152000) 11 | 12 | IOSPEED(1500000) 13 | IOSPEED(3000000) 14 | 15 | IOSPEED(500000) 16 | IOSPEED(1000000) 17 | IOSPEED(2000000) 18 | IOSPEED(4000000) 19 | 20 | IOSPEED(2500000) 21 | IOSPEED(3500000) 22 | -------------------------------------------------------------------------------- /iospeeds_posix.h: -------------------------------------------------------------------------------- 1 | IOSPEED(0) 2 | IOSPEED(50) 3 | IOSPEED(110) 4 | IOSPEED(134) 5 | IOSPEED(200) 6 | 7 | IOSPEED(75) 8 | IOSPEED(150) 9 | IOSPEED(300) 10 | IOSPEED(600) 11 | IOSPEED(1200) 12 | IOSPEED(1800) 13 | IOSPEED(2400) 14 | IOSPEED(4800) 15 | IOSPEED(9600) 16 | IOSPEED(19200) 17 | IOSPEED(38400) 18 | -------------------------------------------------------------------------------- /jtag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef BFGMINER_JTAG_H 11 | #define BFGMINER_JTAG_H 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | struct jtag_port_a { 18 | struct ft232r_device_handle *ftdi; 19 | uint8_t state; 20 | bool async; 21 | uint8_t bufread; 22 | }; 23 | 24 | struct jtag_port { 25 | struct jtag_port_a *a; 26 | uint8_t tck; 27 | uint8_t tms; 28 | uint8_t tdi; 29 | uint8_t tdo; 30 | uint8_t ignored; 31 | }; 32 | 33 | enum jtagreg { 34 | JTAG_REG_DR, 35 | JTAG_REG_IR, 36 | }; 37 | 38 | extern bool jtag_clock(struct jtag_port *, bool tms, bool tdi, bool *tdo); 39 | extern bool _jtag_llrw(struct jtag_port *, void *buf, size_t bitlength, bool do_read, int stage); 40 | extern bool jtag_reset(struct jtag_port *); 41 | extern ssize_t jtag_detect(struct jtag_port *); 42 | extern bool _jtag_rw(struct jtag_port *, enum jtagreg r, void *buf, size_t bitlength, bool do_read, int stage); 43 | #define jtag_read(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 0xff) 44 | #define jtag_sread(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 1) 45 | #define jtag_sread_more(jp, data, bitlen, finish) _jtag_llrw(jp, data, bitlen, true, (finish) ? 2 : 0) 46 | // Cast is used to accept const data - while it ignores the compiler attribute, it still won't modify the data 47 | #define jtag_write(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 0xff) 48 | #define jtag_swrite(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 1) 49 | #define jtag_swrite_more(jp, data, bitlen, finish) _jtag_llrw(jp, (void*)data, bitlen, false, (finish) ? 2 : 0) 50 | extern bool jtag_run(struct jtag_port *); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /lib/dummy.c: -------------------------------------------------------------------------------- 1 | /* A dummy file, to prevent empty libraries from breaking builds. 2 | Copyright (C) 2004, 2007, 2009-2011 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . */ 16 | 17 | /* Some systems, reportedly OpenBSD and Mac OS X, refuse to create 18 | libraries without any object files. You might get an error like: 19 | 20 | > ar cru .libs/libgl.a 21 | > ar: no archive members specified 22 | 23 | Compiling this file, and adding its object file to the library, will 24 | prevent the library from being empty. */ 25 | 26 | /* Some systems, such as Solaris with cc 5.0, refuse to work with libraries 27 | that don't export any symbol. You might get an error like: 28 | 29 | > cc ... libgnu.a 30 | > ild: (bad file) garbled symbol table in archive ../gllib/libgnu.a 31 | 32 | Compiling this file, and adding its object file to the library, will 33 | prevent the library from exporting no symbols. */ 34 | 35 | #ifdef __sun 36 | /* This declaration ensures that the library will export at least 1 symbol. */ 37 | int gl_dummy_symbol; 38 | #else 39 | /* This declaration is solely to ensure that after preprocessing 40 | this file is never empty. */ 41 | typedef int dummy; 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/memchr.valgrind: -------------------------------------------------------------------------------- 1 | # Suppress a valgrind message about use of uninitialized memory in memchr(). 2 | # POSIX states that when the character is found, memchr must not read extra 3 | # bytes in an overestimated length (for example, where memchr is used to 4 | # implement strnlen). However, we use a safe word read to provide a speedup. 5 | { 6 | memchr-value4 7 | Memcheck:Value4 8 | fun:rpl_memchr 9 | } 10 | { 11 | memchr-value8 12 | Memcheck:Value8 13 | fun:rpl_memchr 14 | } 15 | -------------------------------------------------------------------------------- /lib/memmem.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2011 Free Software 2 | Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | /* This particular implementation was written by Eric Blake, 2008. */ 20 | 21 | #ifndef _LIBC 22 | # include 23 | #endif 24 | 25 | /* Specification of memmem. */ 26 | #include 27 | 28 | #ifndef _LIBC 29 | # define __builtin_expect(expr, val) (expr) 30 | #endif 31 | 32 | #define RETURN_TYPE void * 33 | #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l)) 34 | #include "str-two-way.h" 35 | 36 | /* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK 37 | if NEEDLE_LEN is 0, otherwise NULL if NEEDLE is not found in 38 | HAYSTACK. */ 39 | void * 40 | memmem (const void *haystack_start, size_t haystack_len, 41 | const void *needle_start, size_t needle_len) 42 | { 43 | /* Abstract memory is considered to be an array of 'unsigned char' values, 44 | not an array of 'char' values. See ISO C 99 section 6.2.6.1. */ 45 | const unsigned char *haystack = (const unsigned char *) haystack_start; 46 | const unsigned char *needle = (const unsigned char *) needle_start; 47 | 48 | if (needle_len == 0) 49 | /* The first occurrence of the empty string is deemed to occur at 50 | the beginning of the string. */ 51 | return (void *) haystack; 52 | 53 | /* Sanity check, otherwise the loop might search through the whole 54 | memory. */ 55 | if (__builtin_expect (haystack_len < needle_len, 0)) 56 | return NULL; 57 | 58 | /* Use optimizations in memchr when possible, to reduce the search 59 | size of haystack using a linear algorithm with a smaller 60 | coefficient. However, avoid memchr for long needles, since we 61 | can often achieve sublinear performance. */ 62 | if (needle_len < LONG_NEEDLE_THRESHOLD) 63 | { 64 | haystack = memchr (haystack, *needle, haystack_len); 65 | if (!haystack || __builtin_expect (needle_len == 1, 0)) 66 | return (void *) haystack; 67 | haystack_len -= haystack - (const unsigned char *) haystack_start; 68 | if (haystack_len < needle_len) 69 | return NULL; 70 | return two_way_short_needle (haystack, haystack_len, needle, needle_len); 71 | } 72 | else 73 | return two_way_long_needle (haystack, haystack_len, needle, needle_len); 74 | } 75 | 76 | #undef LONG_NEEDLE_THRESHOLD 77 | -------------------------------------------------------------------------------- /lib/sig-handler.h: -------------------------------------------------------------------------------- 1 | /* Convenience declarations when working with . 2 | 3 | Copyright (C) 2008-2011 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | #ifndef _GL_SIG_HANDLER_H 19 | #define _GL_SIG_HANDLER_H 20 | 21 | #include 22 | 23 | /* Convenience type when working with signal handlers. */ 24 | typedef void (*sa_handler_t) (int); 25 | 26 | /* Return the handler of a signal, as a sa_handler_t value regardless 27 | of its true type. The resulting function can be compared to 28 | special values like SIG_IGN but it is not portable to call it. */ 29 | static inline sa_handler_t 30 | get_handler (struct sigaction const *a) 31 | { 32 | #ifdef SA_SIGINFO 33 | /* POSIX says that special values like SIG_IGN can only occur when 34 | action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4, 35 | for example, sa_sigaction and sa_handler are aliases and a signal 36 | is ignored if sa_sigaction (after casting) equals SIG_IGN. So 37 | use (and cast) sa_sigaction in that case. */ 38 | if (a->sa_flags & SA_SIGINFO) 39 | return (sa_handler_t) a->sa_sigaction; 40 | #endif 41 | return a->sa_handler; 42 | } 43 | 44 | #endif /* _GL_SIG_HANDLER_H */ 45 | -------------------------------------------------------------------------------- /lib/stddef.in.h: -------------------------------------------------------------------------------- 1 | /* A substitute for POSIX 2008 , for platforms that have issues. 2 | 3 | Copyright (C) 2009-2011 Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | /* Written by Eric Blake. */ 20 | 21 | /* 22 | * POSIX 2008 for platforms that have issues. 23 | * 24 | */ 25 | 26 | #if __GNUC__ >= 3 27 | @PRAGMA_SYSTEM_HEADER@ 28 | #endif 29 | @PRAGMA_COLUMNS@ 30 | 31 | #if defined __need_wchar_t || defined __need_size_t \ 32 | || defined __need_ptrdiff_t || defined __need_NULL \ 33 | || defined __need_wint_t 34 | /* Special invocation convention inside gcc header files. In 35 | particular, gcc provides a version of that blindly 36 | redefines NULL even when __need_wint_t was defined, even though 37 | wint_t is not normally provided by . Hence, we must 38 | remember if special invocation has ever been used to obtain wint_t, 39 | in which case we need to clean up NULL yet again. */ 40 | 41 | # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) 42 | # ifdef __need_wint_t 43 | # undef _@GUARD_PREFIX@_STDDEF_H 44 | # define _GL_STDDEF_WINT_T 45 | # endif 46 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 47 | # endif 48 | 49 | #else 50 | /* Normal invocation convention. */ 51 | 52 | # ifndef _@GUARD_PREFIX@_STDDEF_H 53 | 54 | /* The include_next requires a split double-inclusion guard. */ 55 | 56 | # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 57 | 58 | # ifndef _@GUARD_PREFIX@_STDDEF_H 59 | # define _@GUARD_PREFIX@_STDDEF_H 60 | 61 | /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 62 | #if @REPLACE_NULL@ 63 | # undef NULL 64 | # ifdef __cplusplus 65 | /* ISO C++ says that the macro NULL must expand to an integer constant 66 | expression, hence '((void *) 0)' is not allowed in C++. */ 67 | # if __GNUG__ >= 3 68 | /* GNU C++ has a __null macro that behaves like an integer ('int' or 69 | 'long') but has the same size as a pointer. Use that, to avoid 70 | warnings. */ 71 | # define NULL __null 72 | # else 73 | # define NULL 0L 74 | # endif 75 | # else 76 | # define NULL ((void *) 0) 77 | # endif 78 | #endif 79 | 80 | /* Some platforms lack wchar_t. */ 81 | #if !@HAVE_WCHAR_T@ 82 | # define wchar_t int 83 | #endif 84 | 85 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ 86 | # endif /* _@GUARD_PREFIX@_STDDEF_H */ 87 | #endif /* __need_XXX */ 88 | -------------------------------------------------------------------------------- /lib/strtok_r.c: -------------------------------------------------------------------------------- 1 | /* Reentrant string tokenizer. Generic version. 2 | Copyright (C) 1991, 1996-1999, 2001, 2004, 2007, 2009-2011 Free Software 3 | Foundation, Inc. 4 | This file is part of the GNU C Library. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | # include 21 | #endif 22 | 23 | #include 24 | 25 | #ifdef _LIBC 26 | # undef strtok_r 27 | # undef __strtok_r 28 | #else 29 | # define __strtok_r strtok_r 30 | # define __rawmemchr strchr 31 | #endif 32 | 33 | /* Parse S into tokens separated by characters in DELIM. 34 | If S is NULL, the saved pointer in SAVE_PTR is used as 35 | the next starting point. For example: 36 | char s[] = "-abc-=-def"; 37 | char *sp; 38 | x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" 39 | x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL 40 | x = strtok_r(NULL, "=", &sp); // x = NULL 41 | // s = "abc\0-def\0" 42 | */ 43 | char * 44 | __strtok_r (char *s, const char *delim, char **save_ptr) 45 | { 46 | char *token; 47 | 48 | if (s == NULL) 49 | s = *save_ptr; 50 | 51 | /* Scan leading delimiters. */ 52 | s += strspn (s, delim); 53 | if (*s == '\0') 54 | { 55 | *save_ptr = s; 56 | return NULL; 57 | } 58 | 59 | /* Find the end of the token. */ 60 | token = s; 61 | s = strpbrk (token, delim); 62 | if (s == NULL) 63 | /* This token finishes the string. */ 64 | *save_ptr = __rawmemchr (token, '\0'); 65 | else 66 | { 67 | /* Terminate the token and make *SAVE_PTR point past it. */ 68 | *s = '\0'; 69 | *save_ptr = s + 1; 70 | } 71 | return token; 72 | } 73 | #ifdef weak_alias 74 | libc_hidden_def (__strtok_r) 75 | weak_alias (__strtok_r, strtok_r) 76 | #endif 77 | -------------------------------------------------------------------------------- /libbitfury.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LIBBITFURY_H 2 | #define BFG_LIBBITFURY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "lowl-spi.h" 8 | #include "miner.h" 9 | 10 | struct work; 11 | 12 | #define BITFURY_STAT_N 1024 13 | 14 | struct bitfury_payload { 15 | uint8_t midstate[32]; 16 | uint32_t junk[8]; 17 | uint32_t m7; 18 | uint32_t ntime; 19 | uint32_t nbits; 20 | uint32_t nnonce; 21 | }; 22 | 23 | struct freq_stat { 24 | double *mh; 25 | double *s; 26 | int osc6_min; 27 | int osc6_max; 28 | double omh; 29 | double os; 30 | int best_osc; 31 | int best_done; 32 | }; 33 | 34 | struct bitfury_device { 35 | struct spi_port *spi; 36 | uint8_t osc6_bits; 37 | uint32_t newbuf[17]; 38 | uint32_t oldbuf[17]; 39 | bool oldjob; 40 | int active; 41 | int chipgen; 42 | int chipgen_probe; 43 | uint32_t atrvec[20]; 44 | struct bitfury_payload payload; 45 | struct freq_stat chip_stat; 46 | struct timeval timer1; 47 | struct timeval tv_stat; 48 | uint32_t counter1, counter2; 49 | double mhz; 50 | int mhz_last; 51 | int mhz_best; 52 | uint32_t slot; 53 | unsigned fasync; 54 | unsigned strange_counter; 55 | bool force_reinit; 56 | int desync_counter; 57 | int sample_hwe; 58 | int sample_tot; 59 | }; 60 | 61 | extern void work_to_bitfury_payload(struct bitfury_payload *, struct work *); 62 | extern void bitfury_payload_to_atrvec(uint32_t *atrvec, struct bitfury_payload *); 63 | extern void bitfury_send_reinit(struct spi_port *, int slot, int chip_n, int n); 64 | extern void bitfury_send_shutdown(struct spi_port *, int slot, int chip_n); 65 | extern void bitfury_send_freq(struct spi_port *, int slot, int chip_n, int bits); 66 | extern int libbitfury_detectChips1(struct spi_port *); 67 | extern uint32_t bitfury_decnonce(uint32_t); 68 | extern bool bitfury_fudge_nonce(const void *midstate, const uint32_t m7, const uint32_t ntime, const uint32_t nbits, uint32_t *nonce_p); 69 | 70 | #endif /* __LIBBITFURY_H__ */ 71 | -------------------------------------------------------------------------------- /libztex.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LIBZTEX_H 2 | #define BFG_LIBZTEX_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "dynclock.h" 10 | 11 | #define LIBZTEX_MAX_DESCRIPTORS 512 12 | #define LIBZTEX_SNSTRING_LEN 10 13 | 14 | #define LIBZTEX_IDVENDOR 0x221A 15 | #define LIBZTEX_IDPRODUCT 0x0100 16 | 17 | struct libztex_fpgastate { 18 | bool fpgaConfigured; 19 | unsigned char fpgaChecksum; 20 | uint16_t fpgaBytes; 21 | unsigned char fpgaInitB; 22 | unsigned char fpgaFlashResult; 23 | bool fpgaFlashBitSwap; 24 | }; 25 | 26 | struct libztex_device { 27 | pthread_mutex_t mutex; 28 | struct libztex_device *root; 29 | struct libusb_device_descriptor descriptor; 30 | libusb_device_handle *hndl; 31 | unsigned char usbbus; 32 | unsigned char usbaddress; 33 | char *dev_manufacturer; 34 | char *dev_product; 35 | unsigned char snString[LIBZTEX_SNSTRING_LEN+1]; 36 | unsigned char productId[4]; 37 | unsigned char fwVersion; 38 | unsigned char interfaceVersion; 39 | unsigned char interfaceCapabilities[6]; 40 | unsigned char moduleReserved[12]; 41 | uint8_t numNonces; 42 | uint16_t offsNonces; 43 | double freqM1; 44 | char* bitFileName; 45 | bool suspendSupported; 46 | double hashesPerClock; 47 | uint8_t extraSolutions; 48 | 49 | struct dclk_data dclk; 50 | 51 | int16_t numberOfFpgas; 52 | int handles; 53 | int selectedFpga; 54 | bool parallelConfigSupport; 55 | 56 | char repr[20]; 57 | }; 58 | 59 | struct libztex_dev_list { 60 | struct libztex_device *dev; 61 | struct libztex_dev_list *next; 62 | }; 63 | 64 | struct libztex_hash_data { 65 | uint32_t goldenNonce[2]; 66 | uint32_t nonce; 67 | uint32_t hash7; 68 | }; 69 | 70 | enum ztex_check_result 71 | { 72 | CHECK_ERROR, 73 | CHECK_IS_NOT_ZTEX, 74 | CHECK_OK, 75 | CHECK_RESCAN, 76 | }; 77 | 78 | extern int libztex_scanDevices (struct libztex_dev_list ***devs); 79 | extern void libztex_freeDevList (struct libztex_dev_list **devs); 80 | extern enum ztex_check_result libztex_checkDevice(struct libusb_device *); 81 | extern struct libztex_device *libztex_prepare_device2(struct libusb_device *); 82 | extern void libztex_destroy_device (struct libztex_device* ztex); 83 | extern int libztex_configureFpga (struct libztex_device *dev, const char *repr); 84 | extern int libztex_setFreq (struct libztex_device *ztex, uint16_t freq, const char *repr); 85 | extern int libztex_sendHashData (struct libztex_device *ztex, unsigned char *sendbuf); 86 | extern int libztex_readHashData (struct libztex_device *ztex, struct libztex_hash_data nonces[]); 87 | extern int libztex_resetFpga (struct libztex_device *ztex); 88 | extern int libztex_selectFpga(struct libztex_device *ztex, int16_t fpgaNum); 89 | extern int libztex_numberOfFpgas(struct libztex_device *ztex); 90 | 91 | #endif /* __LIBZTEX_H__ */ 92 | -------------------------------------------------------------------------------- /logging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2013 Con Kolivas 3 | * Copyright 2012-2014 Luke Dashjr 4 | * Copyright 2013 Andrew Smith 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 3 of the License, or (at your option) 9 | * any later version. See COPYING for more details. 10 | */ 11 | 12 | #include "config.h" 13 | 14 | #include 15 | #include 16 | 17 | #include "compat.h" 18 | #include "logging.h" 19 | #include "miner.h" 20 | 21 | bool opt_debug = false; 22 | bool opt_debug_console = false; // Only used if opt_debug is also enabled 23 | bool opt_log_output = false; 24 | bool opt_log_microseconds; 25 | 26 | /* per default priorities higher than LOG_NOTICE are logged */ 27 | int opt_log_level = LOG_NOTICE; 28 | 29 | static void _my_log_curses(int prio, const char *datetime, const char *str) 30 | { 31 | #ifdef HAVE_CURSES 32 | extern bool use_curses; 33 | if (use_curses && _log_curses_only(prio, datetime, str)) 34 | ; 35 | else 36 | #endif 37 | { 38 | last_logstatusline_len = -1; 39 | printf("\n %s %s\r", datetime, str); 40 | fflush(stdout); 41 | } 42 | } 43 | 44 | /* high-level logging function, based on global opt_log_level */ 45 | 46 | /* 47 | * log function 48 | */ 49 | void _applog(int prio, const char *str) 50 | { 51 | #ifdef HAVE_SYSLOG_H 52 | if (use_syslog) { 53 | syslog(prio, "%s", str); 54 | } 55 | #else 56 | if (0) {} 57 | #endif 58 | else { 59 | bool writetocon = 60 | (opt_debug_console || (opt_log_output && prio != LOG_DEBUG) || prio <= LOG_NOTICE) 61 | && !(opt_quiet && prio != LOG_ERR); 62 | bool writetofile = !isatty(fileno((FILE *)stderr)); 63 | if (!(writetocon || writetofile)) 64 | return; 65 | 66 | char datetime[64]; 67 | 68 | if (opt_log_microseconds) 69 | { 70 | struct timeval tv; 71 | struct tm tm; 72 | 73 | bfg_gettimeofday(&tv); 74 | localtime_r(&tv.tv_sec, &tm); 75 | 76 | snprintf(datetime, sizeof(datetime), "[%d-%02d-%02d %02d:%02d:%02d.%06ld]", 77 | tm.tm_year + 1900, 78 | tm.tm_mon + 1, 79 | tm.tm_mday, 80 | tm.tm_hour, 81 | tm.tm_min, 82 | tm.tm_sec, 83 | (long)tv.tv_usec); 84 | } 85 | else 86 | get_now_datestamp(datetime, sizeof(datetime)); 87 | 88 | if (writetofile || writetocon) 89 | { 90 | bfg_console_lock(); 91 | 92 | /* Only output to stderr if it's not going to the screen as well */ 93 | if (writetofile) { 94 | fprintf(stderr, " %s %s\n", datetime, str); /* atomic write to stderr */ 95 | fflush(stderr); 96 | } 97 | 98 | if (writetocon) 99 | _my_log_curses(prio, datetime, str); 100 | 101 | bfg_console_unlock(); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 Luke Dashjr 3 | * Copyright 2012 zefir 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 3 of the License, or (at your option) 8 | * any later version. See COPYING for more details. 9 | */ 10 | 11 | #ifndef BFG_LOGGING_H 12 | #define BFG_LOGGING_H 13 | 14 | #include "config.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifdef HAVE_SYSLOG_H 22 | #include 23 | #else 24 | enum { 25 | LOG_ERR, 26 | LOG_WARNING, 27 | LOG_NOTICE, 28 | LOG_INFO, 29 | LOG_DEBUG, 30 | }; 31 | #endif 32 | 33 | #include "util.h" 34 | 35 | /* debug flags */ 36 | extern bool opt_debug; 37 | extern bool opt_debug_console; 38 | extern bool opt_log_output; 39 | extern bool opt_log_microseconds; 40 | extern bool opt_realquiet; 41 | extern bool want_per_device_stats; 42 | 43 | /* global log_level, messages with lower or equal prio are logged */ 44 | extern int opt_log_level; 45 | 46 | #define return_via(label, stmt) do { \ 47 | stmt; \ 48 | goto label; \ 49 | } while (0) 50 | 51 | #define LOGBUFSIZ 0x1000 52 | 53 | extern void _applog(int prio, const char *str); 54 | 55 | #define IN_FMT_FFL " in %s %s():%d" 56 | 57 | #define applog(prio, fmt, ...) do { \ 58 | if (opt_debug || (prio) != LOG_DEBUG) { \ 59 | char tmp42[LOGBUFSIZ]; \ 60 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 61 | _applog(prio, tmp42); \ 62 | } \ 63 | } while (0) 64 | 65 | #define applogsiz(prio, _SIZ, fmt, ...) do { \ 66 | if (opt_debug || (prio) != LOG_DEBUG) { \ 67 | char tmp42[_SIZ]; \ 68 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 69 | _applog(prio, tmp42); \ 70 | } \ 71 | } while (0) 72 | 73 | #define applogr(rv, prio, ...) do { \ 74 | applog(prio, __VA_ARGS__); \ 75 | return rv; \ 76 | } while (0) 77 | 78 | #define return_via_applog(label, expr, prio, ...) do { \ 79 | applog(prio, __VA_ARGS__); \ 80 | expr; \ 81 | goto label; \ 82 | } while (0) 83 | 84 | #define appperror(prio, s) do { \ 85 | const char *_tmp43 = bfg_strerror(errno, BST_ERRNO); \ 86 | if (s && s[0]) \ 87 | applog(prio, "%s: %s", s, _tmp43); \ 88 | else \ 89 | _applog(prio, _tmp43); \ 90 | } while (0) 91 | 92 | #define perror(s) appperror(LOG_ERR, s) 93 | 94 | #define applogfailinfo(prio, failed, fmt, ...) do { \ 95 | applog(prio, "Failed to %s"IN_FMT_FFL": "fmt, \ 96 | failed, \ 97 | __FILE__, __func__, __LINE__, \ 98 | __VA_ARGS__); \ 99 | } while (0) 100 | 101 | #define applogfailinfor(rv, prio, failed, fmt, ...) do { \ 102 | applogfailinfo(prio, failed, fmt, __VA_ARGS__); \ 103 | return rv; \ 104 | } while (0) 105 | 106 | #define return_via_applogfailinfo(label, expr, prio, failed, fmt, ...) do { \ 107 | applogfailinfo(prio, failed, fmt, __VA_ARGS__); \ 108 | expr; \ 109 | goto label; \ 110 | } while (0) 111 | 112 | #define applogfail(prio, failed) do { \ 113 | applog(prio, "Failed to %s"IN_FMT_FFL, \ 114 | failed, \ 115 | __FILE__, __func__, __LINE__); \ 116 | } while (0) 117 | 118 | #define applogfailr(rv, prio, failed) do { \ 119 | applogfail(prio, failed); \ 120 | return rv; \ 121 | } while (0) 122 | 123 | #define return_via_applogfail(label, expr, prio, failed) do { \ 124 | applogfail(prio, failed); \ 125 | expr; \ 126 | goto label; \ 127 | } while (0) 128 | 129 | extern void _bfg_clean_up(bool); 130 | 131 | #define quit(status, fmt, ...) do { \ 132 | _bfg_clean_up(false); \ 133 | if (fmt) { \ 134 | fprintf(stderr, "\n" fmt, ##__VA_ARGS__); \ 135 | } \ 136 | fflush(stderr); \ 137 | _quit(status); \ 138 | } while (0) 139 | 140 | #define quithere(status, fmt, ...) do { \ 141 | if (fmt) { \ 142 | char tmp42[LOGBUFSIZ]; \ 143 | snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \ 144 | ##__VA_ARGS__, __FILE__, __func__, __LINE__); \ 145 | _applog(LOG_ERR, tmp42); \ 146 | } \ 147 | _quit(status); \ 148 | } while (0) 149 | 150 | #define quitfrom(status, _file, _func, _line, fmt, ...) do { \ 151 | if (fmt) { \ 152 | char tmp42[LOGBUFSIZ]; \ 153 | snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \ 154 | ##__VA_ARGS__, _file, _func, _line); \ 155 | _applog(LOG_ERR, tmp42); \ 156 | } \ 157 | _quit(status); \ 158 | } while (0) 159 | 160 | #ifdef HAVE_CURSES 161 | 162 | #define wlog(fmt, ...) do { \ 163 | char tmp42[LOGBUFSIZ]; \ 164 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 165 | _wlog(tmp42); \ 166 | } while (0) 167 | 168 | #define wlogprint(fmt, ...) do { \ 169 | char tmp42[LOGBUFSIZ]; \ 170 | snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \ 171 | _wlogprint(tmp42); \ 172 | } while (0) 173 | 174 | #endif 175 | 176 | #endif /* __LOGGING_H__ */ 177 | -------------------------------------------------------------------------------- /lowl-ftdi.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_FTDI_H 2 | #define BFG_LOWL_FTDI_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "lowlevel.h" 10 | 11 | enum ft232r_reset_purge { 12 | FTDI_PURGE_RX = 1, 13 | FTDI_PURGE_TX = 2, 14 | FTDI_PURGE_BOTH = 3, 15 | }; 16 | 17 | struct ft232r_device_handle; 18 | 19 | extern struct ft232r_device_handle *ft232r_open(const struct lowlevel_device_info *); 20 | extern struct ft232r_device_handle *ft232h_open_mpsse(const struct lowlevel_device_info *); 21 | extern void ft232r_close(struct ft232r_device_handle *); 22 | extern bool ft232r_purge_buffers(struct ft232r_device_handle *, enum ft232r_reset_purge); 23 | extern bool ft232r_set_bitmode(struct ft232r_device_handle *, uint8_t mask, uint8_t mode); 24 | extern ssize_t ft232r_flush(struct ft232r_device_handle *); 25 | extern ssize_t ft232r_write(struct ft232r_device_handle *, const void *data, size_t count); 26 | extern ssize_t ft232r_write_all(struct ft232r_device_handle *, const void *data, size_t count); 27 | extern ssize_t ft232r_read(struct ft232r_device_handle *, void *buf, size_t count); 28 | extern ssize_t ft232r_read_all(struct ft232r_device_handle *, void *data, size_t count); 29 | extern bool ft232r_get_pins(struct ft232r_device_handle *, uint8_t *pins); 30 | extern bool ft232r_set_cbus_bits(struct ft232r_device_handle *dev, bool sc, bool cs); 31 | extern bool ft232r_get_cbus_bits(struct ft232r_device_handle *dev, bool *out_sio0, bool *out_sio1); 32 | extern bool ft232h_mpsse_set_axbus(struct ft232r_device_handle *, uint8_t value, uint8_t directions, bool adbus); 33 | #define ft232h_mpsse_set_acbus(ftdi, val, dir) ft232h_mpsse_set_axbus(ftdi, val, dir, false) 34 | #define ft232h_mpsse_set_adbus(ftdi, val, dir) ft232h_mpsse_set_axbus(ftdi, val, dir, true) 35 | extern ssize_t ft232h_mpsse_readwrite_all(struct ft232r_device_handle *, void *read_data, const void *write_data, size_t count); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lowl-hid.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_HID_H 2 | #define BFG_LOWL_HID_H 3 | 4 | #include 5 | 6 | #ifdef WIN32 7 | #define HID_API_EXPORT __declspec(dllexport) 8 | #else 9 | #define HID_API_EXPORT /* */ 10 | #endif 11 | extern struct hid_device_info HID_API_EXPORT *(*dlsym_hid_enumerate)(unsigned short, unsigned short); 12 | extern void HID_API_EXPORT (*dlsym_hid_free_enumeration)(struct hid_device_info *); 13 | extern hid_device * HID_API_EXPORT (*dlsym_hid_open_path)(const char *); 14 | extern void HID_API_EXPORT (*dlsym_hid_close)(hid_device *); 15 | extern int HID_API_EXPORT (*dlsym_hid_read)(hid_device *, unsigned char *, size_t); 16 | extern int HID_API_EXPORT (*dlsym_hid_write)(hid_device *, const unsigned char *, size_t); 17 | 18 | #define hid_enumerate dlsym_hid_enumerate 19 | #define hid_free_enumeration dlsym_hid_free_enumeration 20 | #define hid_open_path dlsym_hid_open_path 21 | #define hid_close dlsym_hid_close 22 | #define hid_read dlsym_hid_read 23 | #define hid_write dlsym_hid_write 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lowl-mswin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "logging.h" 23 | #include "lowlevel.h" 24 | #include "lowl-mswin.h" 25 | #include "util.h" 26 | 27 | static 28 | struct lowlevel_device_info *mswin_devinfo_scan() 29 | { 30 | struct lowlevel_device_info *devinfo_list = NULL, *info; 31 | 32 | HDEVINFO devinfo = SetupDiGetClassDevs(NULL, NULL, NULL, (DIGCF_ALLCLASSES | DIGCF_DEVICEINTERFACE | DIGCF_PRESENT)); 33 | if (INVALID_HANDLE_VALUE == devinfo) 34 | applogfailinfor(NULL, LOG_DEBUG, "SetupDiGetClassDevs", "%s", bfg_strerror(GetLastError(), BST_SYSTEM)); 35 | 36 | SP_DEVINFO_DATA devinfodata = { 37 | .cbSize = sizeof(devinfodata), 38 | }; 39 | SP_DEVICE_INTERFACE_DATA devifacedata = { 40 | .cbSize = sizeof(devifacedata), 41 | }; 42 | for (int i = 0; SetupDiEnumDeviceInfo(devinfo, i, &devinfodata); ++i) 43 | { 44 | // FIXME: Figure out a way to get all GUIDs here 45 | if (!SetupDiEnumDeviceInterfaces(devinfo, &devinfodata, &WIN_GUID_DEVINTERFACE_MonarchKMDF, 0, &devifacedata)) 46 | { 47 | applogfailinfo(LOG_DEBUG, "SetupDiEnumDeviceInterfaces", "%s", bfg_strerror(GetLastError(), BST_SYSTEM)); 48 | continue; 49 | } 50 | DWORD detailsz; 51 | if (!(!SetupDiGetDeviceInterfaceDetail(devinfo, &devifacedata, NULL, 0, &detailsz, NULL) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)) 52 | { 53 | applogfailinfo(LOG_ERR, "SetupDiEnumDeviceInterfaceDetail (1)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM)); 54 | continue; 55 | } 56 | PSP_DEVICE_INTERFACE_DETAIL_DATA detail = alloca(detailsz); 57 | detail->cbSize = sizeof(*detail); 58 | if (!SetupDiGetDeviceInterfaceDetail(devinfo, &devifacedata, detail, detailsz, &detailsz, NULL)) 59 | { 60 | applogfailinfo(LOG_ERR, "SetupDiEnumDeviceInterfaceDetail (2)", "%s", bfg_strerror(GetLastError(), BST_SYSTEM)); 61 | continue; 62 | } 63 | 64 | char *devid = malloc(6 + strlen(detail->DevicePath) + 1); 65 | sprintf(devid, "mswin:%s", detail->DevicePath); 66 | 67 | info = malloc(sizeof(struct lowlevel_device_info)); 68 | *info = (struct lowlevel_device_info){ 69 | .lowl = &lowl_mswin, 70 | .devid = devid, 71 | .path = strdup(detail->DevicePath), 72 | .lowl_data = (void *)&WIN_GUID_DEVINTERFACE_MonarchKMDF, 73 | }; 74 | LL_PREPEND(devinfo_list, info); 75 | } 76 | 77 | SetupDiDestroyDeviceInfoList(devinfo); 78 | 79 | return devinfo_list; 80 | } 81 | 82 | bool lowl_mswin_match_guid(const struct lowlevel_device_info * const info, const GUID * const guid) 83 | { 84 | if (info->lowl != &lowl_mswin) 85 | return false; 86 | return IsEqualGUID(info->lowl_data, guid); 87 | } 88 | 89 | struct lowlevel_driver lowl_mswin = { 90 | .dname = "mswin", 91 | .devinfo_scan = mswin_devinfo_scan, 92 | }; 93 | -------------------------------------------------------------------------------- /lowl-mswin.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_MSWIN_H 2 | #define BFG_LOWL_MSWIN_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | static const GUID WIN_GUID_DEVINTERFACE_MonarchKMDF = { 0xdcdb8d6f, 0x98b0, 0x4d1c, {0xa2, 0x77, 0x71, 0x17, 0x69, 0x70, 0x54, 0x31} }; 9 | 10 | extern bool lowl_mswin_match_guid(const struct lowlevel_device_info *, const GUID *); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lowl-pci.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_PCI_H 2 | #define BFG_LOWL_PCI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct lowl_pci_handle; 11 | 12 | struct _lowl_pci_config { 13 | int bar; 14 | size_t sz; 15 | int mode; 16 | }; 17 | extern struct lowl_pci_handle *lowl_pci_open(const char *, const struct _lowl_pci_config *); 18 | #define LP_BARINFO(...) (struct _lowl_pci_config[]){__VA_ARGS__ { .bar = -1 }} 19 | #define LP_BAR(barno, size, mode) {barno, size, mode} 20 | extern void lowl_pci_close(struct lowl_pci_handle *); 21 | 22 | // Don't assume buf is used in any specific way! Memory returned may be mmap'd (and thus change after call) 23 | extern const uint32_t *lowl_pci_get_words(struct lowl_pci_handle *, void *buf, size_t words, int bar, off_t); 24 | extern bool lowl_pci_set_words(struct lowl_pci_handle *, const uint32_t *, size_t, int bar, off_t); 25 | // buf passed to lowl_pci_get_data must have at least LOWL_PCI_GET_DATA_PADDING bytes more than size to read 26 | #define LOWL_PCI_GET_DATA_PADDING 6 27 | extern const void *lowl_pci_get_data(struct lowl_pci_handle *, void *buf, size_t, int bar, off_t); 28 | extern bool lowl_pci_set_data(struct lowl_pci_handle *, const void *, size_t, int bar, off_t); 29 | 30 | static inline 31 | uint32_t lowl_pci_get_word(struct lowl_pci_handle * const lph, const int bar, const off_t offset) 32 | { 33 | uint32_t buf[1]; 34 | const uint32_t * const p = lowl_pci_get_words(lph, buf, 1, bar, offset); 35 | if (!p) 36 | return 0; 37 | return *p; 38 | } 39 | 40 | static inline 41 | bool lowl_pci_set_word(struct lowl_pci_handle * const lph, const int bar, const off_t offset, const uint32_t val) 42 | { 43 | return lowl_pci_set_words(lph, &val, 1, bar, offset); 44 | } 45 | 46 | static inline 47 | bool lowl_pci_read_words(struct lowl_pci_handle * const lph, void * const buf, const size_t words, const int bar, const off_t offset) 48 | { 49 | const void * const p = lowl_pci_get_words(lph, buf, words, bar, offset); 50 | if (!p) 51 | return false; 52 | if (buf != p) 53 | memmove(buf, p, words * 4); 54 | return true; 55 | } 56 | 57 | static inline 58 | bool lowl_pci_read_data(struct lowl_pci_handle * const lph, void * const buf, const size_t sz, const int bar, const off_t offset) 59 | { 60 | const void * const p = lowl_pci_get_data(lph, buf, sz, bar, offset); 61 | if (!p) 62 | return false; 63 | if (buf != p) 64 | memmove(buf, p, sz); 65 | return true; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /lowl-spi.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_SPI_H 2 | #define BFG_LOWL_SPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define SPIMAXSZ (256*1024) 9 | 10 | /* Initialize SPI using this function */ 11 | void spi_init(void); 12 | 13 | #ifdef HAVE_LINUX_SPI_SPIDEV_H 14 | extern void bfg_gpio_setpin_output(unsigned pin); 15 | extern void bfg_gpio_set_high(unsigned mask); 16 | extern void bfg_gpio_set_low(unsigned mask); 17 | extern unsigned bfg_gpio_get(); 18 | #endif 19 | 20 | /* Do not allocate spi_port on the stack! OS X, at least, has a 512 KB default stack size for secondary threads 21 | This includes struct assignments which get allocated on the stack before being assigned to */ 22 | struct spi_port { 23 | /* TX-RX single frame */ 24 | bool (*txrx)(struct spi_port *port); 25 | 26 | char spibuf[SPIMAXSZ], spibuf_rx[SPIMAXSZ]; 27 | size_t spibufsz; 28 | 29 | void *userp; 30 | struct cgpu_info *cgpu; 31 | const char *repr; 32 | int logprio; 33 | 34 | int fd; 35 | uint32_t speed; 36 | uint16_t delay; 37 | uint8_t mode; 38 | uint8_t bits; 39 | int chipselect; 40 | int *chipselect_current; 41 | }; 42 | 43 | extern struct spi_port *sys_spi; 44 | 45 | 46 | /* SPI BUFFER OPS */ 47 | static inline 48 | void spi_clear_buf(struct spi_port *port) 49 | { 50 | port->spibufsz = 0; 51 | } 52 | 53 | static inline 54 | void *spi_getrxbuf(struct spi_port *port) 55 | { 56 | return port->spibuf_rx; 57 | } 58 | 59 | static inline 60 | void *spi_gettxbuf(struct spi_port *port) 61 | { 62 | return port->spibuf; 63 | } 64 | 65 | static inline 66 | size_t spi_getbufsz(struct spi_port *port) 67 | { 68 | return port->spibufsz; 69 | } 70 | 71 | extern void spi_emit_buf(struct spi_port *, const void *, size_t); 72 | 73 | extern void spi_emit_break(struct spi_port *port); /* BREAK CONNECTIONS AFTER RESET */ 74 | extern void spi_emit_fsync(struct spi_port *port); /* FEED-THROUGH TO NEXT CHIP SYNCHRONOUSLY (WITH FLIP-FLOP) */ 75 | extern void spi_emit_fasync(struct spi_port *port, int n); /* FEED-THROUGH TO NEXT CHIP ASYNCHRONOUSLY (WITHOUT FLIP-FLOP INTERMEDIATE) */ 76 | extern void spi_emit_nop(struct spi_port *port, int n); 77 | 78 | /* TRANSMIT PROGRAMMING SEQUENCE (AND ALSO READ-BACK) */ 79 | /* addr is the destination address in bits (16-bit - 0 to 0xFFFF valid ones) 80 | buf is buffer to be transmitted, it will go at position spi_getbufsz()+3 81 | len is length in _bytes_, should be 4 to 128 and be multiple of 4, as smallest 82 | transmission quantum is 32 bits */ 83 | extern void *spi_emit_data(struct spi_port *port, uint16_t addr, const void *buf, size_t len); 84 | 85 | static inline 86 | bool spi_txrx(struct spi_port *port) 87 | { 88 | return port->txrx(port); 89 | } 90 | 91 | extern int spi_open(struct spi_port *, const char *); 92 | extern bool sys_spi_txrx(struct spi_port *); 93 | extern bool linux_spi_txrx(struct spi_port *); 94 | extern bool linux_spi_txrx2(struct spi_port *); 95 | 96 | void spi_bfsb_select_bank(int bank); 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /lowl-usb.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_USB_H 2 | #define BFG_LOWL_USB_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr); 10 | #define bfg_make_devid_libusb(dev) bfg_make_devid_usb(libusb_get_bus_number(dev), libusb_get_device_address(dev)) 11 | #define bfg_claim_libusb(api, verbose, dev) bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev)) 12 | 13 | extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *); 14 | 15 | struct lowl_usb_endpoint; 16 | 17 | extern struct lowl_usb_endpoint *usb_open_ep(struct libusb_device_handle *, uint8_t epid, int pktsz); 18 | extern struct lowl_usb_endpoint *usb_open_ep_pair(struct libusb_device_handle *, uint8_t epid_r, int pktsz_r, uint8_t epid_w, int pktsz_w); 19 | extern void usb_ep_set_timeouts_ms(struct lowl_usb_endpoint *, unsigned timeout_ms_r, unsigned timeout_ms_w); 20 | extern ssize_t usb_read(struct lowl_usb_endpoint *, void *, size_t); 21 | extern ssize_t usb_write(struct lowl_usb_endpoint *, const void *, size_t); 22 | extern void usb_close_ep(struct lowl_usb_endpoint *); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lowl-vcom.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWL_VCOM_H 2 | #define BFG_LOWL_VCOM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "deviceapi.h" 10 | #include "util.h" 11 | 12 | struct device_drv; 13 | struct cgpu_info; 14 | 15 | struct detectone_meta_info_t { 16 | const char *manufacturer; 17 | const char *product; 18 | const char *serial; 19 | }; 20 | 21 | extern struct detectone_meta_info_t *_detectone_meta_info(); 22 | #define detectone_meta_info (*_detectone_meta_info()) 23 | extern void clear_detectone_meta_info(void); 24 | 25 | extern bool vcom_lowl_probe_wrapper(const struct lowlevel_device_info *, detectone_func_t); 26 | 27 | extern int _serial_autodetect(detectone_func_t, ...); 28 | #define serial_autodetect(...) _serial_autodetect(__VA_ARGS__, NULL) 29 | 30 | extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath); 31 | #define serial_claim(devpath, drv) bfg_claim_serial(drv, false, devpath) 32 | #define serial_claim_v(devpath, drv) bfg_claim_serial(drv, true , devpath) 33 | 34 | extern int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge); 35 | extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol); 36 | #define serial_read(fd, buf, count) \ 37 | _serial_read(fd, (char*)(buf), count, NULL) 38 | #define serial_read_line(fd, buf, bufsiz, eol) \ 39 | _serial_read(fd, buf, bufsiz, &eol) 40 | extern int serial_close(int fd); 41 | 42 | // NOTE: timeout_ms=0 means it never times out 43 | extern bool vcom_set_timeout_ms(int fd, unsigned timeout_ms); 44 | #define vcom_set_timeout(fd, timeout) vcom_set_timeout_ms(fd, (timeout) * 100) 45 | extern enum bfg_gpio_value get_serial_cts(int fd); 46 | extern enum bfg_gpio_value set_serial_dtr(int fd, enum bfg_gpio_value dtr); 47 | extern enum bfg_gpio_value set_serial_rts(int fd, enum bfg_gpio_value rts); 48 | extern bool valid_baud(int baud); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lowlevel.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_LOWLEVEL_H 2 | #define BFG_LOWLEVEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "miner.h" 11 | 12 | struct lowlevel_device_info; 13 | 14 | typedef bool (*lowl_found_devinfo_func_t)(struct lowlevel_device_info *, void *); 15 | 16 | struct lowlevel_driver { 17 | const char *dname; 18 | bool exclude_from_all; 19 | 20 | struct lowlevel_device_info *(*devinfo_scan)(); 21 | void (*devinfo_free)(struct lowlevel_device_info *); 22 | }; 23 | 24 | struct lowlevel_device_info { 25 | char *manufacturer; 26 | char *product; 27 | char *serial; 28 | char *path; 29 | char *devid; 30 | uint16_t vid; 31 | uint16_t pid; 32 | 33 | struct lowlevel_driver *lowl; 34 | void *lowl_data; 35 | 36 | struct lowlevel_device_info *next; 37 | struct lowlevel_device_info *same_devid_next; 38 | UT_hash_handle hh; 39 | pthread_t probe_pth; 40 | int ref; 41 | }; 42 | 43 | extern char *bfg_make_devid_usb(uint8_t usbbus, uint8_t usbaddr); 44 | 45 | extern struct lowlevel_device_info *lowlevel_scan(); 46 | extern bool _lowlevel_match_product(const struct lowlevel_device_info *, const char **); 47 | #define lowlevel_match_product(info, ...) \ 48 | _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL}) 49 | #define lowlevel_match_lowlproduct(info, matchlowl, ...) \ 50 | (matchlowl == info->lowl && _lowlevel_match_product(info, (const char *[]){__VA_ARGS__, NULL})) 51 | extern bool lowlevel_match_id(const struct lowlevel_device_info *, const struct lowlevel_driver *, int32_t vid, int32_t pid); 52 | extern int _lowlevel_detect(lowl_found_devinfo_func_t, const char *serial, const char **product_needles, void *); 53 | #define lowlevel_detect(func, ...) _lowlevel_detect(func, NULL, (const char *[]){__VA_ARGS__, NULL}, NULL) 54 | #define lowlevel_detect_serial(func, serial) _lowlevel_detect(func, serial, (const char *[]){NULL}, NULL) 55 | extern int lowlevel_detect_id(lowl_found_devinfo_func_t, void *, const struct lowlevel_driver *, int32_t vid, int32_t pid); 56 | extern void lowlevel_scan_free(); 57 | 58 | extern struct lowlevel_device_info *lowlevel_ref(const struct lowlevel_device_info *); 59 | #define lowlevel_claim(drv, verbose, info) \ 60 | bfg_claim_any(drv, (verbose) ? ((info)->path ?: "") : NULL, (info)->devid) 61 | extern void lowlevel_devinfo_semicpy(struct lowlevel_device_info *dst, const struct lowlevel_device_info *src); 62 | extern void lowlevel_devinfo_free(struct lowlevel_device_info *); 63 | 64 | #ifdef NEED_BFG_LOWL_FTDI 65 | extern struct lowlevel_driver lowl_ft232r; 66 | #endif 67 | #ifdef NEED_BFG_LOWL_HID 68 | extern struct lowlevel_driver lowl_hid; 69 | #endif 70 | #ifdef USE_NANOFURY 71 | extern struct lowlevel_driver lowl_mcp2210; 72 | #endif 73 | #ifdef NEED_BFG_LOWL_MSWIN 74 | extern struct lowlevel_driver lowl_mswin; 75 | #endif 76 | #ifdef NEED_BFG_LOWL_PCI 77 | extern struct lowlevel_driver lowl_pci; 78 | #endif 79 | #ifdef HAVE_LIBUSB 80 | extern struct lowlevel_driver lowl_usb; 81 | #else 82 | // Dummy definition for the various "don't warn if just a lower-level interface" checks 83 | static __maybe_unused struct lowlevel_driver lowl_usb; 84 | #endif 85 | #ifdef NEED_BFG_LOWL_VCOM 86 | extern struct lowlevel_driver lowl_vcom; 87 | #endif 88 | 89 | extern struct device_drv *bfg_claim_any(struct device_drv *, const char *verbose, const char *devpath); 90 | extern struct device_drv *bfg_claim_any2(struct device_drv *, const char *verbose, const char *llname, const char *path); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /m4/00gnulib.m4: -------------------------------------------------------------------------------- 1 | # 00gnulib.m4 serial 2 2 | dnl Copyright (C) 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl This file must be named something that sorts before all other 8 | dnl gnulib-provided .m4 files. It is needed until such time as we can 9 | dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics. 10 | 11 | # AC_DEFUN_ONCE([NAME], VALUE) 12 | # ---------------------------- 13 | # Define NAME to expand to VALUE on the first use (whether by direct 14 | # expansion, or by AC_REQUIRE), and to nothing on all subsequent uses. 15 | # Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This 16 | # definition is slower than the version in Autoconf 2.64, because it 17 | # can only use interfaces that existed since 2.59; but it achieves the 18 | # same effect. Quoting is necessary to avoid confusing Automake. 19 | m4_version_prereq([2.63.263], [], 20 | [m4_define([AC][_DEFUN_ONCE], 21 | [AC][_DEFUN([$1], 22 | [AC_REQUIRE([_gl_DEFUN_ONCE([$1])], 23 | [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl 24 | [AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])]) 25 | 26 | # gl_00GNULIB 27 | # ----------- 28 | # Witness macro that this file has been included. Needed to force 29 | # Automake to include this file prior to all other gnulib .m4 files. 30 | AC_DEFUN([gl_00GNULIB]) 31 | -------------------------------------------------------------------------------- /m4/bundled_lib.m4: -------------------------------------------------------------------------------- 1 | dnl * Copyright 2014 Luke Dashjr 2 | dnl * 3 | dnl * This program is free software; you can redistribute it and/or modify it 4 | dnl * under the terms of the GNU General Public License as published by the Free 5 | dnl * Software Foundation; either version 3 of the License, or (at your option) 6 | dnl * any later version. See COPYING for more details. 7 | 8 | m4_divert_text([DEFAULTS], [ 9 | origin_LDFLAGS= 10 | origin_LDFLAGS_checked=false 11 | maybe_ldconfig= 12 | maybe_ldconfig_checked=false 13 | BUNDLED_LIB_RULES= 14 | ]) 15 | 16 | AC_SUBST(BUNDLED_LIB_RULES) 17 | 18 | AC_DEFUN([BFG_CHECK_LD_ORIGIN],[ 19 | if ! $origin_LDFLAGS_checked; then 20 | save_LDFLAGS="$LDFLAGS" 21 | LDFLAGS="$LDFLAGS -Wl,-zorigin" 22 | AC_MSG_CHECKING([whether the linker recognizes the -zorigin option]) 23 | AC_TRY_LINK([],[],[ 24 | AC_MSG_RESULT([yes]) 25 | origin_LDFLAGS=',-zorigin' 26 | ],[ 27 | AC_MSG_RESULT([no]) 28 | ]) 29 | LDFLAGS="$save_LDFLAGS" 30 | origin_LDFLAGS_checked=true 31 | fi 32 | ]) 33 | 34 | AC_DEFUN([BFG_CHECK_LDCONFIG],[ 35 | if ! $maybe_ldconfig_checked; then 36 | _ROOTPATH=$PATH$PATH_SEPARATOR`echo $PATH | sed s/bin/sbin/g` 37 | possible_ldconfigs="${target}-ldconfig" 38 | if test "x$cross_compiling" != "xyes"; then 39 | possible_ldconfigs="${possible_ldconfigs} ldconfig" 40 | fi 41 | AC_CHECK_PROGS([LDCONFIG],[${possible_ldconfigs}],[],[$_ROOTPATH]) 42 | if test "x$LDCONFIG" != "x"; then 43 | maybe_ldconfig=" && $LDCONFIG" 44 | fi 45 | maybe_ldconfig_checked=true 46 | fi 47 | ]) 48 | 49 | AC_DEFUN([BFG_BUNDLED_LIB_VARS],[ 50 | BFG_CHECK_LD_ORIGIN 51 | _AC_SRCDIRS(["$ac_dir"]) 52 | $1_CFLAGS='-I'"${ac_abs_top_srcdir}"'/$2' 53 | $1_LIBS='-L'"${ac_abs_top_builddir}"'/$2/.libs -Wl,-rpath,\$$ORIGIN/$2/.libs'"$origin_LDFLAGS"' m4_foreach_w([mylib],[$3],[ -l[]mylib])' 54 | $1_SUBDIRS=$2 55 | $1_EXTRADEPS=$1_directory 56 | BUNDLED_LIB_RULES="$BUNDLED_LIB_RULES 57 | $1_directory: 58 | \$(MAKE) -C $2 59 | " 60 | AM_SUBST_NOTMAKE([BUNDLED_LIB_RULES]) 61 | if $have_cygwin; then 62 | $1_EXTRADEPS="$$1_EXTRADEPS m4_foreach_w([mylib],[$3],[ cyg[]mylib[]-0.dll])" 63 | BUNDLED_LIB_RULES="$BUNDLED_LIB_RULES[]m4_foreach_w([mylib],[$3],[ 64 | cyg[]mylib[]-%.dll: $2/.libs/cyg[]mylib[]-%.dll 65 | cp -p \$< \$[]@ 66 | ])" 67 | fi 68 | ]) 69 | 70 | dnl BFG_BUNDLED_LIB([PKG-NAME],PKGCONF-NAME],[DEFAULT:YES/NO/AUTO],[PATH],[LIBS],[DEPENDENT-PKGS],[CONFIGURE-ARGS],[CONFIGURE-ARGS]) 71 | AC_DEFUN([BFG_BUNDLED_LIB],[ 72 | AC_ARG_WITH([system-$1],[ifelse([$3],[no],AC_HELP_STRING([--with-system-$1], [Use system $1 rather than bundled one (default disabled)]),AC_HELP_STRING([--without-system-$1], [Use bundled $1 rather than system one]))],[true],[with_system_$1=$3]) 73 | if test "x$with_system_$1" != "xno"; then 74 | PKG_CHECK_MODULES([$1],[$2],[ 75 | with_system_$1=yes 76 | ],[ 77 | if test "x$with_system_$1" = "xyes"; then 78 | AC_MSG_ERROR([Could not find system $1]) 79 | else 80 | AC_MSG_NOTICE([Didn't find system $1, using bundled copy]) 81 | with_system_$1=no 82 | fi 83 | ]) 84 | fi 85 | if test "x$with_system_$1" = "xno"; then 86 | BFG_BUNDLED_LIB_VARS([$1],[$4],[$5]) 87 | BFG_CUSTOM_SUBDIR([$4],[$7],[$8 m4_foreach_w([mydep],[$6],[ mydep[]_LIBS='$mydep[]_LIBS' mydep[]_CFLAGS='$mydep[]_CFLAGS'])]) 88 | BFG_CHECK_LDCONFIG 89 | else 90 | $1_SUBDIRS= 91 | $1_EXTRADEPS= 92 | fi 93 | AC_SUBST($1_CFLAGS) 94 | AC_SUBST($1_LIBS) 95 | AC_SUBST($1_SUBDIRS) 96 | AC_SUBST($1_EXTRADEPS) 97 | AM_CONDITIONAL(NEED_[]m4_toupper([$1]), [test x$with_system_$1 != xyes]) 98 | ]) 99 | -------------------------------------------------------------------------------- /m4/custom_subdirs.m4: -------------------------------------------------------------------------------- 1 | dnl * Copyright 2014 Luke Dashjr 2 | dnl * 3 | dnl * This program is free software; you can redistribute it and/or modify it 4 | dnl * under the terms of the GNU General Public License as published by the Free 5 | dnl * Software Foundation; either version 3 of the License, or (at your option) 6 | dnl * any later version. See COPYING for more details. 7 | 8 | m4_divert_text([DEFAULTS], [ 9 | custom_subdirs= 10 | ]) 11 | 12 | AC_DEFUN([BFG_CUSTOM_SUBDIR],[ 13 | if false; then 14 | AC_CONFIG_SUBDIRS([$1]) 15 | fi 16 | custom_subdirs="$custom_subdirs $1" 17 | custom_subdir_[]AS_TR_SH([$1])_args="$2" 18 | custom_subdir_[]AS_TR_SH([$1])_forceargs="$3" 19 | ]) 20 | 21 | AC_DEFUN([BFG_CUSTOM_SUBDIRS_OUTPUT],[ 22 | if test "$no_recursion" != yes; then 23 | orig_subdirs="$subdirs" 24 | orig_ac_configure_args="$ac_configure_args" 25 | for custom_subdir in $custom_subdirs; do 26 | subdirs="$custom_subdir" 27 | custom_subdir_base="AS_TR_SH([$custom_subdir])" 28 | eval 'ac_configure_args="$custom_subdir_'"$custom_subdir_base"'_args $orig_ac_configure_args $custom_subdir_'"$custom_subdir_base"'_forceargs"' 29 | _AC_OUTPUT_SUBDIRS 30 | done 31 | subdirs="$orig_subdirs" 32 | ac_configure_args="$orig_ac_configure_args" 33 | fi 34 | ]) 35 | -------------------------------------------------------------------------------- /m4/extensions.m4: -------------------------------------------------------------------------------- 1 | # serial 9 -*- Autoconf -*- 2 | # Enable extensions on systems that normally disable them. 3 | 4 | # Copyright (C) 2003, 2006-2011 Free Software Foundation, Inc. 5 | # This file is free software; the Free Software Foundation 6 | # gives unlimited permission to copy and/or distribute it, 7 | # with or without modifications, as long as this notice is preserved. 8 | 9 | # This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS 10 | # Autoconf. Perhaps we can remove this once we can assume Autoconf 11 | # 2.62 or later everywhere, but since CVS Autoconf mutates rapidly 12 | # enough in this area it's likely we'll need to redefine 13 | # AC_USE_SYSTEM_EXTENSIONS for quite some time. 14 | 15 | # If autoconf reports a warning 16 | # warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS 17 | # or warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS 18 | # the fix is 19 | # 1) to ensure that AC_USE_SYSTEM_EXTENSIONS is never directly invoked 20 | # but always AC_REQUIREd, 21 | # 2) to ensure that for each occurrence of 22 | # AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 23 | # or 24 | # AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 25 | # the corresponding gnulib module description has 'extensions' among 26 | # its dependencies. This will ensure that the gl_USE_SYSTEM_EXTENSIONS 27 | # invocation occurs in gl_EARLY, not in gl_INIT. 28 | 29 | # AC_USE_SYSTEM_EXTENSIONS 30 | # ------------------------ 31 | # Enable extensions on systems that normally disable them, 32 | # typically due to standards-conformance issues. 33 | # Remember that #undef in AH_VERBATIM gets replaced with #define by 34 | # AC_DEFINE. The goal here is to define all known feature-enabling 35 | # macros, then, if reports of conflicts are made, disable macros that 36 | # cause problems on some platforms (such as __EXTENSIONS__). 37 | AC_DEFUN_ONCE([AC_USE_SYSTEM_EXTENSIONS], 38 | [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl 39 | AC_BEFORE([$0], [AC_RUN_IFELSE])dnl 40 | 41 | AC_REQUIRE([AC_CANONICAL_HOST]) 42 | 43 | AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) 44 | if test "$MINIX" = yes; then 45 | AC_DEFINE([_POSIX_SOURCE], [1], 46 | [Define to 1 if you need to in order for `stat' and other 47 | things to work.]) 48 | AC_DEFINE([_POSIX_1_SOURCE], [2], 49 | [Define to 2 if the system does not provide POSIX.1 features 50 | except with this defined.]) 51 | AC_DEFINE([_MINIX], [1], 52 | [Define to 1 if on MINIX.]) 53 | fi 54 | 55 | dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500, 56 | dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already 57 | dnl provided. 58 | case "$host_os" in 59 | hpux*) 60 | AC_DEFINE([_XOPEN_SOURCE], [500], 61 | [Define to 500 only on HP-UX.]) 62 | ;; 63 | esac 64 | 65 | AH_VERBATIM([__EXTENSIONS__], 66 | [/* Enable extensions on AIX 3, Interix. */ 67 | #ifndef _ALL_SOURCE 68 | # undef _ALL_SOURCE 69 | #endif 70 | /* Enable GNU extensions on systems that have them. */ 71 | #ifndef _GNU_SOURCE 72 | # undef _GNU_SOURCE 73 | #endif 74 | /* Enable threading extensions on Solaris. */ 75 | #ifndef _POSIX_PTHREAD_SEMANTICS 76 | # undef _POSIX_PTHREAD_SEMANTICS 77 | #endif 78 | /* Enable extensions on HP NonStop. */ 79 | #ifndef _TANDEM_SOURCE 80 | # undef _TANDEM_SOURCE 81 | #endif 82 | /* Enable general extensions on Solaris. */ 83 | #ifndef __EXTENSIONS__ 84 | # undef __EXTENSIONS__ 85 | #endif 86 | ]) 87 | AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], 88 | [ac_cv_safe_to_define___extensions__], 89 | [AC_COMPILE_IFELSE( 90 | [AC_LANG_PROGRAM([[ 91 | # define __EXTENSIONS__ 1 92 | ]AC_INCLUDES_DEFAULT])], 93 | [ac_cv_safe_to_define___extensions__=yes], 94 | [ac_cv_safe_to_define___extensions__=no])]) 95 | test $ac_cv_safe_to_define___extensions__ = yes && 96 | AC_DEFINE([__EXTENSIONS__]) 97 | AC_DEFINE([_ALL_SOURCE]) 98 | AC_DEFINE([_GNU_SOURCE]) 99 | AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 100 | AC_DEFINE([_TANDEM_SOURCE]) 101 | ])# AC_USE_SYSTEM_EXTENSIONS 102 | 103 | # gl_USE_SYSTEM_EXTENSIONS 104 | # ------------------------ 105 | # Enable extensions on systems that normally disable them, 106 | # typically due to standards-conformance issues. 107 | AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], 108 | [ 109 | dnl Require this macro before AC_USE_SYSTEM_EXTENSIONS. 110 | dnl gnulib does not need it. But if it gets required by third-party macros 111 | dnl after AC_USE_SYSTEM_EXTENSIONS is required, autoconf 2.62..2.63 emit a 112 | dnl warning: "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". 113 | dnl Note: We can do this only for one of the macros AC_AIX, AC_GNU_SOURCE, 114 | dnl AC_MINIX. If people still use AC_AIX or AC_MINIX, they are out of luck. 115 | AC_REQUIRE([AC_GNU_SOURCE]) 116 | 117 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 118 | ]) 119 | -------------------------------------------------------------------------------- /m4/gnulib-cache.m4: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2002-2011 Free Software Foundation, Inc. 2 | # 3 | # This file is free software, distributed under the terms of the GNU 4 | # General Public License. As a special exception to the GNU General 5 | # Public License, this file may be distributed as part of a program 6 | # that contains a configuration script generated by Autoconf, under 7 | # the same distribution terms as the rest of that program. 8 | # 9 | # Generated by gnulib-tool. 10 | # 11 | # This file represents the specification of how gnulib-tool is used. 12 | # It acts as a cache: It is written and read by gnulib-tool. 13 | # In projects that use version control, this file is meant to be put under 14 | # version control, like the configure.ac and various Makefile.am files. 15 | 16 | 17 | # Specification in the form of a command-line invocation: 18 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files memmem sigaction signal strtok_r 19 | 20 | # Specification in the form of a few gnulib-tool.m4 macro invocations: 21 | gl_LOCAL_DIR([]) 22 | gl_MODULES([ 23 | memmem 24 | sigaction 25 | signal 26 | strtok_r 27 | ]) 28 | gl_AVOID([]) 29 | gl_SOURCE_BASE([lib]) 30 | gl_M4_BASE([m4]) 31 | gl_PO_BASE([]) 32 | gl_DOC_BASE([doc]) 33 | gl_TESTS_BASE([tests]) 34 | gl_LIB([libgnu]) 35 | gl_MAKEFILE_NAME([]) 36 | gl_MACRO_PREFIX([gl]) 37 | gl_PO_DOMAIN([]) 38 | gl_WITNESS_C_DOMAIN([]) 39 | gl_VC_FILES([false]) 40 | -------------------------------------------------------------------------------- /m4/gnulib-tool.m4: -------------------------------------------------------------------------------- 1 | # gnulib-tool.m4 serial 2 2 | dnl Copyright (C) 2004-2005, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl The following macros need not be invoked explicitly. 8 | dnl Invoking them does nothing except to declare default arguments 9 | dnl for "gnulib-tool --import". 10 | 11 | dnl Usage: gl_LOCAL_DIR([DIR]) 12 | AC_DEFUN([gl_LOCAL_DIR], []) 13 | 14 | dnl Usage: gl_MODULES([module1 module2 ...]) 15 | AC_DEFUN([gl_MODULES], []) 16 | 17 | dnl Usage: gl_AVOID([module1 module2 ...]) 18 | AC_DEFUN([gl_AVOID], []) 19 | 20 | dnl Usage: gl_SOURCE_BASE([DIR]) 21 | AC_DEFUN([gl_SOURCE_BASE], []) 22 | 23 | dnl Usage: gl_M4_BASE([DIR]) 24 | AC_DEFUN([gl_M4_BASE], []) 25 | 26 | dnl Usage: gl_PO_BASE([DIR]) 27 | AC_DEFUN([gl_PO_BASE], []) 28 | 29 | dnl Usage: gl_DOC_BASE([DIR]) 30 | AC_DEFUN([gl_DOC_BASE], []) 31 | 32 | dnl Usage: gl_TESTS_BASE([DIR]) 33 | AC_DEFUN([gl_TESTS_BASE], []) 34 | 35 | dnl Usage: gl_WITH_TESTS 36 | AC_DEFUN([gl_WITH_TESTS], []) 37 | 38 | dnl Usage: gl_LIB([LIBNAME]) 39 | AC_DEFUN([gl_LIB], []) 40 | 41 | dnl Usage: gl_LGPL or gl_LGPL([VERSION]) 42 | AC_DEFUN([gl_LGPL], []) 43 | 44 | dnl Usage: gl_MAKEFILE_NAME([FILENAME]) 45 | AC_DEFUN([gl_MAKEFILE_NAME], []) 46 | 47 | dnl Usage: gl_LIBTOOL 48 | AC_DEFUN([gl_LIBTOOL], []) 49 | 50 | dnl Usage: gl_MACRO_PREFIX([PREFIX]) 51 | AC_DEFUN([gl_MACRO_PREFIX], []) 52 | 53 | dnl Usage: gl_PO_DOMAIN([DOMAIN]) 54 | AC_DEFUN([gl_PO_DOMAIN], []) 55 | 56 | dnl Usage: gl_VC_FILES([BOOLEAN]) 57 | AC_DEFUN([gl_VC_FILES], []) 58 | -------------------------------------------------------------------------------- /m4/memchr.m4: -------------------------------------------------------------------------------- 1 | # memchr.m4 serial 12 2 | dnl Copyright (C) 2002-2004, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN_ONCE([gl_FUNC_MEMCHR], 8 | [ 9 | dnl Check for prerequisites for memory fence checks. 10 | gl_FUNC_MMAP_ANON 11 | AC_CHECK_HEADERS_ONCE([sys/mman.h]) 12 | AC_CHECK_FUNCS_ONCE([mprotect]) 13 | 14 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 15 | m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [ 16 | dnl These days, we assume memchr is present. But if support for old 17 | dnl platforms is desired: 18 | AC_CHECK_FUNCS_ONCE([memchr]) 19 | if test $ac_cv_func_memchr = no; then 20 | HAVE_MEMCHR=0 21 | fi 22 | ]) 23 | if test $HAVE_MEMCHR = 1; then 24 | # Detect platform-specific bugs in some versions of glibc: 25 | # memchr should not dereference anything with length 0 26 | # http://bugzilla.redhat.com/499689 27 | # memchr should not dereference overestimated length after a match 28 | # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 29 | # http://sourceware.org/bugzilla/show_bug.cgi?id=10162 30 | # Assume that memchr works on platforms that lack mprotect. 31 | AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works], 32 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 33 | #include 34 | #if HAVE_SYS_MMAN_H 35 | # include 36 | # include 37 | # include 38 | # include 39 | # ifndef MAP_FILE 40 | # define MAP_FILE 0 41 | # endif 42 | #endif 43 | ]], [[ 44 | int result = 0; 45 | char *fence = NULL; 46 | #if HAVE_SYS_MMAN_H && HAVE_MPROTECT 47 | # if HAVE_MAP_ANONYMOUS 48 | const int flags = MAP_ANONYMOUS | MAP_PRIVATE; 49 | const int fd = -1; 50 | # else /* !HAVE_MAP_ANONYMOUS */ 51 | const int flags = MAP_FILE | MAP_PRIVATE; 52 | int fd = open ("/dev/zero", O_RDONLY, 0666); 53 | if (fd >= 0) 54 | # endif 55 | { 56 | int pagesize = getpagesize (); 57 | char *two_pages = 58 | (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, 59 | flags, fd, 0); 60 | if (two_pages != (char *)(-1) 61 | && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) 62 | fence = two_pages + pagesize; 63 | } 64 | #endif 65 | if (fence) 66 | { 67 | if (memchr (fence, 0, 0)) 68 | result |= 1; 69 | strcpy (fence - 9, "12345678"); 70 | if (memchr (fence - 9, 0, 79) != fence - 1) 71 | result |= 2; 72 | if (memchr (fence - 1, 0, 3) != fence - 1) 73 | result |= 4; 74 | } 75 | return result; 76 | ]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no], 77 | [dnl Be pessimistic for now. 78 | gl_cv_func_memchr_works="guessing no"])]) 79 | if test "$gl_cv_func_memchr_works" != yes; then 80 | REPLACE_MEMCHR=1 81 | fi 82 | fi 83 | ]) 84 | 85 | # Prerequisites of lib/memchr.c. 86 | AC_DEFUN([gl_PREREQ_MEMCHR], [ 87 | AC_CHECK_HEADERS([bp-sym.h]) 88 | ]) 89 | -------------------------------------------------------------------------------- /m4/mmap-anon.m4: -------------------------------------------------------------------------------- 1 | # mmap-anon.m4 serial 9 2 | dnl Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Detect how mmap can be used to create anonymous (not file-backed) memory 8 | # mappings. 9 | # - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS 10 | # and MAP_ANON exist and have the same value. 11 | # - On HP-UX, only MAP_ANONYMOUS exists. 12 | # - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists. 13 | # - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be 14 | # used. 15 | 16 | AC_DEFUN([gl_FUNC_MMAP_ANON], 17 | [ 18 | dnl Persuade glibc to define MAP_ANONYMOUS. 19 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 20 | 21 | # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it 22 | # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is 23 | # irrelevant for anonymous mappings. 24 | AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no]) 25 | 26 | # Try to allow MAP_ANONYMOUS. 27 | gl_have_mmap_anonymous=no 28 | if test $gl_have_mmap = yes; then 29 | AC_MSG_CHECKING([for MAP_ANONYMOUS]) 30 | AC_EGREP_CPP([I cant identify this map.], [ 31 | #include 32 | #ifdef MAP_ANONYMOUS 33 | I cant identify this map. 34 | #endif 35 | ], 36 | [gl_have_mmap_anonymous=yes]) 37 | if test $gl_have_mmap_anonymous != yes; then 38 | AC_EGREP_CPP([I cant identify this map.], [ 39 | #include 40 | #ifdef MAP_ANON 41 | I cant identify this map. 42 | #endif 43 | ], 44 | [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON], 45 | [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.]) 46 | gl_have_mmap_anonymous=yes]) 47 | fi 48 | AC_MSG_RESULT([$gl_have_mmap_anonymous]) 49 | if test $gl_have_mmap_anonymous = yes; then 50 | AC_DEFINE([HAVE_MAP_ANONYMOUS], [1], 51 | [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including 52 | config.h and .]) 53 | fi 54 | fi 55 | ]) 56 | -------------------------------------------------------------------------------- /m4/multiarch.m4: -------------------------------------------------------------------------------- 1 | # multiarch.m4 serial 6 2 | dnl Copyright (C) 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine whether the compiler is or may be producing universal binaries. 8 | # 9 | # On MacOS X 10.5 and later systems, the user can create libraries and 10 | # executables that work on multiple system types--known as "fat" or 11 | # "universal" binaries--by specifying multiple '-arch' options to the 12 | # compiler but only a single '-arch' option to the preprocessor. Like 13 | # this: 14 | # 15 | # ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 16 | # CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 17 | # CPP="gcc -E" CXXCPP="g++ -E" 18 | # 19 | # Detect this situation and set APPLE_UNIVERSAL_BUILD accordingly. 20 | 21 | AC_DEFUN_ONCE([gl_MULTIARCH], 22 | [ 23 | dnl Code similar to autoconf-2.63 AC_C_BIGENDIAN. 24 | gl_cv_c_multiarch=no 25 | AC_COMPILE_IFELSE( 26 | [AC_LANG_SOURCE( 27 | [[#ifndef __APPLE_CC__ 28 | not a universal capable compiler 29 | #endif 30 | typedef int dummy; 31 | ]])], 32 | [ 33 | dnl Check for potential -arch flags. It is not universal unless 34 | dnl there are at least two -arch flags with different values. 35 | arch= 36 | prev= 37 | for word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do 38 | if test -n "$prev"; then 39 | case $word in 40 | i?86 | x86_64 | ppc | ppc64) 41 | if test -z "$arch" || test "$arch" = "$word"; then 42 | arch="$word" 43 | else 44 | gl_cv_c_multiarch=yes 45 | fi 46 | ;; 47 | esac 48 | prev= 49 | else 50 | if test "x$word" = "x-arch"; then 51 | prev=arch 52 | fi 53 | fi 54 | done 55 | ]) 56 | if test $gl_cv_c_multiarch = yes; then 57 | APPLE_UNIVERSAL_BUILD=1 58 | else 59 | APPLE_UNIVERSAL_BUILD=0 60 | fi 61 | AC_SUBST([APPLE_UNIVERSAL_BUILD]) 62 | ]) 63 | -------------------------------------------------------------------------------- /m4/onceonly.m4: -------------------------------------------------------------------------------- 1 | # onceonly.m4 serial 7 2 | dnl Copyright (C) 2002-2003, 2005-2006, 2008-2011 Free Software Foundation, 3 | dnl Inc. 4 | dnl This file is free software, distributed under the terms of the GNU 5 | dnl General Public License. As a special exception to the GNU General 6 | dnl Public License, this file may be distributed as part of a program 7 | dnl that contains a configuration script generated by Autoconf, under 8 | dnl the same distribution terms as the rest of that program. 9 | 10 | dnl This file defines some "once only" variants of standard autoconf macros. 11 | dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS 12 | dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS 13 | dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS 14 | dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL 15 | dnl The advantage is that the check for each of the headers/functions/decls 16 | dnl will be put only once into the 'configure' file. It keeps the size of 17 | dnl the 'configure' file down, and avoids redundant output when 'configure' 18 | dnl is run. 19 | dnl The drawback is that the checks cannot be conditionalized. If you write 20 | dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi 21 | dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to 22 | dnl empty, and the check will be inserted before the body of the AC_DEFUNed 23 | dnl function. 24 | 25 | dnl The original code implemented AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE 26 | dnl in terms of AC_DEFUN and AC_REQUIRE. This implementation uses diversions to 27 | dnl named sections DEFAULTS and INIT_PREPARE in order to check all requested 28 | dnl headers at once, thus reducing the size of 'configure'. It is known to work 29 | dnl with autoconf 2.57..2.62 at least . The size reduction is ca. 9%. 30 | 31 | dnl Autoconf version 2.59 plus gnulib is required; this file is not needed 32 | dnl with Autoconf 2.60 or greater. But note that autoconf's implementation of 33 | dnl AC_CHECK_DECLS_ONCE expects a comma-separated list of symbols as first 34 | dnl argument! 35 | AC_PREREQ([2.59]) 36 | 37 | # AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of 38 | # AC_CHECK_HEADERS(HEADER1 HEADER2 ...). 39 | AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ 40 | : 41 | m4_foreach_w([gl_HEADER_NAME], [$1], [ 42 | AC_DEFUN([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, 43 | [./-], [___])), [ 44 | m4_divert_text([INIT_PREPARE], 45 | [gl_header_list="$gl_header_list gl_HEADER_NAME"]) 46 | gl_HEADERS_EXPANSION 47 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), 48 | [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) 49 | ]) 50 | AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, 51 | [./-], [___]))) 52 | ]) 53 | ]) 54 | m4_define([gl_HEADERS_EXPANSION], [ 55 | m4_divert_text([DEFAULTS], [gl_header_list=]) 56 | AC_CHECK_HEADERS([$gl_header_list]) 57 | m4_define([gl_HEADERS_EXPANSION], []) 58 | ]) 59 | 60 | # AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of 61 | # AC_CHECK_FUNCS(FUNC1 FUNC2 ...). 62 | AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ 63 | : 64 | m4_foreach_w([gl_FUNC_NAME], [$1], [ 65 | AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ 66 | m4_divert_text([INIT_PREPARE], 67 | [gl_func_list="$gl_func_list gl_FUNC_NAME"]) 68 | gl_FUNCS_EXPANSION 69 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])), 70 | [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.]) 71 | ]) 72 | AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) 73 | ]) 74 | ]) 75 | m4_define([gl_FUNCS_EXPANSION], [ 76 | m4_divert_text([DEFAULTS], [gl_func_list=]) 77 | AC_CHECK_FUNCS([$gl_func_list]) 78 | m4_define([gl_FUNCS_EXPANSION], []) 79 | ]) 80 | 81 | # AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of 82 | # AC_CHECK_DECLS(DECL1, DECL2, ...). 83 | AC_DEFUN([AC_CHECK_DECLS_ONCE], [ 84 | : 85 | m4_foreach_w([gl_DECL_NAME], [$1], [ 86 | AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ 87 | AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) 88 | ]) 89 | AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) 90 | ]) 91 | ]) 92 | -------------------------------------------------------------------------------- /m4/sigaction.m4: -------------------------------------------------------------------------------- 1 | # sigaction.m4 serial 6 2 | dnl Copyright (C) 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine if sigaction interface is present. 8 | AC_DEFUN([gl_SIGACTION], 9 | [ 10 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 11 | AC_CHECK_FUNCS_ONCE([sigaction]) 12 | if test $ac_cv_func_sigaction = yes; then 13 | AC_CHECK_MEMBERS([struct sigaction.sa_sigaction], , , 14 | [[#include ]]) 15 | if test $ac_cv_member_struct_sigaction_sa_sigaction = no; then 16 | HAVE_STRUCT_SIGACTION_SA_SIGACTION=0 17 | fi 18 | else 19 | HAVE_SIGACTION=0 20 | fi 21 | ]) 22 | 23 | # Prerequisites of the part of lib/signal.in.h and of lib/sigaction.c. 24 | AC_DEFUN([gl_PREREQ_SIGACTION], 25 | [ 26 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 27 | AC_REQUIRE([AC_C_RESTRICT]) 28 | AC_REQUIRE([AC_TYPE_UID_T]) 29 | AC_REQUIRE([gl_PREREQ_SIG_HANDLER_H]) 30 | AC_CHECK_FUNCS_ONCE([sigaltstack siginterrupt]) 31 | AC_CHECK_TYPES([siginfo_t], [], [], [[ 32 | #include 33 | ]]) 34 | if test $ac_cv_type_siginfo_t = no; then 35 | HAVE_SIGINFO_T=0 36 | fi 37 | ]) 38 | 39 | # Prerequisites of lib/sig-handler.h. 40 | AC_DEFUN([gl_PREREQ_SIG_HANDLER_H], 41 | [ 42 | AC_REQUIRE([AC_C_INLINE]) 43 | ]) 44 | -------------------------------------------------------------------------------- /m4/signal_h.m4: -------------------------------------------------------------------------------- 1 | # signal_h.m4 serial 12 2 | dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | AC_DEFUN([gl_SIGNAL_H], 8 | [ 9 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 10 | gl_NEXT_HEADERS([signal.h]) 11 | 12 | # AIX declares sig_atomic_t to already include volatile, and C89 compilers 13 | # then choke on 'volatile sig_atomic_t'. C99 requires that it compile. 14 | AC_CHECK_TYPE([volatile sig_atomic_t], [], 15 | [HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=0], [[ 16 | #include 17 | ]]) 18 | 19 | AC_REQUIRE([AC_TYPE_UID_T]) 20 | 21 | dnl Persuade glibc to define sighandler_t. 22 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) 23 | AC_CHECK_TYPE([sighandler_t], [], [HAVE_SIGHANDLER_T=0], [[ 24 | #include 25 | ]]) 26 | 27 | dnl Check for declarations of anything we want to poison if the 28 | dnl corresponding gnulib module is not in use. 29 | gl_WARN_ON_USE_PREPARE([[#include 30 | ]], [sigaction sigaddset sigdelset sigemptyset sigfillset sigismember 31 | sigpending sigprocmask]) 32 | ]) 33 | 34 | AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR], 35 | [ 36 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 37 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 38 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 39 | dnl Define it also as a C macro, for the benefit of the unit tests. 40 | gl_MODULE_INDICATOR_FOR_TESTS([$1]) 41 | ]) 42 | 43 | AC_DEFUN([gl_SIGNAL_H_DEFAULTS], 44 | [ 45 | GNULIB_SIGNAL_H_SIGPIPE=0; AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE]) 46 | GNULIB_SIGPROCMASK=0; AC_SUBST([GNULIB_SIGPROCMASK]) 47 | GNULIB_SIGACTION=0; AC_SUBST([GNULIB_SIGACTION]) 48 | dnl Assume proper GNU behavior unless another module says otherwise. 49 | HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING]) 50 | HAVE_SIGSET_T=1; AC_SUBST([HAVE_SIGSET_T]) 51 | HAVE_SIGINFO_T=1; AC_SUBST([HAVE_SIGINFO_T]) 52 | HAVE_SIGACTION=1; AC_SUBST([HAVE_SIGACTION]) 53 | HAVE_STRUCT_SIGACTION_SA_SIGACTION=1; 54 | AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION]) 55 | HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1; 56 | AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T]) 57 | HAVE_SIGHANDLER_T=1; AC_SUBST([HAVE_SIGHANDLER_T]) 58 | ]) 59 | -------------------------------------------------------------------------------- /m4/signalblocking.m4: -------------------------------------------------------------------------------- 1 | # signalblocking.m4 serial 11 2 | dnl Copyright (C) 2001-2002, 2006-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # Determine available signal blocking primitives. Three different APIs exist: 8 | # 1) POSIX: sigemptyset, sigaddset, sigprocmask 9 | # 2) SYSV: sighold, sigrelse 10 | # 3) BSD: sigblock, sigsetmask 11 | # For simplicity, here we check only for the POSIX signal blocking. 12 | AC_DEFUN([gl_SIGNALBLOCKING], 13 | [ 14 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 15 | signals_not_posix= 16 | AC_EGREP_HEADER([sigset_t], [signal.h], , [signals_not_posix=1]) 17 | if test -z "$signals_not_posix"; then 18 | AC_CHECK_FUNC([sigprocmask], [gl_cv_func_sigprocmask=1]) 19 | fi 20 | if test -z "$gl_cv_func_sigprocmask"; then 21 | HAVE_POSIX_SIGNALBLOCKING=0 22 | fi 23 | ]) 24 | 25 | # Prerequisites of the part of lib/signal.in.h and of lib/sigprocmask.c. 26 | AC_DEFUN([gl_PREREQ_SIGPROCMASK], 27 | [ 28 | AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) 29 | AC_CHECK_TYPES([sigset_t], 30 | [gl_cv_type_sigset_t=yes], [gl_cv_type_sigset_t=no], 31 | [#include 32 | /* Mingw defines sigset_t not in , but in . */ 33 | #include ]) 34 | if test $gl_cv_type_sigset_t != yes; then 35 | HAVE_SIGSET_T=0 36 | fi 37 | dnl HAVE_SIGSET_T is 1 if the system lacks the sigprocmask function but has 38 | dnl the sigset_t type. 39 | AC_SUBST([HAVE_SIGSET_T]) 40 | ]) 41 | -------------------------------------------------------------------------------- /m4/stddef_h.m4: -------------------------------------------------------------------------------- 1 | dnl A placeholder for POSIX 2008 , for platforms that have issues. 2 | # stddef_h.m4 serial 4 3 | dnl Copyright (C) 2009-2011 Free Software Foundation, Inc. 4 | dnl This file is free software; the Free Software Foundation 5 | dnl gives unlimited permission to copy and/or distribute it, 6 | dnl with or without modifications, as long as this notice is preserved. 7 | 8 | AC_DEFUN([gl_STDDEF_H], 9 | [ 10 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 11 | AC_REQUIRE([gt_TYPE_WCHAR_T]) 12 | STDDEF_H= 13 | if test $gt_cv_c_wchar_t = no; then 14 | HAVE_WCHAR_T=0 15 | STDDEF_H=stddef.h 16 | fi 17 | AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], 18 | [gl_cv_decl_null_works], 19 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include 20 | int test[2 * (sizeof NULL == sizeof (void *)) -1]; 21 | ]])], 22 | [gl_cv_decl_null_works=yes], 23 | [gl_cv_decl_null_works=no])]) 24 | if test $gl_cv_decl_null_works = no; then 25 | REPLACE_NULL=1 26 | STDDEF_H=stddef.h 27 | fi 28 | AC_SUBST([STDDEF_H]) 29 | AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) 30 | if test -n "$STDDEF_H"; then 31 | gl_NEXT_HEADERS([stddef.h]) 32 | fi 33 | ]) 34 | 35 | AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], 36 | [ 37 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 38 | AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 39 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 40 | ]) 41 | 42 | AC_DEFUN([gl_STDDEF_H_DEFAULTS], 43 | [ 44 | dnl Assume proper GNU behavior unless another module says otherwise. 45 | REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) 46 | HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) 47 | ]) 48 | -------------------------------------------------------------------------------- /m4/strtok_r.m4: -------------------------------------------------------------------------------- 1 | # strtok_r.m4 serial 12 2 | dnl Copyright (C) 2002-2004, 2006-2007, 2009-2011 Free Software Foundation, 3 | dnl Inc. 4 | dnl This file is free software; the Free Software Foundation 5 | dnl gives unlimited permission to copy and/or distribute it, 6 | dnl with or without modifications, as long as this notice is preserved. 7 | 8 | AC_DEFUN([gl_FUNC_STRTOK_R], 9 | [ 10 | dnl The strtok_r() declaration in lib/string.in.h uses 'restrict'. 11 | AC_REQUIRE([AC_C_RESTRICT]) 12 | 13 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 14 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 15 | AC_CHECK_FUNCS([strtok_r]) 16 | if test $ac_cv_func_strtok_r = yes; then 17 | dnl glibc 2.7 has a bug in strtok_r that causes a segmentation fault 18 | dnl when the second argument to strtok_r is a constant string that has 19 | dnl exactly one byte and compiling with optimization. This bug is, for 20 | dnl example, present in the glibc 2.7-18 package in Debian "lenny". 21 | dnl See . 22 | AC_CACHE_CHECK([whether strtok_r works], [gl_cv_func_strtok_r_works], 23 | [AC_RUN_IFELSE( 24 | [AC_LANG_PROGRAM([[ 25 | #ifndef __OPTIMIZE__ 26 | # define __OPTIMIZE__ 1 27 | #endif 28 | #undef __OPTIMIZE_SIZE__ 29 | #undef __NO_INLINE__ 30 | #include 31 | #include 32 | ]], 33 | [[static const char dummy[] = "\177\01a"; 34 | char delimiters[] = "xxxxxxxx"; 35 | char *save_ptr = (char *) dummy; 36 | strtok_r (delimiters, "x", &save_ptr); 37 | strtok_r (NULL, "x", &save_ptr); 38 | return 0; 39 | ]]) 40 | ], 41 | [gl_cv_func_strtok_r_works=yes], 42 | [gl_cv_func_strtok_r_works=no], 43 | [ 44 | changequote(,)dnl 45 | case "$host_os" in 46 | # Guess no on glibc systems. 47 | *-gnu*) gl_cv_func_strtok_r_works="guessing no";; 48 | *) gl_cv_func_strtok_r_works="guessing yes";; 49 | esac 50 | changequote([,])dnl 51 | ]) 52 | ]) 53 | case "$gl_cv_func_strtok_r_works" in 54 | *no) 55 | dnl We could set REPLACE_STRTOK_R=1 and AC_LIBOBJ([strtok_r]) here, 56 | dnl but it's only the macro version in which is wrong. 57 | dnl The code compiled into libc is fine. 58 | UNDEFINE_STRTOK_R=1 59 | ;; 60 | esac 61 | else 62 | AC_LIBOBJ([strtok_r]) 63 | gl_PREREQ_STRTOK_R 64 | fi 65 | AC_CHECK_DECLS_ONCE([strtok_r]) 66 | if test $ac_cv_have_decl_strtok_r = no; then 67 | HAVE_DECL_STRTOK_R=0 68 | fi 69 | ]) 70 | 71 | # Prerequisites of lib/strtok_r.c. 72 | AC_DEFUN([gl_PREREQ_STRTOK_R], [ 73 | : 74 | ]) 75 | -------------------------------------------------------------------------------- /m4/warn-on-use.m4: -------------------------------------------------------------------------------- 1 | # warn-on-use.m4 serial 2 2 | dnl Copyright (C) 2010-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES) 8 | # --------------------------------------- 9 | # For each whitespace-separated element in the list of NAMES, define 10 | # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES 11 | # even after being undefined as a macro. 12 | # 13 | # See warn-on-use.h for some hints on how to poison function names, as 14 | # well as ideas on poisoning global variables and macros. NAMES may 15 | # include global variables, but remember that only functions work with 16 | # _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single 17 | # header, but if the replacement header pulls in other headers because 18 | # some systems declare functions in the wrong header, then INCLUDES 19 | # should do likewise. 20 | # 21 | # If you assume C89, then it is generally safe to assume declarations 22 | # for functions declared in that standard (such as gets) without 23 | # needing gl_WARN_ON_USE_PREPARE. 24 | AC_DEFUN([gl_WARN_ON_USE_PREPARE], 25 | [ 26 | m4_foreach_w([gl_decl], [$2], 27 | [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])), 28 | [Define to 1 if ]m4_defn([gl_decl])[ is declared even after 29 | undefining macros.])])dnl 30 | for gl_func in m4_flatten([$2]); do 31 | AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl 32 | AC_CACHE_CHECK([whether $gl_func is declared without a macro], 33 | gl_Symbol, 34 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1], 35 | [@%:@undef $gl_func 36 | (void) $gl_func;])], 37 | [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])]) 38 | AS_VAR_IF(gl_Symbol, [yes], 39 | [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1]) 40 | dnl shortcut - if the raw declaration exists, then set a cache 41 | dnl variable to allow skipping any later AC_CHECK_DECL efforts 42 | eval ac_cv_have_decl_$gl_func=yes]) 43 | AS_VAR_POPDEF([gl_Symbol])dnl 44 | done 45 | ]) 46 | -------------------------------------------------------------------------------- /m4/wchar_t.m4: -------------------------------------------------------------------------------- 1 | # wchar_t.m4 serial 4 (gettext-0.18.2) 2 | dnl Copyright (C) 2002-2003, 2008-2011 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | dnl Test whether has the 'wchar_t' type. 9 | dnl Prerequisite: AC_PROG_CC 10 | 11 | AC_DEFUN([gt_TYPE_WCHAR_T], 12 | [ 13 | AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t], 14 | [AC_COMPILE_IFELSE( 15 | [AC_LANG_PROGRAM( 16 | [[#include 17 | wchar_t foo = (wchar_t)'\0';]], 18 | [[]])], 19 | [gt_cv_c_wchar_t=yes], 20 | [gt_cv_c_wchar_t=no])]) 21 | if test $gt_cv_c_wchar_t = yes; then 22 | AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.]) 23 | fi 24 | ]) 25 | -------------------------------------------------------------------------------- /malgo/scrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRYPT_H 2 | #define SCRYPT_H 3 | 4 | extern void test_scrypt(void); 5 | 6 | #endif /* SCRYPT_H */ 7 | -------------------------------------------------------------------------------- /malgo/sha256d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2014 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "logging.h" 18 | #include "miner.h" 19 | #include "ocl.h" 20 | #include "util.h" 21 | 22 | static 23 | void hash_data(void *out_hash, const void *data) 24 | { 25 | unsigned char blkheader[80]; 26 | 27 | // data is past the first SHA256 step (padding and interpreting as big endian on a little endian platform), so we need to flip each 32-bit chunk around to get the original input block header 28 | swap32yes(blkheader, data, 80 / 4); 29 | 30 | // double-SHA256 to get the block hash 31 | gen_hash(blkheader, out_hash, 80); 32 | } 33 | 34 | #ifdef USE_OPENCL 35 | static 36 | float opencl_oclthreads_to_intensity_sha256d(const unsigned long oclthreads) 37 | { 38 | return log2f(oclthreads) - 15.; 39 | } 40 | 41 | static 42 | unsigned long opencl_intensity_to_oclthreads_sha256d(float intensity) 43 | { 44 | return powf(2, intensity + 15); 45 | } 46 | 47 | static 48 | char *opencl_get_default_kernel_file_sha256d(const struct mining_algorithm * const malgo, struct cgpu_info * const cgpu, struct _clState * const clState) 49 | { 50 | const char * const vbuff = clState->platform_ver_str; 51 | 52 | if (clState->is_mesa) 53 | { 54 | applog(LOG_INFO, "Selecting phatk kernel for Mesa"); 55 | return strdup("phatk"); 56 | } 57 | 58 | /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */ 59 | if (!strstr(cgpu->name, "Tahiti") && 60 | (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK 61 | strstr(vbuff, "851.4") || // Windows 64 bit "" 62 | strstr(vbuff, "831.4") || 63 | strstr(vbuff, "898.1") || // 12.2 driver SDK 64 | strstr(vbuff, "923.1") || // 12.4 65 | strstr(vbuff, "938.2") || // SDK 2.7 66 | strstr(vbuff, "1113.2"))) // SDK 2.8 67 | { 68 | applog(LOG_INFO, "Selecting diablo kernel"); 69 | return strdup("diablo"); 70 | } 71 | 72 | /* Detect all 7970s, older ATI and NVIDIA and use poclbm */ 73 | if (strstr(cgpu->name, "Tahiti") || !clState->hasBitAlign) 74 | { 75 | applog(LOG_INFO, "Selecting poclbm kernel"); 76 | return strdup("poclbm"); 77 | } 78 | 79 | /* Use phatk for the rest R5xxx R6xxx */ 80 | { 81 | applog(LOG_INFO, "Selecting phatk kernel"); 82 | return strdup("phatk"); 83 | } 84 | } 85 | #endif /* USE_OPENCL */ 86 | 87 | struct mining_algorithm malgo_sha256d = { 88 | .name = "SHA256d", 89 | .aliases = "SHA256d|SHA256|SHA2", 90 | 91 | .algo = POW_SHA256D, 92 | .ui_skip_hash_bytes = 4, 93 | .worktime_skip_prevblk_u32 = 1, 94 | .reasonable_low_nonce_diff = 1., 95 | 96 | .hash_data_f = hash_data, 97 | 98 | #ifdef USE_OPENCL 99 | .opencl_nodefault = true, 100 | .opencl_oclthreads_to_intensity = opencl_oclthreads_to_intensity_sha256d, 101 | .opencl_intensity_to_oclthreads = opencl_intensity_to_oclthreads_sha256d, 102 | .opencl_min_oclthreads = 0x20, // intensity -10 103 | .opencl_max_oclthreads = 0x20000000, // intensity 14 104 | .opencl_min_nonce_diff = 1., 105 | .opencl_get_default_kernel_file = opencl_get_default_kernel_file_sha256d, 106 | #endif 107 | }; 108 | 109 | static 110 | __attribute__((constructor)) 111 | void init_sha256d(void) 112 | { 113 | LL_APPEND(mining_algorithms, (&malgo_sha256d)); 114 | } 115 | -------------------------------------------------------------------------------- /mcp2210.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_MCP2210_H 2 | #define BFG_MCP2210_H 3 | 4 | #include 5 | #include 6 | 7 | enum mcp2210_gpio_direction { 8 | MGD_OUTPUT, 9 | MGD_INPUT, 10 | }; 11 | 12 | struct mcp2210_device; 13 | 14 | extern struct mcp2210_device *mcp2210_open(const struct lowlevel_device_info *); 15 | extern void mcp2210_close(struct mcp2210_device *); 16 | 17 | extern bool mcp2210_spi_cancel(struct mcp2210_device *); 18 | extern bool mcp2210_configure_spi(struct mcp2210_device *, uint32_t bitrate, uint16_t idlechipsel, uint16_t activechipsel, uint16_t chipseltodatadelay, uint16_t lastbytetocsdelay, uint16_t midbytedelay); 19 | extern bool mcp2210_set_spimode(struct mcp2210_device *, uint8_t spimode); 20 | extern bool mcp2210_spi_transfer(struct mcp2210_device *, const void *tx, void *rx, uint8_t sz); 21 | 22 | extern bool mcp2210_set_gpio_output(struct mcp2210_device *, int pin, enum bfg_gpio_value); 23 | extern enum bfg_gpio_value mcp2210_get_gpio_input(struct mcp2210_device *, int pin); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /ocl.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_OCL_H 2 | #define BFG_OCL_H 3 | 4 | #include 5 | #include 6 | 7 | #include "CL/cl.h" 8 | 9 | #include "miner.h" 10 | 11 | #define SCRYPT_CLBUFFER0_SZ (128) 12 | #define FULLHEADER_CLBUFFER0_SZ ( 80) 13 | #ifdef USE_SCRYPT 14 | # define MAX_CLBUFFER0_SZ SCRYPT_CLBUFFER0_SZ 15 | #elif USE_OPENCL_FULLHEADER 16 | # define MAX_CLBUFFER0_SZ FULLHEADER_CLBUFFER0_SZ 17 | #endif 18 | 19 | struct mining_algorithm; 20 | struct opencl_kernel_info; 21 | typedef struct _clState _clState; 22 | 23 | struct _clState { 24 | cl_device_id devid; 25 | char *platform_ver_str; 26 | bool is_mesa; 27 | 28 | cl_context context; 29 | cl_command_queue commandQueue; 30 | 31 | cl_mem outputBuffer; 32 | #ifdef MAX_CLBUFFER0_SZ 33 | cl_mem CLbuffer0; 34 | #endif 35 | #ifdef USE_SCRYPT 36 | cl_mem padbuffer8; 37 | size_t padbufsize; 38 | void * cldata; 39 | #endif 40 | bool hasBitAlign; 41 | cl_uint preferred_vwidth; 42 | cl_uint vwidth; 43 | size_t max_work_size; 44 | cl_uint max_compute_units; 45 | }; 46 | 47 | extern FILE *opencl_open_kernel(const char *filename); 48 | extern char *file_contents(const char *filename, int *length); 49 | extern char *opencl_kernel_source(const char *filename, int *out_sourcelen, enum cl_kernels *out_kinterface, struct mining_algorithm **); 50 | extern int clDevicesNum(void); 51 | extern _clState *opencl_create_clState(unsigned int gpu, char *name, size_t nameSize); 52 | extern bool opencl_load_kernel(struct cgpu_info *, _clState *clState, const char *name, struct opencl_kernel_info *, const char *kernel_file, const struct mining_algorithm *); 53 | 54 | #endif /* __OCL_H__ */ 55 | -------------------------------------------------------------------------------- /openwrt/.gitignore: -------------------------------------------------------------------------------- 1 | !bfgminer 2 | !bfgminer/Makefile 3 | openwrt-src 4 | -------------------------------------------------------------------------------- /openwrt/bfgminer/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013-2017 Luke Dashjr 3 | # 4 | # This program is free software; you can redistribute it and/or modify it 5 | # under the terms of the GNU General Public License as published by the Free 6 | # Software Foundation; either version 3 of the License, or (at your option) 7 | # any later version. See COPYING for more details. 8 | # 9 | 10 | include $(TOPDIR)/rules.mk 11 | 12 | PKG_NAME:=bfgminer 13 | PKG_TITLE:=BFGMiner 14 | PKG_VERSION:=5.5.0 15 | PKG_RELEASE:=1 16 | 17 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).txz 18 | PKG_SOURCE_URL:=http://luke.dashjr.org/programs/bitcoin/files/$(PKG_NAME)/$(PKG_VERSION)/ 19 | 20 | PKG_MAINTAINER:=Luke Dashjr 21 | PKG_LICENSE:=GPL-3.0+ 22 | PKG_LICENSE_FILES:=COPYING 23 | 24 | PKG_INSTALL:=1 25 | 26 | include $(INCLUDE_DIR)/package.mk 27 | 28 | define Download/uthash 29 | FILE:=v1.9.8 30 | URL:=https://codeload.github.com/troydhanson/uthash/tar.gz/ 31 | endef 32 | $(eval $(call Download,uthash)) 33 | 34 | define Package/$(PKG_NAME)/Default 35 | MAINTAINER:="Luke Dashjr" 36 | SECTION:=utils 37 | CATEGORY:=Utilities 38 | URL:=http://luke.dashjr.org/programs/$(PKG_NAME) 39 | DEPENDS:=+$(PKG_NAME) 40 | endef 41 | 42 | define Package/$(PKG_NAME) 43 | $(call Package/$(PKG_NAME)/Default) 44 | TITLE:=$(PKG_TITLE) (Bitcoin miner) 45 | DEPENDS:=+libc +libcurl +libpthread +jansson +PACKAGE_$(PKG_NAME)_libevent:libevent2 +PACKAGE_$(PKG_NAME)_libevent:libevent2-pthreads +PACKAGE_$(PKG_NAME)_curses:libncurses +PACKAGE_$(PKG_NAME)_libmicrohttpd:libmicrohttpd +PACKAGE_$(PKG_NAME)_libusb:libusb-1.0 46 | endef 47 | 48 | define Package/$(PKG_NAME)/description 49 | Modular Bitcoin ASIC/FPGA/GPU/CPU miner in C 50 | endef 51 | 52 | define Package/$(PKG_NAME)/config 53 | config PACKAGE_$(PKG_NAME)_curses 54 | bool "Build with curses TUI support" 55 | depends on PACKAGE_$(PKG_NAME) 56 | default y 57 | config PACKAGE_$(PKG_NAME)_libevent 58 | bool "Build with stratum server support" 59 | depends on PACKAGE_$(PKG_NAME) 60 | default y 61 | config PACKAGE_$(PKG_NAME)_libmicrohttpd 62 | bool "Build with getwork server support (Block Erupter blades)" 63 | depends on PACKAGE_$(PKG_NAME) 64 | default y 65 | config PACKAGE_$(PKG_NAME)_libusb 66 | bool "Build with libusb support (Cointerra, HashBuster Micro, Klondike, X6500 & ZTEX)" 67 | depends on PACKAGE_$(PKG_NAME) 68 | default y 69 | config PACKAGE_$(PKG_NAME)_bitmain 70 | bool "Build with bitmain driver (only for S* series miners)" 71 | depends on PACKAGE_$(PKG_NAME) 72 | default n 73 | config PACKAGE_$(PKG_NAME)_keccak 74 | bool "Build with Keccak algorithm support" 75 | depends on PACKAGE_$(PKG_NAME) 76 | default n 77 | config PACKAGE_$(PKG_NAME)_scrypt 78 | bool "Build with scrypt algorithm support" 79 | depends on PACKAGE_$(PKG_NAME) 80 | default y 81 | endef 82 | 83 | ifndef CONFIG_PACKAGE_$(PKG_NAME)_curses 84 | CONFIGURE_ARGS += --without-curses 85 | else 86 | CONFIGURE_ARGS += --with-curses=ncurses 87 | endif 88 | 89 | ifndef CONFIG_PACKAGE_$(PKG_NAME)_libevent 90 | CONFIGURE_ARGS += --without-libevent 91 | else 92 | CONFIGURE_ARGS += --with-libevent 93 | endif 94 | 95 | ifndef CONFIG_PACKAGE_$(PKG_NAME)_libmicrohttpd 96 | CONFIGURE_ARGS += --without-libmicrohttpd 97 | else 98 | CONFIGURE_ARGS += --with-libmicrohttpd 99 | endif 100 | 101 | ifndef CONFIG_PACKAGE_$(PKG_NAME)_libusb 102 | CONFIGURE_ARGS += --without-libusb 103 | endif 104 | 105 | ifdef CONFIG_PACKAGE_$(PKG_NAME)_bitmain 106 | CONFIGURE_ARGS += --enable-bitmain 107 | endif 108 | 109 | ifdef CONFIG_PACKAGE_$(PKG_NAME)_keccak 110 | CONFIGURE_ARGS += --enable-keccak 111 | endif 112 | 113 | ifdef CONFIG_PACKAGE_$(PKG_NAME)_scrypt 114 | CONFIGURE_ARGS += --enable-scrypt 115 | endif 116 | 117 | TARGET_CFLAGS += -std=gnu99 118 | TARGET_CFLAGS += -Iuthash-1.9.8/src 119 | 120 | CONFIGURE_ARGS += --without-libudev 121 | CONFIGURE_ARGS += --without-sensors 122 | CONFIGURE_ARGS += --without-system-libbase58 123 | 124 | define Build/Prepare 125 | $(call Build/Prepare/Default) 126 | gzip -dc $(DL_DIR)/v1.9.8 | $(HOST_TAR) -C $(PKG_BUILD_DIR) $(TAR_OPTIONS) 127 | endef 128 | 129 | define Build/Configure 130 | # Need to remake configure etc to pick up on cross-compiler libtool 131 | ( cd $(PKG_BUILD_DIR); NOSUBMODULES=1 ./autogen.sh; ) 132 | 133 | $(call Build/Configure/Default) 134 | endef 135 | 136 | define Package/$(PKG_NAME)/install 137 | $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib 138 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(PKG_NAME) $(1)/usr/bin 139 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(PKG_NAME)-rpc $(1)/usr/bin 140 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libblkmaker*.so* $(1)/usr/lib 141 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libbase58*.so* $(1)/usr/lib 142 | endef 143 | 144 | ALL_$(PKG_NAME)_PACKAGES += $(PKG_NAME) 145 | 146 | 147 | $(foreach bitstream,$(ALL_$(PKG_NAME)_PACKAGES),$(eval $(call BuildPackage,$(bitstream)))) 148 | -------------------------------------------------------------------------------- /openwrt/multibuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2013-2017 Luke Dashjr 3 | # 4 | # This program is free software; you can redistribute it and/or modify it 5 | # under the terms of the GNU General Public License as published by the Free 6 | # Software Foundation; either version 3 of the License, or (at your option) 7 | # any later version. See COPYING for more details. 8 | 9 | set -e 10 | set -x 11 | reporoot="$1" # .../files/bfgminer/BFGMINER_VERSION/openwrt/OPENWRT_VERSION 12 | openwrt_root="${2:-openwrt-src}" 13 | BITSTREAM_PKG_PATH="${3}" # Relative to reporoot 14 | test -n "$reporoot" 15 | reporoot="$(realpath "$reporoot")" 16 | test -n "$reporoot" 17 | cd "${openwrt_root}/" 18 | openwrt_root="$PWD" 19 | test -d "$reporoot" 20 | vcfgdir='vanilla_configs' 21 | vcfglist="$( 22 | ls -d "$vcfgdir"/*.config* | 23 | perl -ple 's[.*/][]' | 24 | sort -n 25 | )" 26 | BITSTREAMS=( 27 | fpgaminer_402-1 28 | ztex-ufm1_15b1_121126-1 29 | ztex-ufm1_15d4_121126-1 30 | ztex-ufm1_15y1_121126-1 31 | ) 32 | 33 | if [ -d "${reporoot}/${BITSTREAM_PKG_PATH}" ]; then 34 | ( 35 | for bs in ${BITSTREAMS[@]}; do 36 | if ! [ -r "${reporoot}/${BITSTREAM_PKG_PATH}/bitstream-${bs}_all.ipk" ]; then 37 | echo "Cannot find ${bs} bitstream package" >&2 38 | exit 1 39 | fi 40 | done 41 | ) 42 | else 43 | echo 'Cannot find bitstreams directory' >&2 44 | exit 1 45 | fi 46 | 47 | plat1='' 48 | for cfn in $vcfglist; do 49 | plat="$(perl -ple 's/^\d+\.config\.(\w+)$/$1/ or $_=""' <<<"$cfn")" 50 | test -n "$plat" || 51 | continue 52 | if [[ $plat =~ _pkgs$ ]]; then 53 | plat="${plat::-5}" 54 | else 55 | plat="$(perl -ple 's/_.*//' <<<"$plat")" 56 | fi 57 | platlist+=("$plat") 58 | cp -v "$vcfgdir/$cfn" .config 59 | yes '' | make oldconfig 60 | make {tools,toolchain}/install package/bfgminer/{clean,compile} V=s 61 | mkdir "$reporoot/$plat" -pv 62 | files=$(ls bin/"$plat"/packages/{*/,}bfgminer*_${plat}*.ipk bin/packages/"$plat"/{*/,}bfgminer*_${plat}*.ipk || true) 63 | if test -z "${files}"; then 64 | echo "Cannot find built packages" 65 | exit 1 66 | fi 67 | cp -v ${files} "$reporoot/$plat/" 68 | if [ -n "${BITSTREAM_PKG_PATH}" ]; then 69 | ( 70 | test -d "$reporoot/${BITSTREAM_PKG_PATH}" 71 | cd "$reporoot/$plat" 72 | for bs in ${BITSTREAMS[@]}; do 73 | ln -vfs "../${BITSTREAM_PKG_PATH}/bitstream-${bs}_all.ipk" . 74 | done 75 | ) 76 | fi 77 | ( 78 | cd "$reporoot/$plat/" 79 | PATH="${openwrt_root}/staging_dir/host/bin/:${PATH}" \ 80 | "${openwrt_root}/scripts/ipkg-make-index.sh" . 81 | ) > "$reporoot/$plat/Packages" 82 | gzip -9 < "$reporoot/$plat/Packages" > "$reporoot/$plat/Packages.gz" 83 | done 84 | -------------------------------------------------------------------------------- /setup-vfio: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEVICES_PATH=/sys/bus/pci/devices 4 | VFIO_MODULE="vfio-pci" 5 | VFIO_PCI_NEW_ID=/sys/bus/pci/drivers/${VFIO_MODULE}/new_id 6 | Interactive=true 7 | UnsafeInts=false 8 | CHOWN_USER= 9 | 10 | die() { 11 | echo "$@" >&2 12 | exit 1 13 | } 14 | 15 | dieusage() { 16 | die "Usage: $0 [--unsafe] [--user ] [--yes] " 17 | } 18 | 19 | yesno() { 20 | if ! $Interactive; then 21 | $2 22 | return 23 | fi 24 | while true; do 25 | echo -n "$1 " 26 | read answer 27 | case "$answer" in 28 | yes|y|ye) 29 | return 0 30 | ;; 31 | no|n) 32 | return 1 33 | ;; 34 | *) 35 | echo "Please enter 'yes' or 'no'." 36 | esac 37 | done 38 | } 39 | 40 | while [ "$#" -gt 0 ]; do 41 | case "$1" in 42 | --help|-h) 43 | dieusage 44 | ;; 45 | --unsafe) 46 | UnsafeInts=true 47 | ;; 48 | --user|-u) 49 | shift 50 | CHOWN_USER="$1" 51 | ;; 52 | --yes|-y) 53 | Interactive=false 54 | ;; 55 | *) 56 | if [ -n "$WANT_VENDOR" ]; then 57 | WANT_DEVICE="$1" 58 | else 59 | WANT_VENDOR="$1" 60 | fi 61 | ;; 62 | esac 63 | shift 64 | done 65 | 66 | [ -n "$WANT_DEVICE" ] || dieusage 67 | 68 | modprobe ${VFIO_MODULE} || die 'Failed to load ${VFIO_MODULE} module' 69 | for TARGET_DEVICE_ID in $(ls $DEVICES_PATH); do 70 | { grep -q '^0x'"${WANT_VENDOR}" "${DEVICES_PATH}/${TARGET_DEVICE_ID}/vendor" && grep -q '^0x'"${WANT_DEVICE}" "${DEVICES_PATH}/${TARGET_DEVICE_ID}/device"; } || continue 71 | 72 | echo "Found $(lspci -s "$TARGET_DEVICE_ID")" 73 | extradevs= 74 | extradevsn=0 75 | extradevsq= 76 | for RELATED_DEVICE_ID in $(ls "${DEVICES_PATH}/${TARGET_DEVICE_ID}/iommu_group/devices/"); do 77 | if [ "$RELATED_DEVICE_ID" = "$TARGET_DEVICE_ID" ] || 78 | { 79 | { ! [ -e "${DEVICES_PATH}/${RELATED_DEVICE_ID}/driver" ]; } || 80 | [ "$(basename "$(readlink "${DEVICES_PATH}/${RELATED_DEVICE_ID}/driver")")" = "${VFIO_MODULE}" ] 81 | } || 82 | grep -q '^0x060400$' "${DEVICES_PATH}/${RELATED_DEVICE_ID}/class"; then 83 | extradevsq="$extradevsq $RELATED_DEVICE_ID" 84 | else 85 | extradevs="$extradevs $RELATED_DEVICE_ID" 86 | let ++extradevsn 87 | fi 88 | done 89 | if [ "$extradevsn" -gt 0 ]; then 90 | if [ $extradevsn -gt 1 ]; then 91 | echo "Enabling VFIO for this device will also disable the following $extradevsn devices:" 92 | else 93 | echo "Enabling VFIO for this device will also disable this device:" 94 | fi 95 | for RELATED_DEVICE_ID in ${extradevs}; do 96 | echo "- $(lspci -s "$RELATED_DEVICE_ID")" 97 | done 98 | fi 99 | yesno 'Enable VFIO?' true || continue 100 | 101 | if $UnsafeInts; then 102 | echo 1 >/sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts || die 'Failed to enable unsafe interrupts' 103 | fi 104 | for RELATED_DEVICE_ID in ${extradevsq} ${extradevs}; do 105 | if [ -e "${DEVICES_PATH}/${RELATED_DEVICE_ID}/driver" ]; then 106 | echo "$RELATED_DEVICE_ID" >"${DEVICES_PATH}/${RELATED_DEVICE_ID}/driver/unbind" || die "Failed to unbind $RELATED_DEVICE_ID" 107 | fi 108 | echo "$(<"${DEVICES_PATH}/${RELATED_DEVICE_ID}/vendor") $(<"${DEVICES_PATH}/${RELATED_DEVICE_ID}/device")" >"${VFIO_PCI_NEW_ID}" || die "Failed to associate device id with ${VFIO_MODULE} module" 109 | done 110 | IOMMU_GROUP="$(basename "$(readlink "${DEVICES_PATH}/${TARGET_DEVICE_ID}/iommu_group")")" 111 | VFIO_DEVICE="/dev/vfio/$IOMMU_GROUP" 112 | [ -e "$VFIO_DEVICE" ] || die "$VFIO_DEVICE does not exist" 113 | if [ -n "${CHOWN_USER}" ]; then 114 | chown "${CHOWN_USER}" "$VFIO_DEVICE" || die "Failed to chown $VFIO_DEVICE to $CHOWN_USER" 115 | fi 116 | echo "VFIO enabled on $VFIO_DEVICE" 117 | done 118 | -------------------------------------------------------------------------------- /sha2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FIPS 180-2 SHA-224/256/384/512 implementation 3 | * Last update: 02/02/2007 4 | * Issue date: 04/30/2005 5 | * 6 | * Copyright 2013 Con Kolivas 7 | * Copyright 2005, 2007 Olivier Gay 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the project nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #include "config.h" 36 | 37 | #include 38 | 39 | #include "miner.h" 40 | 41 | #ifndef SHA2_H 42 | #define SHA2_H 43 | 44 | #define SHA256_DIGEST_SIZE ( 256 / 8) 45 | #define SHA256_BLOCK_SIZE ( 512 / 8) 46 | 47 | #define SHFR(x, n) (x >> n) 48 | #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) 49 | #define CH(x, y, z) ((x & y) ^ (~x & z)) 50 | #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) 51 | 52 | #define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) 53 | #define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) 54 | #define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) 55 | #define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) 56 | 57 | typedef struct { 58 | unsigned int tot_len; 59 | unsigned int len; 60 | unsigned char block[2 * SHA256_BLOCK_SIZE]; 61 | uint32_t h[8]; 62 | } sha256_ctx; 63 | 64 | extern uint32_t sha256_k[64]; 65 | 66 | void sha256_init(sha256_ctx * ctx); 67 | void sha256_update(sha256_ctx *ctx, const unsigned char *message, 68 | unsigned int len); 69 | void sha256_final(sha256_ctx *ctx, unsigned char *digest); 70 | void sha256(const unsigned char *message, unsigned int len, 71 | unsigned char *digest); 72 | 73 | #endif /* !SHA2_H */ 74 | -------------------------------------------------------------------------------- /sha256_sse2_amd64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Mark Crichton 3 | * Copyright 2012-2013 Luke Dashjr 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 2 of the License, or (at your option) 8 | * any later version. 9 | * 10 | */ 11 | 12 | #include "config.h" 13 | 14 | #include "driver-cpu.h" 15 | 16 | #ifdef WANT_X8664_SSE2 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | extern void sha256_sse2_64_new (__m128i *res, __m128i *res1, __m128i *data, const uint32_t init[8])__asm__("sha256_sse2_64_new"); 27 | 28 | static uint32_t g_sha256_k[]__attribute__((aligned(0x100))) = { 29 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */ 30 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 31 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /* 8 */ 32 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 33 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */ 34 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 35 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */ 36 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 37 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */ 38 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 39 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */ 40 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 41 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */ 42 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 43 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */ 44 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 45 | }; 46 | 47 | 48 | const uint32_t sha256_init_sse2[8]__asm__("sha256_init_sse2")__attribute__((aligned(0x100))) = 49 | {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; 50 | 51 | __m128i sha256_consts_m128i[64]__asm__("sha256_consts_m128i")__attribute__((aligned(0x1000))); 52 | 53 | bool scanhash_sse2_64(struct thr_info * const thr, struct work * const work, 54 | uint32_t max_nonce, uint32_t *last_nonce, 55 | uint32_t nonce) 56 | { 57 | const uint8_t * const pmidstate = work->midstate; 58 | uint8_t *pdata = work->data; 59 | const uint32_t * const phash1 = hash1_init; 60 | uint8_t * const phash = work->hash; 61 | 62 | uint32_t *hash32 = (uint32_t *)phash; 63 | uint32_t *nNonce_p = (uint32_t *)(pdata + 76); 64 | uint32_t m_midstate[8], m_w[16], m_w1[16]; 65 | __m128i m_4w[64] __attribute__ ((aligned (0x100))); 66 | __m128i m_4hash[64] __attribute__ ((aligned (0x100))); 67 | __m128i m_4hash1[64] __attribute__ ((aligned (0x100))); 68 | __m128i offset; 69 | int i; 70 | 71 | pdata += 64; 72 | 73 | /* For debugging */ 74 | union { 75 | __m128i m; 76 | uint32_t i[4]; 77 | } mi; 78 | 79 | /* Message expansion */ 80 | memcpy(m_midstate, pmidstate, sizeof(m_midstate)); 81 | memcpy(m_w, pdata, sizeof(m_w)); /* The 2nd half of the data */ 82 | memcpy(m_w1, phash1, sizeof(m_w1)); 83 | memset(m_4hash, 0, sizeof(m_4hash)); 84 | 85 | /* Transmongrify */ 86 | for (i = 0; i < 16; i++) 87 | m_4w[i] = _mm_set1_epi32(m_w[i]); 88 | 89 | for (i = 0; i < 16; i++) 90 | m_4hash1[i] = _mm_set1_epi32(m_w1[i]); 91 | 92 | for (i = 0; i < 64; i++) 93 | sha256_consts_m128i[i] = _mm_set1_epi32(g_sha256_k[i]); 94 | 95 | offset = _mm_set_epi32(0x3, 0x2, 0x1, 0x0); 96 | 97 | for (;;) 98 | { 99 | int j; 100 | 101 | m_4w[3] = _mm_add_epi32(offset, _mm_set1_epi32(nonce)); 102 | 103 | sha256_sse2_64_new (m_4hash, m_4hash1, m_4w, m_midstate); 104 | 105 | for (j = 0; j < 4; j++) { 106 | mi.m = m_4hash[7]; 107 | if (unlikely(mi.i[j] == 0)) 108 | break; 109 | } 110 | 111 | /* If j = true, we found a hit...so check it */ 112 | /* Use the C version for a check... */ 113 | if (unlikely(j != 4)) { 114 | for (i = 0; i < 8; i++) { 115 | mi.m = m_4hash[i]; 116 | *(uint32_t *)&(phash)[i*4] = mi.i[j]; 117 | } 118 | 119 | if (unlikely(hash32[7] == 0)) 120 | { 121 | nonce += j; 122 | *last_nonce = nonce + 1; 123 | *nNonce_p = nonce; 124 | return true; 125 | } 126 | } 127 | 128 | if (unlikely((nonce >= max_nonce) || thr->work_restart)) 129 | { 130 | *last_nonce = nonce; 131 | return false; 132 | } 133 | 134 | nonce += 4; 135 | } 136 | } 137 | 138 | #endif /* WANT_X8664_SSE2 */ 139 | 140 | -------------------------------------------------------------------------------- /sha256_sse2_i386.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Mark Crichton 3 | * Copyright 2012-2013 Luke Dashjr 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 2 of the License, or (at your option) 8 | * any later version. 9 | * 10 | */ 11 | 12 | #include "config.h" 13 | 14 | #include "driver-cpu.h" 15 | 16 | #ifdef WANT_X8632_SSE2 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | extern void CalcSha256_x86 (__m128i *res, __m128i *data, const uint32_t init[8])__asm__("CalcSha256_x86")__attribute__((fastcall)); 27 | 28 | static uint32_t g_sha256_k[]__attribute__((aligned(0x100))) = { 29 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */ 30 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 31 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /* 8 */ 32 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 33 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */ 34 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 35 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */ 36 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 37 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */ 38 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 39 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */ 40 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 41 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */ 42 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 43 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */ 44 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 45 | }; 46 | 47 | 48 | const uint32_t sha256_32init[8]__attribute__((aligned(0x100))) = 49 | {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; 50 | 51 | __m128i sha256_consts_m128i[64]__asm__("sha256_consts_m128i")__attribute__((aligned(0x1000))); 52 | 53 | bool scanhash_sse2_32(struct thr_info * const thr, struct work * const work, 54 | uint32_t max_nonce, uint32_t *last_nonce, 55 | uint32_t nonce) 56 | { 57 | const uint8_t * const pmidstate = work->midstate; 58 | uint8_t *pdata = work->data; 59 | const uint32_t * const phash1 = hash1_init; 60 | uint8_t * const phash = work->hash; 61 | 62 | uint32_t *hash32 = (uint32_t *)phash; 63 | uint32_t *nNonce_p = (uint32_t *)(pdata + 76); 64 | uint32_t m_midstate[8], m_w[16], m_w1[16]; 65 | __m128i m_4w[64] __attribute__ ((aligned (0x100))); 66 | __m128i m_4hash[64] __attribute__ ((aligned (0x100))); 67 | __m128i m_4hash1[64] __attribute__ ((aligned (0x100))); 68 | __m128i offset; 69 | int i; 70 | 71 | pdata += 64; 72 | 73 | /* Message expansion */ 74 | memcpy(m_midstate, pmidstate, sizeof(m_midstate)); 75 | memcpy(m_w, pdata, sizeof(m_w)); /* The 2nd half of the data */ 76 | memcpy(m_w1, phash1, sizeof(m_w1)); 77 | memset(m_4hash, 0, sizeof(m_4hash)); 78 | 79 | /* Transmongrify */ 80 | for (i = 0; i < 16; i++) 81 | m_4w[i] = _mm_set1_epi32(m_w[i]); 82 | 83 | for (i = 0; i < 16; i++) 84 | m_4hash1[i] = _mm_set1_epi32(m_w1[i]); 85 | 86 | for (i = 0; i < 64; i++) 87 | sha256_consts_m128i[i] = _mm_set1_epi32(g_sha256_k[i]); 88 | 89 | offset = _mm_set_epi32(0x3, 0x2, 0x1, 0x0); 90 | 91 | for (;;) 92 | { 93 | int j; 94 | 95 | m_4w[3] = _mm_add_epi32(offset, _mm_set1_epi32(nonce)); 96 | 97 | /* Some optimization can be done here W.R.T. precalculating some hash */ 98 | CalcSha256_x86 (m_4hash1, m_4w, m_midstate); 99 | CalcSha256_x86 (m_4hash, m_4hash1, sha256_32init); 100 | 101 | for (j = 0; j < 4; j++) { 102 | if (unlikely(((uint32_t *)&(m_4hash[7]))[j] == 0)) { 103 | /* We found a hit...so check it */ 104 | /* Use the C version for a check... */ 105 | 106 | for (i = 0; i < 8; i++) { 107 | *(uint32_t *)&(phash)[i<<2] = ((uint32_t *)&(m_4hash[i]))[j]; 108 | } 109 | 110 | if (unlikely(hash32[7] == 0)) 111 | { 112 | nonce += j; 113 | *last_nonce = nonce; 114 | *nNonce_p = nonce; 115 | return true; 116 | } 117 | } 118 | } 119 | 120 | if (unlikely((nonce >= max_nonce) || thr->work_restart)) { 121 | *last_nonce = nonce; 122 | return false; 123 | } 124 | 125 | nonce += 4; 126 | 127 | } 128 | } 129 | 130 | #endif /* WANT_X8632_SSE2 */ 131 | 132 | -------------------------------------------------------------------------------- /sha256_sse4_amd64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Mark Crichton 3 | * Copyright 2012-2013 Luke Dashjr 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation; either version 2 of the License, or (at your option) 8 | * any later version. 9 | * 10 | */ 11 | 12 | #include "config.h" 13 | 14 | #include "driver-cpu.h" 15 | 16 | #ifdef WANT_X8664_SSE4 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | extern void CalcSha256_x64_sse4(__m128i *res, __m128i *data, uint32_t init[8])__asm__("CalcSha256_x64_sse4"); 27 | 28 | static uint32_t g_sha256_k[] = { 29 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */ 30 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 31 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /* 8 */ 32 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 33 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */ 34 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 35 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */ 36 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 37 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */ 38 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 39 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */ 40 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 41 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */ 42 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 43 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */ 44 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 45 | }; 46 | 47 | 48 | static uint32_t g_sha256_hinit[8] = 49 | {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; 50 | 51 | __m128i g_4sha256_k[64]__asm__("g_4sha256_k"); 52 | 53 | bool scanhash_sse4_64(struct thr_info * const thr, struct work * const work, 54 | uint32_t max_nonce, uint32_t *last_nonce, 55 | uint32_t nonce) 56 | { 57 | const uint8_t * const pmidstate = work->midstate; 58 | uint8_t *pdata = work->data; 59 | const uint32_t * const phash1 = hash1_init; 60 | uint8_t * const phash = work->hash; 61 | 62 | uint32_t *hash32 = (uint32_t *)phash; 63 | uint32_t *nNonce_p = (uint32_t *)(pdata + 76); 64 | uint32_t m_midstate[8], m_w[16], m_w1[16]; 65 | __m128i m_4w[64], m_4hash[64], m_4hash1[64]; 66 | __m128i offset; 67 | int i; 68 | 69 | pdata += 64; 70 | 71 | /* For debugging */ 72 | union { 73 | __m128i m; 74 | uint32_t i[4]; 75 | } mi; 76 | 77 | /* Message expansion */ 78 | memcpy(m_midstate, pmidstate, sizeof(m_midstate)); 79 | memcpy(m_w, pdata, sizeof(m_w)); /* The 2nd half of the data */ 80 | memcpy(m_w1, phash1, sizeof(m_w1)); 81 | memset(m_4hash, 0, sizeof(m_4hash)); 82 | 83 | /* Transmongrify */ 84 | for (i = 0; i < 16; i++) 85 | m_4w[i] = _mm_set1_epi32(m_w[i]); 86 | 87 | for (i = 0; i < 16; i++) 88 | m_4hash1[i] = _mm_set1_epi32(m_w1[i]); 89 | 90 | for (i = 0; i < 64; i++) 91 | g_4sha256_k[i] = _mm_set1_epi32(g_sha256_k[i]); 92 | 93 | offset = _mm_set_epi32(0x3, 0x2, 0x1, 0x0); 94 | 95 | for (;;) 96 | { 97 | int j; 98 | 99 | m_4w[3] = _mm_add_epi32(offset, _mm_set1_epi32(nonce)); 100 | 101 | /* Some optimization can be done here W.R.T. precalculating some hash */ 102 | CalcSha256_x64_sse4(m_4hash1, m_4w, m_midstate); 103 | CalcSha256_x64_sse4(m_4hash, m_4hash1, g_sha256_hinit); 104 | 105 | for (j = 0; j < 4; j++) { 106 | mi.m = m_4hash[7]; 107 | if (unlikely(mi.i[j] == 0)) 108 | break; 109 | } 110 | 111 | /* If j = true, we found a hit...so check it */ 112 | /* Use the C version for a check... */ 113 | if (unlikely(j != 4)) { 114 | for (i = 0; i < 8; i++) { 115 | mi.m = m_4hash[i]; 116 | *(uint32_t *)&(phash)[i*4] = mi.i[j]; 117 | } 118 | 119 | if (unlikely(hash32[7] == 0)) 120 | { 121 | nonce += j; 122 | *last_nonce = nonce; 123 | *nNonce_p = nonce; 124 | return true; 125 | } 126 | } 127 | 128 | if (unlikely((nonce >= max_nonce) || thr->work_restart)) 129 | { 130 | *last_nonce = nonce; 131 | return false; 132 | } 133 | 134 | nonce += 4; 135 | } 136 | } 137 | 138 | #endif /* WANT_X8664_SSE4 */ 139 | 140 | -------------------------------------------------------------------------------- /sha256_via.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2011 Jeff Garzik 3 | * Copyright 2012-2013 Luke Dashjr 4 | * Copyright 2011-2012 Con Kolivas 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 3 of the License, or (at your option) 9 | * any later version. See COPYING for more details. 10 | */ 11 | 12 | #include "config.h" 13 | 14 | #include "driver-cpu.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "miner.h" 23 | 24 | #ifdef WANT_VIA_PADLOCK 25 | 26 | static void via_sha256(void *hash, void *buf, unsigned len) 27 | { 28 | unsigned stat = 0; 29 | asm volatile(".byte 0xf3, 0x0f, 0xa6, 0xd0" 30 | :"+S"(buf), "+a"(stat) 31 | :"c"(len), "D" (hash) 32 | :"memory"); 33 | } 34 | 35 | bool scanhash_via(struct thr_info * const thr, struct work * const work, 36 | uint32_t max_nonce, uint32_t *last_nonce, 37 | uint32_t n) 38 | { 39 | uint8_t * const data_inout = work->data; 40 | 41 | unsigned char data[128] __attribute__((aligned(128))); 42 | unsigned char tmp_hash[32] __attribute__((aligned(128))); 43 | unsigned char tmp_hash1[32] __attribute__((aligned(128))); 44 | uint32_t *data32 = (uint32_t *) data; 45 | uint32_t *hash32 = (uint32_t *) tmp_hash; 46 | uint32_t *nonce = (uint32_t *)(data + 64 + 12); 47 | uint32_t *nonce_inout = (uint32_t *)(data_inout + 64 + 12); 48 | unsigned long stat_ctr = 0; 49 | 50 | /* bitcoin gives us big endian input, but via wants LE, 51 | * so we reverse the swapping bitcoin has already done (extra work) 52 | * in order to permit the hardware to swap everything 53 | * back to BE again (extra work). 54 | */ 55 | swap32yes(data32, data_inout, 128/4); 56 | 57 | while (1) { 58 | *nonce = n; 59 | 60 | /* first SHA256 transform */ 61 | memcpy(tmp_hash1, sha256_init_state, 32); 62 | via_sha256(tmp_hash1, data, 80); /* or maybe 128? */ 63 | 64 | swap32yes(tmp_hash1, tmp_hash1, 32/4); 65 | 66 | /* second SHA256 transform */ 67 | memcpy(tmp_hash, sha256_init_state, 32); 68 | via_sha256(tmp_hash, tmp_hash1, 32); 69 | 70 | stat_ctr++; 71 | 72 | if (unlikely((hash32[7] == 0))) 73 | { 74 | /* swap nonce'd data back into original storage area; 75 | */ 76 | *nonce_inout = bswap_32(n); 77 | *last_nonce = n; 78 | return true; 79 | } 80 | 81 | if ((n >= max_nonce) || thr->work_restart) { 82 | *last_nonce = n; 83 | return false; 84 | } 85 | 86 | n++; 87 | } 88 | } 89 | 90 | #endif /* WANT_VIA_PADLOCK */ 91 | 92 | -------------------------------------------------------------------------------- /start-bfgminer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | n=" 3 | " 4 | startscreen() { 5 | name="$1"; shift 6 | cmd="$1"; shift 7 | if ! screen -ls | grep -q "^[[:space:]]\+[0-9]\+\.$name"; then 8 | screen -dmS "$name" 9 | else 10 | for i in 1 2 3; do 11 | screen -x "$name" -p 0 -X stuff $(echo 'x' | tr 'x' '\003') 12 | done 13 | screen -x "$name" -p 0 -X stuff "stty sane$n" 14 | fi 15 | screen -x "$name" -p 0 -X stuff "$cmd$n" 16 | } 17 | PROG=bfgminer 18 | MYDIR="$(dirname "$0")" 19 | WHICHPROG="$(which "$PROG" 2>/dev/null)" 20 | if test -f "$MYDIR/$PROG" && test "$(realpath "$WHICHPROG" 2>/dev/null)" != "$(realpath "$MYDIR/$PROG")"; then 21 | PROG="cd $(realpath -s "$MYDIR")$n./$PROG" 22 | fi 23 | startscreen miner "${PROG} ${BFGMINER_OPTS}" 24 | -------------------------------------------------------------------------------- /test-bfgminer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo $PATH 3 | bfgminer --unittest --no-default-config --scan noauto -d? 4 | -------------------------------------------------------------------------------- /titan-asic.h: -------------------------------------------------------------------------------- 1 | #ifndef __TITAN_ASIC_H 2 | #define __TITAN_ASIC_H 3 | 4 | #include "knc-asic/knc-asic.h" 5 | #include "knc-asic/knc-transport.h" 6 | 7 | #define KNC_TITAN_MAX_ASICS 6 8 | #define KNC_TITAN_DIES_PER_ASIC 4 9 | #define KNC_TITAN_CORES_PER_DIE 571 10 | #define KNC_TITAN_CORES_PER_ASIC (KNC_TITAN_CORES_PER_DIE * KNC_TITAN_DIES_PER_ASIC) 11 | #define KNC_TITAN_WORKSLOTS_PER_CORE 2 12 | #define KNC_TITAN_THREADS_PER_CORE 8 13 | #define KNC_TITAN_NONCES_PER_REPORT 5 14 | 15 | /* Valid slot numbers: 1..15 */ 16 | #define KNC_TITAN_MIN_WORK_SLOT_NUM 1 17 | #define KNC_TITAN_MAX_WORK_SLOT_NUM 15 18 | 19 | #define KNC_TITAN_FPGA_SYSCLK_FREQ 24576000 20 | #define KNC_TITAN_FPGA_SPI_FREQ 6144000 21 | #define KNC_TITAN_FPGA_SPI_DIVIDER (KNC_TITAN_FPGA_SYSCLK_FREQ / (2*KNC_TITAN_FPGA_SPI_FREQ) - 1) 22 | #if KNC_TITAN_FPGA_SYSCLK_FREQ % (2*KNC_TITAN_FPGA_SPI_FREQ) != 0 23 | #warning Requested SPI frequency could not be accomplished exactly, adjusting as needed 24 | #endif 25 | #define KNC_TITAN_FPGA_SPI_PRECLK 7 26 | #define KNC_TITAN_FPGA_SPI_DECLK 7 27 | #define KNC_TITAN_FPGA_SPI_SSLOWMIN 15 28 | #define KNC_TITAN_FPGA_RETRIES 1 29 | 30 | struct nonce_report { 31 | uint32_t nonce; 32 | uint8_t slot; 33 | }; 34 | 35 | bool knc_titan_get_info(int log_level, void * const ctx, int channel, int die, struct knc_die_info *die_info); 36 | bool knc_titan_set_work(const char *repr, void * const ctx, int channel, int die, int core, int slot, struct work *work, bool urgent, bool *work_accepted, struct knc_report *report); 37 | bool knc_titan_set_work_multi(const char *repr, void * const ctx, int channel, int die, int core_start, int slot, struct work *work, bool urgent, bool *work_accepted, struct knc_report *reports, int num); 38 | bool knc_titan_get_report(const char *repr, void * const ctx, int channel, int die, int core, struct knc_report *report); 39 | bool knc_titan_setup_core_local(const char *repr, void * const ctx, int channel, int die, int core, struct titan_setup_core_params *params); 40 | bool knc_titan_setup_spi(const char *repr, void * const ctx, int asic, int divider, int preclk, int declk, int sslowmin); 41 | bool knc_titan_set_work_parallel(const char *repr, void * const ctx, int asic, int die, int core_start, int slot, struct work *work, bool urgent, int num, int resend); 42 | bool knc_titan_get_work_status(const char *repr, void * const ctx, int asic, int *num_request_busy, int *num_status_byte_error); 43 | 44 | #endif /* __TITAN_ASIC_H */ 45 | -------------------------------------------------------------------------------- /tm_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 gluk 3 | * Copyright 2013 Anatoly Legkodymov 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | #include "config.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef NEED_LINUX_I2C_H 31 | #include 32 | #endif 33 | #include 34 | 35 | #include "logging.h" 36 | #include "tm_i2c.h" 37 | 38 | static int tm_i2c_fd; 39 | 40 | float tm_i2c_Data2Temp(unsigned int ans) { 41 | float t = ans; 42 | return (t / 1023.0 * 3.3 * 2-2.73) * 100.0; 43 | } 44 | 45 | float tm_i2c_Data2Core(unsigned int ans) { 46 | float t = ans; 47 | return t / 1023.0 * 3.3; 48 | } 49 | 50 | int tm_i2c_init() { 51 | if ((tm_i2c_fd = open("/dev/i2c-1", O_RDWR)) < 0) 52 | return 1; 53 | else 54 | return 0; 55 | } 56 | 57 | void tm_i2c_close() { 58 | close(tm_i2c_fd); 59 | } 60 | 61 | unsigned int tm_i2c_req(int fd, unsigned char addr, unsigned char cmd, unsigned int data) { 62 | int i; 63 | unsigned char buf[16]; 64 | struct i2c_msg msg; 65 | tm_struct *tm = (tm_struct *) buf; 66 | struct i2c_rdwr_ioctl_data msg_rdwr; 67 | unsigned int ret; 68 | 69 | //applog(LOG_DEBUG, "REQ from %02X cmd: %02X", addr, cmd); 70 | 71 | tm->cmd = cmd; 72 | tm->data_lsb = data & 0xFF; 73 | tm->data_msb = (data & 0xFF00) >> 8; 74 | 75 | /* Write CMD */ 76 | msg.addr = addr; 77 | msg.flags = 0; 78 | msg.len = 3; 79 | msg.buf = (void*)tm; 80 | msg_rdwr.msgs = &msg; 81 | msg_rdwr.nmsgs = 1; 82 | if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) { 83 | // perror("ioctl error"); 84 | return -1; 85 | } 86 | 87 | /* Read result */ 88 | msg.addr = addr; 89 | msg.flags = I2C_M_RD; 90 | msg.len = 3; 91 | msg.buf = (void*)tm; 92 | msg_rdwr.msgs = &msg; 93 | msg_rdwr.nmsgs = 1; 94 | if ((i = ioctl(fd, I2C_RDWR, &msg_rdwr)) < 0) { 95 | // perror("ioctl error"); 96 | return -1; 97 | } 98 | 99 | ret = (tm->data_msb << 8) + tm->data_lsb; 100 | if (tm->cmd == cmd) return ret; 101 | return 0; 102 | } 103 | 104 | int tm_i2c_detect(unsigned char slot) { 105 | if (slot < 0 || slot > 31) return 0; 106 | return tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_GET_CORE0, 0); 107 | } 108 | 109 | float tm_i2c_getcore0(unsigned char slot) { 110 | if (slot < 0 || slot > 31) return 0; 111 | return tm_i2c_Data2Core(tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_GET_CORE0, 0)); 112 | } 113 | 114 | float tm_i2c_getcore1(unsigned char slot) { 115 | if (slot < 0 || slot > 31) return 0; 116 | return tm_i2c_Data2Core(tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_GET_CORE1, 0)); 117 | } 118 | 119 | float tm_i2c_gettemp(unsigned char slot) { 120 | if (slot < 0 || slot > 31) return 0; 121 | return tm_i2c_Data2Temp(tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_GET_TEMP, 0)); 122 | } 123 | 124 | void tm_i2c_set_oe(unsigned char slot) { 125 | if (slot < 0 || slot > 31) return; 126 | tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_SET_OE, 0); 127 | } 128 | 129 | void tm_i2c_clear_oe(unsigned char slot) { 130 | if (slot < 0 || slot > 31) return; 131 | tm_i2c_req(tm_i2c_fd, (TM_ADDR >> 1) + slot, TM_SET_OE, 1); 132 | } 133 | 134 | unsigned char tm_i2c_slot2addr(unsigned char slot) { 135 | if (slot < 0 || slot > 31) return 0; 136 | return ((TM_ADDR >> 1) + slot); 137 | } 138 | 139 | -------------------------------------------------------------------------------- /tm_i2c.h: -------------------------------------------------------------------------------- 1 | /* - Version 1.0 - */ 2 | 3 | #define TM_ADDR 0xC0 4 | 5 | #define TM_GET_TEMP 0x10 6 | #define TM_GET_CORE0 0x11 7 | #define TM_GET_CORE1 0x12 8 | 9 | #define TM_SET_OE 0x20 10 | #define TM_SET_MODE 0x21 11 | #define TM_SET_RED 0x22 12 | #define TM_SET_GREEN 0x23 13 | 14 | #define TM_GET_PORTB 0x30 15 | #define TM_SET_PORTB 0x31 16 | #define TM_GET_PINB 0x32 17 | #define TM_GET_PORTD 0x33 18 | #define TM_SET_PORTD 0x34 19 | #define TM_GET_PIND 0x35 20 | #define TM_GET_ADC 0x36 21 | 22 | #define TM_MODE_AUTO 0 23 | #define TM_MODE_MANUAL 1 24 | 25 | typedef struct { 26 | unsigned char cmd; 27 | unsigned char data_lsb; 28 | unsigned char data_msb; 29 | } tm_struct; 30 | 31 | int tm_i2c_init(); 32 | void tm_i2c_close(); 33 | unsigned int tm_i2c_req(int fd, unsigned char addr, unsigned char cmd, unsigned int data); 34 | float tm_i2c_Data2Temp(unsigned int ans); 35 | float tm_i2c_Data2Core(unsigned int ans); 36 | float tm_i2c_gettemp(unsigned char slot); 37 | float tm_i2c_getcore0(unsigned char slot); 38 | float tm_i2c_getcore1(unsigned char slot); 39 | void tm_i2c_set_oe(unsigned char slot); 40 | void tm_i2c_clear_oe(unsigned char slot); 41 | int tm_i2c_detect(unsigned char slot); 42 | unsigned char tm_i2c_slot2addr(unsigned char slot); 43 | 44 | -------------------------------------------------------------------------------- /todo_ztex.txt: -------------------------------------------------------------------------------- 1 | - verify setting cgpu.status=DEAD does in fact stop the thread 2 | - allow configuring bitstream directory 3 | - HS fpga config 4 | - allow configuring LIBZTEX_OVERHEATTHRESHOLD 5 | - hotplug support? 6 | -------------------------------------------------------------------------------- /usbtest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright 2012-2013 Xiangfu 3 | # Copyright 2012-2013 Andrew Smith 4 | # Copyright 2013 Luke Dashjr 5 | # 6 | # This program is free software; you can redistribute it and/or modify it under 7 | # the terms of the GNU General Public License as published by the Free Software 8 | # Foundation; either version 3 of the License, or (at your option) any later 9 | # version. See COPYING for more details. 10 | 11 | # Linux usage: ./usbtest.py /dev/ttyUSB0 0xhexcodes|string|icarus 12 | # OR python usbtest.py /dev/ttyUSB0 0xhexcodes|string|icarus 13 | # 14 | # Windows usage: ./usbtest.py COM1 0xhexcodes|string|icarus 15 | # 16 | # sends the data sepcified to the USB device and waits 17 | # for a reply then displays it 18 | # 19 | # the data can be: 20 | # 0xhexcodes: e.g. 0x68656c6c6f20776f726c640a 21 | # would send "hello world\n" 22 | # 23 | # string: e.g. sendsometext 24 | # 25 | # icarus: sends 2 known block payloads for an icarus device 26 | # and shows the expected and actual answers if it's 27 | # a working V3 icarus 28 | 29 | import sys 30 | import serial 31 | import binascii 32 | 33 | if len(sys.argv) < 2: 34 | sys.stderr.write("Usage: " + sys.argv[0] + " device strings...\n") 35 | sys.stderr.write(" where device is either like /dev/ttyUSB0 or COM1\n") 36 | sys.stderr.write(" and strings are either '0xXXXX' or 'text'\n") 37 | sys.stderr.write(" if the first string is 'icarus' the rest are ignored\n") 38 | sys.stderr.write(" and 2 valid icarus test payloads are sent with results displayed\n") 39 | sys.stderr.write("\nAfter any command is sent it waits up to 30 seconds for a reply\n"); 40 | sys.exit("Aborting") 41 | 42 | # Open with a 10 second timeout - just to be sure 43 | ser = serial.Serial(sys.argv[1], 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 10, False, False, 5) 44 | 45 | if sys.argv[2] == "icarus": 46 | 47 | # This show how Icarus use the block and midstate data 48 | # This will produce nonce 063c5e01 49 | block = "0000000120c8222d0497a7ab44a1a2c7bf39de941c9970b1dc7cdc400000079700000000e88aabe1f353238c668d8a4df9318e614c10c474f8cdf8bc5f6397b946c33d7c4e7242c31a098ea500000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000" 50 | midstate = "33c5bf5751ec7f7e056443b5aee3800331432c83f404d9de38b94ecbf907b92d" 51 | 52 | rdata2 = binascii.a2b_hex(block.encode('ascii'))[95:63:-1] 53 | rmid = binascii.a2b_hex(midstate.encode('ascii'))[::-1] 54 | payload = rmid + rdata2 55 | 56 | print("Push payload to icarus: " + binascii.hexlify(payload).decode('ascii')) 57 | ser.write(payload) 58 | 59 | b=ser.read(4) 60 | print("Result:(should be: 063c5e01): " + binascii.hexlify(b).decode('ascii')) 61 | 62 | # Just another test 63 | payload2 = "ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8" 64 | print("Push payload to icarus: " + payload2) 65 | ser.write(binascii.a2b_hex(payload2.encode('ascii'))) 66 | 67 | b=ser.read(4) 68 | print("Result:(should be: 8e0b31c5): " + binascii.hexlify(b).decode('ascii')) 69 | else: 70 | data = b"" 71 | for arg in sys.argv[2::]: 72 | if arg[0:2:] == '0x': 73 | data += binascii.a2b_hex(arg[2::].encode('ascii')) 74 | else: 75 | data += arg.encode('latin-1') 76 | 77 | print("Sending: 0x" + binascii.hexlify(data).decode('ascii')) 78 | ser.write(data) 79 | 80 | # If you're expecting more than one linefeed terminated reply, 81 | # you'll only see the first one 82 | # AND with no linefeed, this will wait the 10 seconds before returning 83 | print("Waiting up to 10 seconds ...") 84 | b=ser.readline() 85 | print("Result: hex 0x" + binascii.hexlify(b).decode('ascii')) 86 | 87 | print("Result: asc %s" % (repr(b),)) 88 | 89 | ser.close() 90 | -------------------------------------------------------------------------------- /version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include "version.h" 13 | 14 | const char * const bfgminer_name_space_ver = PACKAGE " " VERSION; 15 | const char * const bfgminer_name_slash_ver = PACKAGE "/" VERSION; 16 | const char * const bfgminer_ver = VERSION; 17 | -------------------------------------------------------------------------------- /winhacks.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_WINHACKS_H 2 | #define BFG_WINHACKS_H 3 | 4 | #include 5 | 6 | // wincon.h contains a KEY_EVENT that conflicts with ncurses 7 | #include 8 | #ifdef KEY_EVENT 9 | # undef KEY_EVENT 10 | #endif 11 | // wincon.h contains a MOUSE_MOVED that conflicts with curses 12 | #ifdef MOUSE_MOVED 13 | # undef MOUSE_MOVED 14 | #endif 15 | 16 | #ifdef interface 17 | #undef interface 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /work2d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2016 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #include "config.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "miner.h" 18 | #include "util.h" 19 | #include "work2d.h" 20 | 21 | #define MAX_DIVISIONS WORK2D_MAX_DIVISIONS 22 | 23 | static bool work2d_reserved[MAX_DIVISIONS + 1] = { true }; 24 | int work2d_xnonce1sz; 25 | int work2d_xnonce2sz; 26 | 27 | void work2d_init() 28 | { 29 | RUNONCE(); 30 | 31 | for (uint64_t n = MAX_DIVISIONS; n; n >>= 8) 32 | ++work2d_xnonce1sz; 33 | work2d_xnonce2sz = 2; 34 | } 35 | 36 | bool reserve_work2d_(uint32_t * const xnonce1_p) 37 | { 38 | uint32_t xnonce1; 39 | for (xnonce1 = MAX_DIVISIONS; work2d_reserved[xnonce1]; --xnonce1) 40 | if (!xnonce1) 41 | return false; 42 | work2d_reserved[xnonce1] = true; 43 | *xnonce1_p = htole32(xnonce1); 44 | return true; 45 | } 46 | 47 | void release_work2d_(uint32_t xnonce1) 48 | { 49 | xnonce1 = le32toh(xnonce1); 50 | work2d_reserved[xnonce1] = false; 51 | } 52 | 53 | int work2d_pad_xnonce_size(const struct stratum_work * const swork) 54 | { 55 | return swork->n2size - work2d_xnonce1sz - work2d_xnonce2sz; 56 | } 57 | 58 | void *work2d_pad_xnonce(void * const buf_, const struct stratum_work * const swork, const bool hex) 59 | { 60 | uint8_t * const buf = buf_; 61 | int pad = work2d_pad_xnonce_size(swork); 62 | if (pad < 0) 63 | return NULL; 64 | if (hex) 65 | { 66 | pad *= 2; 67 | memset(buf, 'b', pad); 68 | } 69 | else 70 | memset(buf, '\xbb', pad); 71 | return &buf[pad]; 72 | } 73 | 74 | static void work2d_gen_dummy_work_prepare(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared) 75 | { 76 | *work = (struct work){ 77 | .pool = swork->pool, 78 | .work_restart_id = swork->work_restart_id, 79 | .tv_staged = *tvp_prepared, 80 | }; 81 | } 82 | 83 | void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared, const void * const xnonce2, const uint32_t xnonce1) 84 | { 85 | uint8_t *p, *s; 86 | 87 | work2d_gen_dummy_work_prepare(work, swork, tvp_prepared); 88 | 89 | bytes_resize(&work->nonce2, swork->n2size); 90 | s = bytes_buf(&work->nonce2); 91 | p = &s[swork->n2size - work2d_xnonce2sz]; 92 | if (xnonce2) 93 | memcpy(p, xnonce2, work2d_xnonce2sz); 94 | #ifndef __OPTIMIZE__ 95 | else 96 | memset(p, '\0', work2d_xnonce2sz); 97 | #endif 98 | p -= work2d_xnonce1sz; 99 | memcpy(p, &xnonce1, work2d_xnonce1sz); 100 | work2d_pad_xnonce(s, swork, false); 101 | gen_stratum_work2(work, swork); 102 | } 103 | 104 | void work2d_gen_dummy_work_for_stale_check(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared, cglock_t * const data_lock_p) 105 | { 106 | work2d_gen_dummy_work_prepare(work, swork, tvp_prepared); 107 | gen_stratum_work3(work, swork, data_lock_p); 108 | } 109 | 110 | bool work2d_submit_nonce(struct thr_info * const thr, struct stratum_work * const swork, const struct timeval * const tvp_prepared, const void * const xnonce2, const uint32_t xnonce1, const uint32_t nonce, const uint32_t ntime, bool * const out_is_stale, const float nonce_diff) 111 | { 112 | struct work _work, *work; 113 | bool rv; 114 | 115 | // Generate dummy work 116 | work = &_work; 117 | work2d_gen_dummy_work(work, swork, tvp_prepared, xnonce2, xnonce1); 118 | *(uint32_t *)&work->data[68] = htobe32(ntime); 119 | work->nonce_diff = nonce_diff; 120 | work->rolltime = INT_MAX; // FIXME 121 | 122 | // Check if it's stale, if desired 123 | if (out_is_stale) 124 | *out_is_stale = stale_work(work, true); 125 | 126 | // Submit nonce 127 | rv = submit_nonce(thr, work, nonce); 128 | 129 | clean_work(work); 130 | 131 | return rv; 132 | } 133 | -------------------------------------------------------------------------------- /work2d.h: -------------------------------------------------------------------------------- 1 | #ifndef BFG_WORK2D_H 2 | #define BFG_WORK2D_H 3 | 4 | #include 5 | #include 6 | 7 | #define WORK2D_MAX_DIVISIONS 255 8 | 9 | extern int work2d_xnonce1sz; 10 | extern int work2d_xnonce2sz; 11 | 12 | extern void work2d_init(); 13 | extern bool reserve_work2d_(uint32_t *xnonce1_p); 14 | extern void release_work2d_(uint32_t xnonce1); 15 | 16 | extern int work2d_pad_xnonce_size(const struct stratum_work *); 17 | extern void *work2d_pad_xnonce(void *buf, const struct stratum_work *, bool hex); 18 | extern void work2d_gen_dummy_work(struct work *, struct stratum_work *, const struct timeval *tvp_prepared, const void *xnonce2, uint32_t xnonce1); 19 | extern void work2d_gen_dummy_work_for_stale_check(struct work *, struct stratum_work *, const struct timeval *tvp_prepared, cglock_t *data_lock_p); 20 | extern bool work2d_submit_nonce(struct thr_info *, struct stratum_work *, const struct timeval *tvp_prepared, const void *xnonce2, uint32_t xnonce1, uint32_t nonce, uint32_t ntime, bool *out_is_stale, float nonce_diff); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /x86_32/.gitignore: -------------------------------------------------------------------------------- 1 | libx8632.a 2 | -------------------------------------------------------------------------------- /x86_32/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libx8632.a 2 | 3 | SUFFIXES = .asm 4 | 5 | libx8632_a_SOURCES = sha256_xmm.asm 6 | 7 | .asm.o: 8 | $(YASM) -f $(YASM_FMT) $< 9 | -------------------------------------------------------------------------------- /x86_64/.gitignore: -------------------------------------------------------------------------------- 1 | libx8664.a 2 | -------------------------------------------------------------------------------- /x86_64/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libx8664.a 2 | 3 | SUFFIXES = .asm 4 | 5 | libx8664_a_SOURCES = sha256_xmm_amd64.asm sha256_sse4_amd64.asm 6 | 7 | .asm.o: 8 | $(YASM) -f $(YASM_FMT) -o $@ $< 9 | --------------------------------------------------------------------------------