6

I have been trying to get my Raspberry Pi Zero to behave as a USB Mass Storage Device, following https://gist.github.com/gbaman/50b6cca61dd1c3f88f41 and other online documentation.

Steps to reproduce:

  1. Download Raspbian Jessie Lite or Raspbian Jessie Pixel and write to SD card using Win32DiskImager.
  2. Connect SD card, HDMI monitor and powered hub for keyboard, mouse and WiFi to Raspberry Pi Zero.
  3. Connect power, wait for reboot and login (user: pi, password: raspberry).
  4. Enable dwc2 overlay and reboot:

    echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
    sudo reboot now
    
  5. Create 400MiB disk image, format as FAT and load g_mass_storage driver:

    sudo dd if=/dev/zero of=/usb-drive.img bs=1M count=400
    sudo mkdosfs -F 32 /usb-drive.img
    sudo modprobe g_mass_storage file=/usb-drive.img stall=0
    
  6. Disconnect USB hub.

I've tried then either connecting from the laptop (Windows 10 x64) to the Pi Zero (with a working USB OTG cable, of course) or powering from another USB port, waiting for a couple of minutes (or not waiting at all) and then connecting the USB OTG cable.

Further investigation

I do not have anything showing up in Disk Manager in Windows. I checked Device Manager and it is listed there as Unknown USB Device (Device Descriptor Failed).

Device status

Windows has stopped this device because it has reported problems. (Code 43)

A request for the USB device descriptor failed.

Events

  • Device not migrated

    Device USB\VID_0000&PID_0002\5&21b40883&0&6 could not be migrated.
    
    Last Device Instance Id: USB\VID_0781&PID_557D\4C530008200730105360
    Class Guid: {36FC9E60-C465-11CF-8056-444553540000}
    Location Path: 
    Migration Rank: 0xF000FFFFFFFFF032
    Present: false
    Status: 0xC0000719
    
  • Device configured (usb.inf)

    Device USB\VID_0000&PID_0002\5&21b40883&0&6 was configured.
    
    Driver Name: usb.inf
    Class Guid: {36FC9E60-C465-11CF-8056-444553540000}
    Driver Date: 06/21/2006
    Driver Version: 10.0.14393.0
    Driver Provider: Microsoft
    Driver Section: BADDEVICE.Dev.NT
    Driver Rank: 0xFF0000
    Matching Device Id: USB\DEVICE_DESCRIPTOR_FAILURE
    Outranked Drivers: usb.inf:USB\DEVICE_DESCRIPTOR_FAILURE:00FF2000
    Device Updated: false
    Parent Device: USB\ROOT_HUB30\4&1070b0ca&0&0
    
  • Device not started

    Device USB\VID_0000&PID_0002\5&21b40883&0&6 had a problem starting.
    
    Driver Name: usb.inf
    Class Guid: {36FC9E60-C465-11CF-8056-444553540000}
    Service: 
    Lower Filters: 
    Upper Filters: 
    Problem: 0x2B
    Problem Status: 0x0
    

dmesg log

Checking the device log with dmesg | grep "dwc2", there are many entries like this:

[   79.760006] dwc2 20890000.usb: NYET/NAK/ACK/other in non-error case, 0x00000002

Another attempt

sudo dd if=/dev/zero of=/usb-drive.img bs=1M count=400
sudo mkdosfs -F 32 /usb-drive.img
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
echo "dwc2" | sudo tee -a /etc/modules
echo "g_mass_storage" | sudo tee -a /etc/modules
sudo touch /etc/modprobe.d/usb-drive.conf
echo "options g_mass_storage file=/usb-drive.img stall=0" | sudo tee -a /etc/modprobe.d/usb-drive.conf

Conclusion

I followed all the guides available online and further checked with the Linux docs and could not get it working.

Many people report in forums that the g_multi driver works but requires a specific driver (RNDIS, to be exact) on the host to function. The problem is that I wish to boot GParted from the Pi Zero and cannot install RNDIS drivers on the laptop's BIOS/EFI firmware.

How do I configure the Raspberry Pi Zero to show itself as a Mass Storage Device? Is there something I have missed?

  • 1
    Could you please clarify what is the purpose of this line sleep 10 && sudo shutdown now in step #5? Obviously, the mass storage target won't work if the Pi is shut down. – sfk Mar 27 '17 at 12:36
  • @sfk I haven't used Linux much before. I understood you need to unplug the hub and reboot before it would work. I come from a Windows background; perhaps that is why… but I have tried it without shutting down before and I don't remember it working. I'll try again later. I also tried adding the kernel modules in /etc/modules/ and the parameters in /etc/modprobe.d/usb-drive.conf, as outlined in “Another attempt”. – Toothbrush Mar 27 '17 at 14:31
  • @sfk I tried with a fresh image without rebooting and it did not work. Windows still states that "USB device not recognised": "The last USB device you connected to this computer malfunctioned and Windows does not recognise it." – Toothbrush Mar 30 '17 at 21:41
  • @sfk I also updated my question with information about a message I notice a lot in dmesg | grep "dwc2": "dwc2 20890000.usb: NYET/NAK/ACK/other in non-error case, 0x00000002". – Toothbrush Mar 30 '17 at 21:51
2

All of your sequences work fine for me on macOS. However, on Windows 10 it would show up with the correct amount of space but "Unallocated". For whatever reason, this fixes itself and a drive letter is assigned when I add removable=1. Try that.

Device USB\VID_0000&PID_0002\5&21b40883&0&6 had a problem starting.

Because that does not say VID=0525 PID=a4a5, it is probably some other device on your Windows 10 system and unrelated.

I've tried then either connecting from the laptop (Windows 10 x64) to the Pi Zero (with a working USB OTG cable, of course) or powering from another USB port, waiting for a couple of minutes (or not waiting at all) and then connecting the USB OTG cable.

To speed up your troubleshooting cycle in the future I have some recommendations. First, to rule out any image creation issues start off by mounting the boot partition directly e.g.

sudo modprobe g_mass_storage file=/dev/mmcblk0p1 removable=1

Second, if you have a 3-pin UART cable or ssh access over WiFi you can make changes in rapid succession without rebooting your Pi Zero, e.g.:

sudo modprobe -r g_mass_storage
sudo modprobe g_mass_storage file=/usb-drive.img stall=0 removable=1
sudo modprobe -r g_mass_storage
sudo modprobe g_multi file=/usb-drive.img stall=0 removable=1

Lastly, on Windows keep an eye out for enumerated disks that may be unreadable. In addition to watching Device Manager, open up Computer Management and select the Disk Management pane.

Many people report in forums that the g_multi driver works but requires a specific driver (RNDIS, to be exact) on the host to function. The problem is that I wish to boot GParted from the Pi Zero and cannot install RNDIS drivers on the laptop's BIOS/EFI firmware.

This actually doesn't matter. With g_multi you can use mass storage and gadget serial even if the RNDIS driver isn't installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.