Monday, October 29, 2018

External hard drive file share on Nvidia Shield with FUSE/SSHFS

I recently picked up a 2nd gen Nvidia Shield (not-pro).  It's slightly smaller than the first gen and has a few less ports...
Image result for nvidia shield 2017
Unlike the pro version it only has 16 GB of internal storage.  No problem, I'll just plug in an external USB hard drive and use the native CIFS service.  Only now there is a problem:  For whatever reason only the internal storage can be accessed via CIFS not the external storage.

I am not wedded to CIFS so I started looking around for alternatives.  
  • First I went down a rabbit hole looking at FTP Android services.  These are easy to get going.  But to get access to the external storage I was going to need to root the device.  Sure I could do that, but I don't want too.  
  • Then I came across a few Internet posts pointing towards SSHelper.  Basically it is a user space SSH service.  That should come in handy even if it couldn't access the external storage (spoiler: it can)
SSHelper is not on the Android TV store.  We need to "sideload" for it to be installed.  Which sounds dodgy but it isn't. probably.  In any case it is tricky and there's a few different methods.  I chose to use the network ADB method.  To make this easier someone has published a GUI frontend, NSTV v0.14.

There was a few gotchas so I'll just summarise the sequence :
    • Unplug the USB hard drive, and
    • Disable all the settings in Android Settings > Storage.
  • Then I tried to use NSTV to sideload the SSHelper package:
    • A command prompt would appear and instantly error with some kind of file not found issue.  This turned out to be a red herring
    • It couldn't initially connect.  I ended up working around this by starting a cmd.exe and running the adb connect command manually i.e. adb connect 192.168.1.2 (the Shield IP)
  • Now installed, but I couldn't see it anywhere in the interface.  But I found an Android TV store app that helps called Sideload Channel.  Using Sideload Channel I was able to launch SSHelper and configure the password
At this point I was able to SSH to the device, success!  Note that because it is in user space it doesn't listen on the standard SSH port (22).  So we need to specify the port in the ssh client (-p 2222).  

Now onto the external hard drive.  Using ADB I worked out that storage devices can be found in /storage.  With SSH we don't get permission to see the root folder (/), so you cannot find it by tabbing or the like.  Also my external hard drive came up with a strange identifier.  Yours will of course be different:

u0_a100@localhost:~$ ls -l /storage
total 32
drwxr-xr-x    1 root     everybod     28672 Oct 27 13:19 30D4A05DD4A026D6
drwx--x--x    4 root     everybod      4096 Jan  1  2013 emulated
drwxr-x--x    2 root     root            60 Oct 22 17:08 self

For security reasons write access has been disabled to the external drive except for one special folder that was already created, NVIDIA_SHIELD.  I suspect this got created when I was fiddling with the settings in Android Settings > Storage.

u0_a100@localhost:NVIDIA_SHIELD$ cd /storage/30D4A05DD4A026D6/
u0_a100@localhost:30D4A05DD4A026D6$ touch t
touch: t: Permission denied
u0_a100@localhost:30D4A05DD4A026D6$ cd /storage/30D4A05DD4A026D6/NVIDIA_SHIELD/
u0_a100@localhost:NVIDIA_SHIELD$ touch t
u0_a100@localhost:NVIDIA_SHIELD$

So we almost have lift off.  Now we just need to access it like a file share.  That's where FUSE/SSHFS comes in.  Under Ubuntu Linux you just need to do a few steps:

Step 1. Install FUSE/SSHFS

ubuntu# apt-get install sshfs fuse

Step 2.  Create an entry in fstab

The fstab entry options we need are not immediately obvious.  In the end my entry looks like this:

sshfs#root@192.168.1.2:/storage/30D4A05DD4A026D6/NVIDIA_SHIELD /mnt/shield fuse defaults,allow_other,port=2222,noatime,IdentityFile=/home/matthewh/.ssh/id_rsa 0 0

The not so obvious options are:
  • port=2222.  Yes this sounds obvious but I found little referencing it with Google.  
  • noatime.  Rsync would error out when trying to set atime and abort transfers.  This is likely due to having limited privileges in SSHelper.
  • IdentityFile=/blah/blah.  This is the private key used for authentication.  I won't go into detail on how to setup private key authentication.  Basically it works just like any other Linux host.
There you have it.  An external hard drive file share on Nvidia Shield using FUSE/SSHFS!


Sunday, March 21, 2010

Google SketchUp for Landscape Design


I've been toying around with SketchUp today and it has inspired me to turn my boring lifeless front yard into a functional outdoor area.





Saturday, December 12, 2009

Cheap Chinese GPS Freezing

I bought a cheap chinese GPS thinking I'd get some exposure to Windows CE 5. TomTom runs great but it freezes after a couple of minutes if not touched. Touch it, and it comes back to life. Not a safe thing to be doing while driving!

The timing seemed too predictable for it to be a hardware failure. So I investigated further and found forums talking about modifying the registry and eliminating idle power saving values. So I tried doing just that, using a copy of RegEdit.exe for WinCE. No luck. Then reading through more forums I learn the power settings control panel needs to be launched and the OK button pressed to make the settings take affect. And this needs to be done on every boot.

All the registry hacking can be scripted with MortScript (PNA version inside the zip). And MortScript can even run the control panel and push the OK button. Except the control panel title is in Chinese so how do I focus on this window? More forum searching I find it's possible to sleep for a second and then just focus on the active window. So tying this all together I just configure the Autorun.exe of MortScript to be my 'GPS Software', this runs Autorun.mscr (see below) in the same directory, which fixes power settings and launches the actual GPS software.

I wanted to get some WinCE exposure but I didn't realise I'd be hacking registries and learning a new scripting language on day one!

RegWriteString("HKLM", "\System\Explorer\Shell Folders", "My Documents", "\StorageCard")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\Timeouts", "BattUserIdle", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\ActivityTimers\UserActivity", "Timeout", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\Timeouts", "ACUserIdle", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\Timeouts", "BattSystemIdle", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\ActivityTimers\SystemActivity", "Timeout", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power\Timeouts", "ACSystemIdle", "0")
RegWriteDWord("HKLM", "\System\CurrentControlSet\Control\Power", "DisableGwesPowerOff", "0")
Run( "ctlpnl.exe", "cplmain.cpl,5,1" )
#WaitFor( "Power Properties", 5 )
#SendOK( "Power Properties" )
Sleep(1000)
WindowName = ActiveWindow()
WaitFor(WindowName, 3)
SendOK(WindowName)
RunWait ("\StorageCard\TomTom\TomTomNavigator.exe")

Thursday, September 17, 2009

Proprietary Airgo Wifi Driver with OpenWrt

I've got this pre-N Belkin access point (f5d8230-4) sitting around doing nothing. The stock firmware is below average in terms of capabilities. Fortunately the thing is Broadcom and runs Linux, which is fairly common. Belkin have even published the GPL stuff. Unfortunately the Airgo driver is a binary driver with no source. And it uses custom commands for wireless configuration instead of the standard Linux stuff.

So it turns out flashing the thing with OpenWrt is a piece of cake. But as expected the wifi doesn't work. Some fellow in the OpenWrt forums figured out that for the binary driver to load with Linux 2.4.30 all that is needed is a few missing semaphore methods patched back in. And sure with a bit of tomfoolery it is then possible to get the wifi up and running for a few seconds before the router crashes and reboots. After that it appears progress on the Airgo driver has been stagnant for nearly 3 years.

But then I wired in my 3.3v tty cable and got a stack trace of the rebooting router. With gdb I was able to identify there was an issue with a method call in linux/netfilter/nf_hook_slow. Seems the method was patched to incorporate ebtables from Linux 2.6. Eliminating the patch fixes the Airgo. Supposedly this wifi card is used in other routers and those routers are also Broadcom based. I was close to throwing this thing away but with OpenWrt I think I'll hold onto it.

update: It was more troublesome to get working with Kamikaze.

Thursday, June 18, 2009

iView RSS feed


iView RTMP streams are unmetred for some Australian ISPs. It would be nice to be able to save these RTMP streams automatically with software like Miro or iTunes. The program information is published as XML, which can be converted to an RSS feed easily enough. But to actually grab the RTMP stream requires special software.

My basic solution:
- Install Tomcat 5.5 and enable the cgi servlet, configure 'executable' to be 'bash'.
- Deploy Exist onto the Tomcat (and locked down the admin account).
- Copy an XQuery script into Exist that fetches the XML file and generates RSS.
- Wrap the rtmpdump binary with a cgi script that does the HTTP handling and grabs an iView authentication token.

End result: I can subscribe to iView RTMP streams in my video rss client of choice (ie Miro).



Kudos to some guys on Whirlpool for publishing scripts that do some CLI rtmpdumping of iView. The IP addresses they use work for me, but different ISPs probably need different IP addresses.

And the two scripts are iview.xql and iviewdump.cgi

Thursday, April 24, 2008

PS3 Black Screen Of Death Fix

I have this DVI-I to DVI-A/DVI-D splitter cable that lets me plugin in my PS3 (with HDMI to DVI-D) and 360 (and Powerbook via switchbox). But I get the PS3 HDMI black screen of death when I turn the 360 _and_ the PS3 on at the same time.

I have to follow a few fixes on the net to make things all good again. 1) hold down the PS3 power button until the second beep and 2) power off my projector (not just standby... complete power off!). I do this with the toslink/spdif cable unplugged. It's annoying. Or is it a M$ tactic to destroy my Playstation fun!?

Thursday, April 17, 2008

Bridging a USB GPS on OSX to a smartphone


My new walkman phone is rocking but it doesn't have GPS. And I have a powerbook in my car but OSX navigation software is lacking. USB GPS + Powerbook + Smartphone ==> Google Earth + TomTom! It's as simple as installing gpsdX, gps2geX then compiling gpspipe, setting up a Bluetooth serial port, and then redirecting the USB GPS output: gpspipe -r | grep -v ^GPSD > /dev/tty.SerialPort-1

Easy!