Introducing a new way to review your PRs.

Read the announcement

luke-jr / bfgminer

Modular ASIC/FPGA miner written in C, featuring overclocking, monitoring, fan speed control and remote interface capabilities.

View on GitHub

13 documents · Updated Nov 16, 2026

docs / usb-stick-and-bitfury-drivers

USB Stick and BitFury Drivers

Overview

This area owns the small USB/serial miners that either speak a simple stick-miner protocol directly or wrap a BitFury/GC3355 ASIC protocol behind HID, USB bulk, MCP2210 SPI, or virtual COM transport.

The shared BitFury path is split between libbitfury.c/libbitfury.h and the concrete drivers. libbitfury.c is the low-level BitFury SPI protocol library: it formats work into struct bitfury_payload, derives the address-translated vector with bitfury_payload_to_atrvec, emits reinitialise/shutdown/frequency SPI sequences, probes chains with libbitfury_detectChips1, decodes chip nonces with bitfury_decnonce, and verifies/fudges candidate nonces with bitfury_fudge_nonce. driver-bitfury.c is the direct GPIO/SPI BitFury driver: detection calls spi_init and libbitfury_detectChips1, thread init allocates one struct bitfury_device per processor, and bitfury_do_io is the common asynchronous poller that walks all managed chips, emits spi_emit_break/spi_emit_fasync/spi_emit_data, rotates the 16-word nonce ring, handles job transitions, submits decoded nonces, tracks frequency, and reinitialises chips after desync or error bursts.

Several USB BitFury products reuse that common lifecycle while supplying only the transport and board controls:

  • driver-littlefury.c wraps BitFury SPI in a framed serial packet protocol (0xabcd, opcode, payload length, CRC). It probes with a version packet, powers chips through LFOP_REGPWR, implements littlefury_txrx as the spi_port backend, then delegates work preparation, polling, nonce accounting, and API/TUI clock controls to driver-bitfury.c.
  • driver-nanofury.c talks to an MCP2210 USB-to-SPI bridge. It toggles GPIOs for LED, SCK override, and power, configures MCP2210 SPI mode/speed, chunks transfers at 60 bytes, then creates BitFury chip records whose spi_port.txrx is nanofury_spi_txrx. Its poll path adds LED identify handling around bitfury_do_io.
  • driver-hashbuster.c uses HID reports with 64-byte command/response frames. It detects the board with command 0xfe, maps BitFury SPI operations to commands 0x01/0x02/0x03, limits transfers to 62 bytes, and reads temperature with command 0x04 while mining through the common BitFury async loop.
  • driver-hashbusterusb.c is the USB bulk variant. It opens endpoint pair 0x81/0x01, works around corrupt 0xff responses by retrying, detects/starts PSU and serial number through board commands, maps SPI to commands 0x01/0x02/0x03, and layers PSU voltage, VRM lock/unlock, RGB identify, and stats over the common BitFury loop.
  • driver-bifury.c is BitFury-family but firmware-driven rather than raw SPI. Detection opens the virtual COM port, sends version, parses firmware/hardware/chip count, and mining uses minerloop_queue: bifury_queue_append sends text work <76-byte-header-hex> <jobid>, bifury_poll reads newline-delimited submit, job, temp, hwerror, and needwork messages, and bifury_send_clock sends per-chip oscillator assignments.
  • driver-twinfury.c is another firmware protocol. Commands are prefixed with 0xDEADBEEF; detection sends I and R, init optionally queries voltage with V, twinfury_job_prepare fills a 46-byte work buffer with midstate and header tail, twinfury_job_start sends command W, and twinfury_poll queries each chip with Q, decodes BitFury nonces with bitfury_decnonce/bitfury_fudge_nonce, handles LED flash and temperature commands, and supports voltage adjustment for newer firmware.

The Icarus-style stick path is centered in driver-icarus.c. icarus_detect_custom probes a serial port by sending a golden 64-byte work item, expecting a known nonce, optionally probing work division, then creates a multi-processor cgpu_info. At runtime, icarus_prepare allocates per-thread state, icarus_init opens the serial device and prepares timing/work division, icarus_job_prepare serialises work as 32-byte midstate + 20 filler bytes + 12 header bytes, icarus_job_start writes it, and icarus_scanhash waits for a fixed-size nonce reply or timeout/restart. It estimates hashes from elapsed time and calibrated Hs, keeps the last two work items for late nonces, reopens flaky serial ports according to the configured reopen mode, and supports timing calibration through the timing set-device option. driver-erupter.c reuses this driver by copying icarus_drv at init and overriding detection metadata, low-level matching, device names (BES/BEE), and identify behavior.

The GC3355/GridSeed/DualMiner path uses serial commands with 0x55aa headers. gc3355.c/gc3355.h hold the command tables and helpers for reset, PLL configuration, SHA-2 gating, scrypt init/reset, work packing, firmware detection, and throttled serial I/O. driver-gridseed.c is a scrypt minerloop_scanhash driver: detection reads firmware via gc3355_get_firmware_version, infers chip count, calls gc3355_init_miner, sends prepared scrypt work after gc3355_scrypt_reset, polls 12-byte responses, and accounts hashes from elapsed time and configured frequency. driver-dualminer.c adapts the Icarus lifecycle for DualMiner hardware: it uses icarus_detect_custom with DualMiner golden work/nonce, selects SHA-2 or scrypt mode from build/runtime settings, initialises the GC3355 through gc3355_init_dualminer, prepares work through gc3355_sha2_prepare_work or gc3355_scrypt_prepare_work, and tears down serial control lines on shutdown.

driver-hashbusteravalon.c is a small product-specific wrapper rather than part of the BitFury helper stack. It matches HashBuster Avalon USB devices, seeds a klondike_info with defaults, and delegates probing/runtime to the Klondike driver by replacing hashbusteravalon_drv from klondike_drv during driver init.

Coverage

Owned globs:

Coupling

Risks

  • driver-bitfury.c is fragile around nonce-ring synchronisation. bitfury_do_io rotates 16-word buffers based on active, treats previous-nonce mismatches as hardware errors, and forces reinitialisation after repeated desync; if response ordering or fasync sequencing changes, valid nonces can be discarded or counted as hardware errors.
  • gc3355.c intentionally sleeps after every gc3355_write because comments note reproducible register corruption on Linux when writes are too close together. Removing or shortening GC3355_WRITE_DELAY_MS can corrupt GC3355 registers in driver-gridseed.c and driver-dualminer.c even if it appears fine on slower serial stacks.
  • driver-icarus.c sends golden work during detection to arbitrary serial scan targets and has comments warning that other devices must tolerate it. Changing the golden payload or probe flow can disturb non-Icarus devices on --scan-serial paths or cause false claims before serial_claim_v.