Donate VRC/VRM for the Wiki to VBzaNDExHyFpnNvYc5QH5e4ipBZqxxPnKJ . Thank you, Joe.

H96 Pro Dongle Mining

From VeriCoin & Verium Wiki
Jump to: navigation, search

This page is about mining on the Amlogic S912 H96 Pro Dongle (see also TV_Box_Mining)

Donations

If you found this guide helpful, feel free to donate some VRC/VRM to @g4b at the following addresses:

  • VRM: VY3XwEUiYsTsreMVv3xMGGp55wT9E4jAhR
  • VRC: VFWWmFcV2n4UZf9TfVUBs1i1hSMdeWqwgr


Hardware revisions

There are two known hardware revisions with different characteristics.

v1 ("S47_V3" printed on PCB)

IMG 20180323 165130.jpg H96-pro-dongle-v1-bottom.jpeg IMG 20180323 180206.jpg

  • manufactured circa 2017-06
  • 2x 1GByte DDR3 chips (top-side)
  • pads for UART console on PCB (top-side, below heatsink)
  • realtek 8723bs wifi chip (bottom-side)
  • "thick" stock heatsink

v2 ('H96PRO_MINI PC_S912" printed on PCB)

IMG 20180323 170344.jpg IMG 20180323 170326.jpg

  • manufactured circa 2017-10 (or later)
  • 4x 512Mbyte DDR3 chips (2 top-side, 2 bottom-side)
  • no pads for UART console
  • Broadcom DHD wifi chip (top-side, HS2734A)
  • "thin" stock heatsink (actually just a small aluminium plate stuck on the CPU and part of the top-side DDR chips. NOTE: heatsink on the photo is NOT stock!)


NOTE broadcom wifi drivers (bcmdhd and brcmfmac) are currently unreliable with 4.9 kernel on those boards. => choose v1 if you can.

Build

It is strongly recommended to do this on a recent debian x86_64 host (debian buster was used to write this procedure), especially for the aarch64 toolchain.

If you're too stubborn or don't know how to use a VM, go there and try your luck: https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/


Kernel

 # install deps (debian buster)
 $ apt-get install build-essential git gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu lzop u-boot-tools bc
 # fetch kernel source
 $ git clone https://github.com/g4bwy/Amlogic_s905-kernel kernel-4.9
 # checkout h96_compute_stick branch
 $ cd kernel-4.9
 $ git checkout h96_compute_stick-4.9
 # use kernel config specfic to H96 dongles
 $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- h96_compute_stick_defconfig
 # build it
 $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4
 # create uboot image
 $ mkimage -A arm64 -O linux -T kernel -C none -a 0x1080000 -e 0x1080000 -n linux-next -d arch/arm64/boot/Image uImage

Then copy uImage + arch/arm64/boot/dts/amlogic/h96_compute_stick.dtb to SD/USB boot device (rename them to zImage and dtb.img, respectively)

WARNING: wifi doesn't work, so use an usb to ethernet adapter (DM9601 and SMSC75XX adapters are built in h96_dongle-4.9.config)

rtl8723BS driver

To build the wifi driver for v1 boards and 4.9 kernel:

 # clone repo
 $ git clone https://github.com/g4bwy/rtl8723BS
 # build it
 $ KSRC=/path/to/kernel-4.9 make


module is 8723bs.ko, move it to device rootfs in /lib/modules/4.9.76/extra/ and autoload through /etc/modules

U-Boot setup

Boot 4.9 from SD/USB

First bootstrap installation by following instructions here: [1], but do NOT install armbian on eMMC.

Then rename the uImage file name to zImage (on your SD/USB device):

Then modify s905_autoscript.cmd (still on your SD/USB device):

  setenv kernel_loadaddr "0x01080000"
  setenv init_hdmi ""
  setenv boot_start "bootm ${kernel_loadaddr} - ${dtb_mem_addr}"

Finally, re-generate the s905_autoscript file (as described here), still on your SD/USB device:

  mkimage -A arm -O linux -T script -C none -d s905_autoscript.txt s905_autoscript

Boot 4.9 from internal eMMC

Boot from SD/USB first, then perform following steps.

Create filesystems:

   # mkfs.vfat /dev/crypt
   # mkfs.ext4 /dev/data

/boot contents:

  • uImage-4.9
  • dtb-4.9.76/h96_compute_stick.dtb

Mount /dev/crypt, copy contents of /boot to it. Mount /dev/data, copy rootfs contents to it.

NOTE: if you boot to the default android image (through 'run storeboot' in U-Boot), android will chown 1023:1023 everything in it (and thus will break suid binaries like sudo)


Modify U-Boot environment (keeping SD/USB boot possible through s905_autoboot script):

   # fw_setenv boot_emmc 'setenv bootargs "console=ttyS0,115200 root=/dev/mmcblk0p13 rw rootflags=data=writeback net.ifnames=0" ; mmc dev 1 ; if fatload mmc 1:8 0x01080000 uImage-4.9 ; then if fatload mmc 1:8 $dtb_mem_addr dtb-4.9.76/h96_compute_stick.dtb ; then osd close ; hdmi off ; bootm 0x1080000 - $dtb_mem_addr; fi; fi;'
   # fw_setenv bootcmd_orig 'run start_autoscript; run storeboot;'
   # fw_setenv bootcmd 'run start_autoscript; run boot_emmc; run storeboot;'

Root Filesystem

Various methods usable, as described here


Quick bootstrap from armbian. First boot your armbian SD or USB stick, then follow these steps:

   mkfs.ext4 /dev/data
   apt-get install debootstrap
   mount /dev/data /mnt
   debootstrap buster /mnt
   chroot /mnt
   apt-get install <whatever packages you want>
   exit

then reboot following the method in previous section (with root=/dev/mmcblk0pX, with X the partition number of /dev/data, which is 13 on the dongles)

cpuminer

With proper RAM configuration, cpuminer can be run with following options:

  • 3x 3way threads (579 huge pages)
  • 6x 1way threads (390 huge pages)
  • 969 total huge pages

Commandline:

   sysctl -w vm.nr_hugepages=969
   cpuminer -t 3 -1 6 --cpu-affinity 0x7 --cpu-affinity-oneway 0xf8


It is also possible to preallocate the hugepages early during boot, ensuring they will be available regardless of userland memory usage (and possibly ensuring the pages are contiguous, providing slightly better performance).

To do so, add the following to kernel's commandline:

   hugepagesz=2M hugepages=969


Then the following line should be visible in dmesg after reboot:

   HugeTLB registered 2 MB page size, pre-allocated 969 pages


If using the kernel commandline, setting up vm.nr_hugepages through sysctl must NOT be used.


Performance

Depending on model, hashrate per unit varies between 550 and 570 H/m.

The V2 appears a bit slower (around 10-20 H/m) than the V1, probably due to the DDR chips having a lower frequency (either due to hardware itself, or to timings set in the manufacturer's bootloader).

Networking

There are 3 ways to setup networking on the sticks.

USB-to-ethernet adapter dongle

Pros:

  • The simplest to setup, you just need to have the proper driver built-in (lots of options below CONFIG_USBNET in menuconfig, eg. ASIX, DAVICOM), plug it and you'll have an ethernet interface
  • Cheap dongles can be bought from amazon, like this one

Cons:

  • consumes more power per board (0.5 to 1W, depending on adapter)
  • takes up more space
  • adds some extra upfront cost


Wifi

Pros:

  • already integrated in the dongles, so no extra up-front cost (except maybe a dedicated access point placed close to the rig for reliability)
  • less power-consumption than the USB-ethernet dongles

Cons:

  • trickier to setup: requires knowing which dongle version you have (to select between 8723bs or bcmdhd/brcmfmac drivers), + wpa_supplicant running on the board, consuming more RAM and CPU
  • connection may be unreliable, unless you setup an AP very close to your rig to ensure good signal quality. also, use of a watchdog daemon or crontab to restart the boards when connection is dropped is recommended


CDC_EEM through the USB-OTG port

Pros:

  • more reliable than wifi, works as good as USB-ethernet dongles
  • male-to-male USB-A cables are cheaper than USB-ethernet dongles (less than one euro, albeit quality is important so it's better to invest a little more)
  • consumes less power than USB-ethernet and wifi

Cons:

  • more tricky to setup (requires proper dtb + script for configfs black-magic)
  • requires a controller board to bridge between the USB network and the outside world (however this can easily be made with an rpi or another cheap SBC)
  • requires USB hubs with enough ports to connect to the controller. powered hubs with per-port power control are a plus.


More about this later when I complete the setup.

Lego rig

BOM:

  • 30x H96 pro dongles
  • 3x Anker 10 ports 60W USB charger (30 euro on amazon)
  • 1x wireless AP (here an old netgear WG602v4 with dd-wrt)
  • 1x 25cm 12V/0.38A fan
  • lego pieces by the pint from lego store


Lego-rig1.png Rig-parts.png


Current state:

  • half-provisionned (15 dongles + 1 khadas vim2 basic)
  • ~9000 H/m
  • power consumption: TBM (10x dongles on 1 anker draw ~52W)
  • total upfront cost: ~475 euro

S912-lego-rig.jpg S912-lego-rig2.jpg