Avalon, Antminer, Bitmain, and Related ASIC Hardware Drivers
Overview
This area covers several large or closely related ASIC/FPGA-backed hardware drivers that sit directly on BFGMiner's device-driver interface and serial/virtual-COM low-level probing layers.
driver-avalon.c implements the original Avalon 1 serial protocol. Detection claims a virtual COM path through serial_claim, opens it at the configured Avalon baud rate, sends a reset task, reads the reset/status reply, registers one cgpu_info, then idles the ASICs before closing the fd until thread preparation. Runtime uses hash_queued_work: queue_full fills a rotating cgpu->works array with per-miner work, and scanwork serializes each struct avalon_task from driver-avalon.h with midstate and 12 bytes of tail data. The CTS line is treated as the device FIFO-full signal, and struct avalon_result replies carry nonce, work-identifying midstate/tail data, fans, temperatures, FIFO pointers, chip count, PWM, timeout, and miner count. Nonces are matched back to queued work with clone_queued_work_bymidstate and submitted with submit_nonce. Avalon configuration is exposed via set-device options for baud, miner count, ASIC count, timeout, and clock; API stats include those settings plus fan, temperature, maximum temperature, no-matching-work count, and per-miner match counters.
driver-avalonmm.c implements Avalon 2/3 modular miners over a packetized UART protocol rather than the Avalon 1 fixed task/result structs. Packets begin with AV, include a command/reply byte, packet index/count, 32 bytes of payload, and CRC16-XMODEM. Detection sends AMC_DETECT for up to four module IDs and creates one master/slave device chain, sharing a serial fd on the master while each module gets its own cgpu_info/thread state. Runtime uses work2d and Stratum work directly: avalonmm_send_swork uploads job metadata, target, job ID, coinbase with padded extranonces, merkle branches, block header, and finally AMC_START containing desired fan, voltage config, clock, extranonce2 start, and range. Poll replies update per-module temperatures, fans, actual clock, voltage config, and nonce results; nonce replies include module ID, job ID, backward extranonce2 bytes, and a nonce adjusted by AVALONMM_NONCE_OFFSET, then work2d_submit_nonce and hashes_done2 account for accepted shares. User/device controls set clock, fan percentage, and voltage.
driver-antminer.c covers Antminer U-series and GekkoScience Compac-style BM138x USB sticks by cloning the icarus_drv during driver init. Detection is virtual-COM/product-string based (Antminer or Compac/Bitcoin) and delegates the mining loop, timing, read/write, and queued work handling to icarus_detect_custom and the Icarus driver with Antminer-specific defaults: 115200 baud, long timing mode, 5-byte reads, no reopen, and optional BM1382/BM1384 frequency-register support inferred from the USB product string or --set antminer:chip=.... The Antminer-specific protocol surface is configuration: clock writes are four-byte BM138x register commands with CRC5, voltage writes are raw BITMAINtech lookup-table-style hex codes, and identify flashes the LED through a padded command. Because this driver inherits Icarus behavior, changes to its work submission or result handling live in the Icarus layer, while this file owns Antminer/Compac detection and control commands.
driver-bitmain.c and driver-bitmain.h implement the embedded-controller Bitmain S1-S5 driver. It can open either a local serial path or an ip: path via libcurl's connect-only socket mode; btm_read/btm_write hide that transport by wrapping network reads/writes in a small direction-and-length framing shim. Detection is explicit rather than fully autodetected: generic_detect requires -S bitmain... configuration, and bitmain_detect_one refuses to proceed until --set bitmain:model=... (or equivalent packet limits) and model-dependent register data are available. Initialization clears input, sends an RXSTATUS token, parses a 0xa1 status reply to learn chain count, FIFO space, hardware version, ASIC presence/status bitmaps, fans, and temperatures, then sends a TXCONFIG token with reset/fan/timeout/frequency/voltage/chip-config flags, chain layout, ASIC count, PWM, timeout, frequency, voltage bytes, register data, and CRC16. Mining uses minerloop_queue: queue_append batches multiple work items into one TXTASK packet with work IDs, midstates, tail data, difficulty fields, and CRC16, and poll parses buffered 0xa1 status and 0xa2 nonce packets. Nonce packets map device work IDs back through thr->work_list, set the work nonce difficulty from the Bitmain diff byte, call submit_nonce, and update accounting; unmatched work IDs and controller nonce-error deltas become hardware errors/no-matching-work. API stats expose configuration, hardware version, fans, temperatures, device hardware error percentage, chain ASIC counts, and textual chain ASIC status.
driver-bigpic.c/driver-bigpic.h implement Big Picture Mining Bitfury USB devices (Bitfury product BF1). Detection opens 115200 baud serial, sends I for a 14-byte identity, sends R for reset, waits for a 7-byte state reply, then registers one device. Runtime uses the async miner loop: job_prepare builds a 45-byte command (W + midstate + 12 tail bytes), job_start writes it, waits for acknowledgement and nonce/state records, and job_process_results decodes 7-byte result records. Nonces are Bitfury-decoded, de-duplicated, adjusted with bitfury_fudge_nonce, then submitted or counted as hardware errors. identify_device sends L to light/identify the unit. README.ASIC notes these devices are sensitive to unexpected probe data, so -S bigpic:all should be ordered before other serial scans.
driver-modminer.c implements ModMiner FPGA hardware using a serial command protocol and an uploaded Xilinx bitstream. Detection sends a ping/no-op burst to recover from devices left in work-read mode, reads a version string beginning with ModMiner, asks for FPGA count, then registers one multi-processor device with one mining thread per FPGA. During thread init each FPGA reads its USER code; if it does not match BISTREAM_USER_ID, or forced init is requested, modminer_fpga_upload_bitstream loads fpgaminer_x6500-overclocker-0402.bit via open_xilinx_bitstream and the MODMINER_PROGRAM command in 32-byte chunks with one-byte status acknowledgements. Work commands are 46 bytes (MODMINER_SEND_WORK, FPGA id, midstate, tail data). Results are polled with MODMINER_CHECK_WORK, validated against current and previous work to tolerate pipeline delay, and submitted or counted as hardware errors. Dynamic clocking (dynclock) changes MODMINER_SET_CLOCK based on valid/bad nonce rates and temperature; API/status output reports frequency, cooling maximum, maximum frequency, hardware errors, valid nonces, and upload percent.
avalonhost-raminst is not a mining driver but an Avalon-host deployment helper. It must run as root on an OpenWrt TL-WR703N Avalon controller, pivots overlayfs into RAM, temporarily rewrites opkg.conf to add a BFGMiner package feed for a requested version, installs requested packages, removes the old cgminer monitor crontab, then pivots back to the persistent overlay. It is intended for one use per boot and should only be reversed by rebooting.
README.ASIC is the operator-facing map for this area. Its Avalon 1, Avalon 2/3, Antminer S1-S5, Antminer U3, Compac, and Big Picture Mining sections document which driver names to scan (avalon, avalonmm, bitmain, antminer, compac, bigpic) and how runtime options correspond to the driver configuration fields above.
Coverage
- driver-avalon.c
- driver-avalon.h
- driver-avalonmm.c
- driver-antminer.c
- driver-bitmain.c
- driver-bitmain.h
- driver-bigpic.c
- driver-bigpic.h
- driver-modminer.c
avalonhost-raminstREADME.ASIC
Coupling
- If
struct avalon_taskorstruct avalon_resultchanges in driver-avalon.h, verifyavalon_send_task,avalon_get_result,avalon_decode_nonce, temperature/fan recording, andAVALON_WRITE_SIZE/AVALON_READ_SIZEusers in driver-avalon.c; the serial protocol transmits the packed struct bytes directly. - If Avalon MM packet size, CRC, or command/reply values change in driver-avalonmm.c, verify both
avalonmm_write_cmdandavalonmm_read; all higher-level job upload, detect, poll, and nonce flows rely on the shared 32-byte packet framing. - If Bitmain token layouts or constants change in driver-bitmain.h, update the token builders/parsers in driver-bitmain.c at the same time.
TXCONFIG,RXSTATUS,TXTASK, andRXNONCElengths and CRCs are built from these packed layouts, and parse errors will silently prevent initialization or nonce accounting. - If Bitmain model defaults change in driver-bitmain.c, also update
README.ASICexamples for S1-S5. Detection requires model/layout/timing/register/voltage configuration, and mismatched documented values can cause the driver to refuse startup or run unstable settings. - If Antminer clock or voltage handling in driver-antminer.c changes, check README.ASIC's Antminer U3 and Compac sections. U3 voltage remains raw hex-only, while BM1382/BM1384 clock input may be decimal MHz only when the chip is identified.
- If ModMiner bitstream identity constants or filename change in driver-modminer.c, verify the packaged bitstream asset expected by
open_xilinx_bitstream; a USER-code mismatch triggers in-field FPGA reprogramming before mining can start.
Risks
- driver-avalon.c treats a failed reset signature as non-fatal (
/* FIXME: return 1; */is left disabled inavalon_reset). A non-Avalon or wedged serial device may still be registered and later fail as communication or controller errors. - driver-bitmain.c requires explicit configuration and aborts detection when
packet_max_workor register data are missing. If README.ASIC or deployment scripts omit--set bitmain:model=...or compatiblereg_data, the driver reports “Device not configured” and never reaches hardware initialization. - driver-bitmain.c prunes old work from
thr->work_listbased on observed FIFO capacity. If status parsing fails to keepfifo_space/max_fifo_spaceaccurate, nonce packets can reference pruned work IDs and be counted as hardware errors/no-matching-work. - driver-bigpic.c and README.ASIC both indicate Big Picture Mining devices are sensitive to unexpected serial data. If other serial probes run before
bigpicprobing, the device can be left confused and require a physical replug before detection succeeds. avalonhost-raminstpivots overlay filesystems and rewrites package sources on a live Avalon host. If a non-opkg/crontabcommand fails, the script warns to reboot ASAP; retrying in the same boot can leave the root overlay in an unexpected state.