How to use mass storage gadget

From RidgeRun Developer Connection
Revision as of 10:53, 20 January 2017 by Jcaballero (talk | contribs)
Jump to: navigation, search

Mass storage gadget

1. Enable the following modules of the kernel:

-> Kernel configuration                                                                                                                       
  -> Device Drivers                                                                                                                          
    -> USB support (USB_SUPPORT [=y])                                                                                                       
      -> USB Gadget Support (USB_GADGET [=y])                                                                                                                      
        -> Mass Storage Gadget ( USB_MASS_STORAGE [=m])

2. In order to expose a sd card partition as backing storage for the mass storage gadget, you need to leave some available space in the sd card, for this, you can limit the space taken by the file system here:

-> Installer Configuration
  -> Minimal size of rootfs (MB)

Then you can create a fat partition on the available space in the sd card, in order to be used as backing storage.

3. Build and install the kernel in the target board.

4. Now in the board command line, load the module and set the parameters, file should point to the fat partition created in step 2.

modprobe g_mass_storage file=/dev/mmcblk3p3 stall=0

An alternative way is to use the parameter removable and specify the file parameter later through sysfs:

modprobe g_mass_storage removable=y  stall=0

To specify the file parameter:

echo "/dev/mmcblk3p3" > sys/devices/soc0/soc.0/2100000.aips-bus/2184000.usb/ci_hdrc.0/gadget/lun0/file

To free the backing storage (No host should have the mass storage mounted):

echo "" > sys/devices/soc0/soc.0/2100000.aips-bus/2184000.usb/ci_hdrc.0/gadget/lun0/file

If the gadget was mounted on the host, you may get a message like:

sh: write error: Device or resource busy