Let's start with a weird image first:
In the plastic box is an Olimex A20-Lime2, a 2.5" HDD with 2TB and Olimex' largest battery with 6600mAh. Mounted on the top cover (box standing on the side) is a Banana Pi M2+ (to be replaced with NanoPi M1 or OPi One/PC in the future)
Why Lime2? Since this board from our friends at Olimex is designed intelligently and provides DC-DC step-up converters on the board providing the ability to power also the connected SATA disk when running from battery (unlike most other A10/A20 boards that do only provide 5V on USB ports in battery mode but not to the disk!). And since A20 is perfectly supported by mainline kernel (I run 4.6.4 on it with btrfs on both SD card and connected SATA disk. Since the Lime2 is used as monitoring/rsyslog host btrfs compression is active and the 2TB HDD might store up to 20TB of raw log/monitoring data)
Why BPi M2+? Since board was lying around and I have no other use for it (SinoVoip sent me a review sample a while ago). The idea to combine A20 with a H3 device was simply to add a camera capable and performant device that is ultra cheap (does not apply to BPi M2+ but to NanoPi M1 or OPi One for example). The H3 device will be used to off-load some stuff (eg. OpenVPN encryption), to capture images and do other hardware monitoring (eg. checking temperature in server racks using 1-Wire sensors)
Both boards in this mode run up to 8 hours on battery (6h when the 2 TB disk is also always spinning -- but I use a large 64GB Samsung EVO in the Lime2 and wake up the HDD only from time to time to move data over from SD card). And in this special mode the Lime2 is acting as UPS for the H3 board too since BPi M2+ is powered through Micro USB from Lime2's left USB type A receptacle. The same USB connection is also used as a 'private' network utilizing Ethernet gadget driver on the H3 device.
BPi M2+ is running our sun8i legacy kernel, g_ether module is active and configuration using a link local address as outlined in this thread. Therefore as soon as BPi M2+ boots and brings up his usb0 interface the board appears as Ethernet USB dongle on the Lime2 and can be used easily with the following settings as directly connected network device (providing ~120 Mbits/sec throughput over the USB cable):
This USB connection can now be used as a directly wired network connection (BPI M2+ is 169.254.2.1 and Lime2 169.254.2.2 and both can interact through this connection or use it as 'heartbeat' connection to monitor network outages). And using BPi M2+ or NanoPi M1 or NEO the very same USB connection can also be used to power the H3 device (not with Oranges there a hardware mod is needed).
Now the fun part: In case the USB powered H3 device freezes or is shut down and has to be restarted... how to do so? Some/most A10/A20 boards provide the 5V on their USB ports not directly from DC-IN but through their AXP209 PMU. And if the board is designed that way, power can be switched on/off on request. This is where the sunxi-pio tool gets interesting since with this tool you can query and switch pin state.
In the above example BPi M2+ is powered through Lime2's left USB port. VDD_USB of this port can be controlled through PH06 pin. So to cut power from Lime2 to BPi M2+ all I have to do is
sunxi-pio -m PH06'<default><default<default><0>'
And to provide power again, it's the opposite:
sunxi-pio -m PH06'<default><default<default><1>'
(at least on my Lime2 the left USB port is more reliable than the right port that can be controlled through PH03 pin). To be able to use the sunxi-pio tool you need a recent sunxi-tools version. As Armbian user you don't have to care since we ship always the most recent version.
Not all A10/A20 boards support this and pin mappings differ between different boards. So where to look? In the fex files (don't trust them blindly, some vendors horribly suck providing documentation for their own hardware, compare the pin mappings in bananapiprolcd7.fex and bananapipro.fex for example).
EDIT: Checked with both Banana Pi and Banana Pro: The USB voltage pin mappings in the fex files are plain BS and do not work (obviously 'copy&paste gone wrong' when they copied all of CubieTech's work in the beginning)
I let a script check the fex files of all Allwinner boards we currently support. Two H3 devices show the ability to switch USB voltage (OPi 2 and Plus/Plus2 -- the pin here most probably controls power for the internal Terminus USB hub) but all the others are A10/A20 based:
So if you want to switch power on the USB ports of a Banana Pro you would not use PH03/PH06 but PH00/PH01 instead (and yes, sunxi-pio works with exactly these settings/syntax even when the board runs vanilla/mainline kernel). Since we're talking about A20 Bananas now: These devices do not provide power to a connected SATA disk when running on battery unlike Olimex' boards. So in case you want to ensure that a connected SATA disk keeps spinning when DC-IN is not available then you have to DIY a cable solution taking power from the 2 USB ports and feeding SATA power this way (the SATA power connector on Banana boards is directly wired to the Micro USB DC-IN jack so you can both provide DC-IN here more reliably and have to keep in mind that battery/AXP209 is not involved at all)
BTW: sunxi-pio can be used for more than just switching power on USB ports. Simply call it without arguments to get the idea / help text. Anyone trying to decrease consumption of his Allwinner board might love this tool since you're able to switch off on-board consumers from user space.