Mining Bitcoins with Openwrt

This is a guide on how to use an OpenWRT device to mine bitcoins using BFG Miner.

Hardware: You'll need a router with usb, and some kind of hardware miner. For this example I will be using a single ASIC Sapphire Block Erupter.

Prereqs:

- first you'll need usb support usb.essentials

Installing Kernel Drivers

First verify your mining hardware is detected with this command:

cat /sys/kernel/debug/usb/devices
T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=10c4 ProdID=ea60 Rev= 1.00
S:  Manufacturer=Silicon Labs
S:  **Product=CP2102 USB to UART Bridge Controller**
S:  SerialNumber=0001
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 **Driver=(none)**
E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

The Driver=(none) indicates that you do not have the proper kernel module installed for this device so we will need to install it. The section 'product=' will tell you which driver we will need. Alternatively a common list of drivers provided by BFG Miner is as follows.

BitForce: ftdi_sio Erupter: cp210x Icarus: pl2303 Lancelot: ftdi_sio Cairnsmore: ftdi_sio

Since my particular controller uses a CP2102 we will need to install the package:

kmod-usb-serial-cp210x

*note it will also install its prereq kmod-usb-serial

Now to verify it worked:

 cat /sys/kernel/debug/usb/devices 
T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12   MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=10c4 ProdID=ea60 Rev= 1.00
S:  Manufacturer=Silicon Labs
S:  Product=CP2102 USB to UART Bridge Controller
S:  SerialNumber=0001
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 **Driver=cp210x**
E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

If the driver now equals something other then (none) it is loaded successfully.

We also have to verify that usb device is available, issue the following and your usb device should appear here

ls -l /dev/ttyUSB* crw-rw-rw- 1 root root 188, 0 Sep 6 21:40 /dev/ttyUSB0

If not you may need to load the drivers manually using the insmod command. Consult the BFG Miner readme for more info on this.

https://github.com/luke-jr/bfgminer/blob/bfgminer/README

Installing BFG Miner

Next we will need to install BFG Miner, luckily for us it provides an openwrt repository for most hardware. Instructions for adding it are here:

https://github.com/luke-jr/bfgminer/blob/bfgminer/README.OpenWrt

*note that you don't have to do this from the command line, it can be done from luci at System→Sofware→Configuration

Next you'll probably want to set your router to run bfgminer at startup. The easiest way to do this is add a command to the local startup script, available at System→Startup (scroll down).

This is the command I use, note that while my device is not an icarus device, the icarus command line options work fine.

 bfgminer -o stratum+(stratum address) -u (username) -p (password) -S all --icarus-options 115200:1:1 --icarus-timing 3.0=100

You can also use an init script, which is explained here initscripts. I use the following script:

#!/bin/sh /etc/rc.common
# Start and stop bfg miner

START=94
STOP=15

start() {
        screen -dmS bfgminer bfgminer -o stratum+(stratum address) -u (user) -p (password) -S all --icarus-options 115200:1:1 --icarus-timing 3.0=100
}

stop() {
        screen -S bfgminer -X quit
}

*note that it uses the screen command, which you will also have to install However because it uses the screen command you can view the BFG Miner interface to see the output by using the command 'screen -rS bfgminer'. Then when you are finnished hit Ctrl+a d to suspend the screen again.

Mining Litecoins with OpenWRT

Also Bfgminer can be used to mining litecoins with openwrt, but only with the CPU in this moment. This is not a good alternative due to the low performance of the CPUs found in the routers (i.e. a bcm6368 calculates 0'11 kH/s with both cores enabled mining litecoins), but we must take in mind the low power comsumption of these devices.

This a possible Makefile for cpuminer, but still needs a lot of debug.

# # Copyright (C) 2013 # # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # include $(TOPDIR)/rules.mk PKG_NAME:=cpuminer PKG_VERSION:=2.3.2 PKG_REV:=93120a697ddd6a6e86102707f41cde3cb689a738 # this is upstream version 2.3.2 PKG_RELEASE:=3 PKG_INSTALL:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_REV).tar.gz PKG_SOURCE_URL:=git://github.com/pooler/cpuminer.git PKG_SOURCE_PROTO:=git PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_VERSION:=$(PKG_REV) PKG_FIXUP:=autoreconf include $(INCLUDE_DIR)/package.mk define Package/cpuminer MAINTAINER:="A brave guy" SECTION:=utils CATEGORY:=Utilities TITLE:=cpuminer (CPU Miner) URL:=https://github.com/pooler/cpuminer DEPENDS:=+libcurl +libpthread +libncurses +jansson endef define Package/cpuminer/description Cpuminer is a multi-threaded CPU miner for bitcoin and derivative coins. Do not use on multiple block chains at the same time! endef CONFIGURE_ARGS += TARGET_CFLAGS += -O3 TARGET_LDFLAGS += -Wl,-rpath-link=$(STAGING_DIR)/usr/lib define Build/Configure # Need to remake configure etc to pick up on cross-compiler libtool ( cd $(PKG_BUILD_DIR); ./autogen.sh; ) $(call Build/Configure/Default) endef define Package/cpuminer/install $(INSTALL_DIR) $(1)/usr/bin/ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/cpuminer $(1)/usr/bin/ endef $(eval $(call BuildPackage,cpuminer))

Discuss: https://forum.openwrt.org/viewtopic.php?id=46164staticv 2013/09/07 04:06

Back to top

doc/howto/bitcoinmining.txt · Last modified: 2014/03/22 01:51 by staticv