From e7d23af7beb2e8ff73e67f38308c6cd56e9cd323 Mon Sep 17 00:00:00 2001 From: progranism Date: Tue, 2 Aug 2011 04:24:02 -0700 Subject: [PATCH] Altera mining script updated. Now automatically detects connected mining FPGAs. No need to manually edit the mining script with your FPGA's hardware and device name now. --- scripts/mine/jtag_comm.tcl | 90 ++++++++++++++++++++++++++++++++++---- scripts/mine/mine.tcl | 22 +++++----- 2 files changed, 93 insertions(+), 19 deletions(-) diff --git a/scripts/mine/jtag_comm.tcl b/scripts/mine/jtag_comm.tcl index 4e0ea83..d539b3c 100644 --- a/scripts/mine/jtag_comm.tcl +++ b/scripts/mine/jtag_comm.tcl @@ -7,17 +7,30 @@ # TODO: These are designed to assume a single FPGA. Re-design to handle multiple FPGAs, assigning # an arbitrary ID to each FPGA. + # Initialize the FPGA proc fpga_init {} { global fpga_last_nonce - # TODO: Automatically find an FPGA with mining firmware loaded on it. - # We can use the code from the programming script to accomplish that. - find_instances - start_insystem_source_probe -hardware_name "USB-Blaster \[USB-0\]" -device_name "@1: EP3C120/EP4CE115 (0x020F70DD)" + global fpga_name + + set fpga [find_miner_fpga] + + if {$fpga == -1} { + return -1 + } + + set hardware_name [lindex $fpga 0] + set device_name [lindex $fpga 1] + + start_insystem_source_probe -hardware_name $hardware_name -device_name $device_name set fpga_last_nonce [read_instance GNON] + set fpga_name "$hardware_name $device_name" + + return 0 } + # Push new work to the FPGA proc push_work_to_fpga {workl} { global fpga_last_nonce @@ -70,18 +83,36 @@ proc get_current_fpga_nonce {} { # Return the FPGA's "name", which could be anything but is hopefully helpful (to the user) in # indentifying which FPGA the software is talking to. proc get_fpga_name {} { - return "Unknown" + global fpga_name + return $fpga_name } + +### +# Internal FPGA/JTAG APIs are below +# These should not be accessed outside of this script +################################### + set fpga_instances [dict create] set fpga_last_nonce 0 +set fpga_name "Unknown" -proc find_instances {} { +# Search the specified FPGA device for all Sources and Probes +proc find_instances {hardware_name device_name} { global fpga_instances - foreach instance [get_insystem_source_probe_instance_info -hardware_name "USB-Blaster \[USB-0\]" -device_name "@1: EP3C120/EP4CE115 (0x020F70DD)"] { - dict set fpga_instances [lindex $instance 3] [lindex $instance 0] + set fpga_instances [dict create] + + if {[catch { + + foreach instance [get_insystem_source_probe_instance_info -hardware_name $hardware_name -device_name $device_name] { + dict set fpga_instances [lindex $instance 3] [lindex $instance 0] + } + + } exc]} { + #puts stderr "DEV-REMOVE: Error in find_instances: $exc" + set fpga_instances [dict create] } } @@ -101,4 +132,47 @@ proc instance_exists {name} { } +# Try to find an FPGA on the JTAG chain that has mining firmware loaded into it. +# TODO: Return multiple FPGAs if more than one are found (that have mining firmware). +proc find_miner_fpga {} { + set hardware_names [get_hardware_names] + + if {[llength $hardware_names] == 0} { + puts stderr "ERROR: There are no Altera devices currently connected." + puts stderr "Please connect an Altera FPGA and re-run this script.\n" + return -1 + } + + foreach hardware_name $hardware_names { + if {[catch { set device_names [get_device_names -hardware_name $hardware_name] } exc]} { + #puts stderr "DEV-REMOVE: Error on get_device_names: $exc" + continue + } + + foreach device_name $device_names { + if { [check_if_fpga_is_miner $hardware_name $device_name] } { + return [list $hardware_name $device_name] + } + } + } + + puts stderr "ERROR: There are no Altera FPGAs with mining firmware loaded on them." + puts stderr "Please program your FPGA with mining firmware and re-run this script.\n" + + return -1 +} + + +# Check if the specified FPGA is loaded with miner firmware +proc check_if_fpga_is_miner {hardware_name device_name} { + find_instances $hardware_name $device_name + + if {[instance_exists STAT] && [instance_exists DAT2] && [instance_exists GNON]} { + return 1 + } + + return 0 +} + + diff --git a/scripts/mine/mine.tcl b/scripts/mine/mine.tcl index c30fa38..ced441c 100644 --- a/scripts/mine/mine.tcl +++ b/scripts/mine/mine.tcl @@ -20,16 +20,11 @@ ## -## TODO: Probe for Hardware and Device names and allow user to select. -## TODO: Allow user to enter username/password pairs and pool server info. -## TDOO: Save user configurations to a file and load on start. -## TODO: Log JSON-RPC information to a file instead of spitting it into the console, or make it a --verbose option. ## TODO: Long polling. -## TODO: Use the NONC virtual wire to measure hashrate. +## TODO: --verbose option for debugging issues. +## TODO: Handle multiple FPGAs at once. -#package ifneeded TclCurl 7.19.6 [list load TclCurl7196.dll]\n[list source tclcurl.tcl] -#package require TclCurl package require http package require json package require base64 @@ -147,14 +142,16 @@ proc submit_nonce {workl golden_nonce} { puts " --- FPGA Mining Tcl Script --- \n\n" -puts "Looking for and preparing FPGAs..." -if [catch {fpga_init} exc] { - puts stderr "ERROR: Unable to find any suitable FPGAs. Please make sure your FPGA is connected to the computer, on, and has been loaded with mining firmware." - puts stderr "\nError Message was:\n$exc" +puts "Looking for and preparing FPGAs...\n" +if {[fpga_init] == -1} { + puts stderr "No mining FPGAs found." puts "\n\n --- Shutting Down --- \n\n" exit } +set fpga_name [get_fpga_name] +puts "Mining FPGA Found: $fpga_name\n\n" + if {[get_current_fpga_nonce] == -1} { puts "WARNING: The FPGA's mining firmware does not report a hashrate. Status messages will show 0.00 MH/s, but the FPGA should still be running. Check the estimated rate for approximate hashing rate after shares have been submitted.\n\n" } @@ -200,4 +197,7 @@ while {1} { } +puts "\n\n --- Shutting Down --- \n\n" + +