75XX USB Device Mass Storage: Difference between revisions

From embeddedTS Manuals
(Created page with "The SBC must be setup prior to connection to a host PC. These steps are outline below. 1.) Create a mount point and then mount the first partition of SD card where the storage e...")
 
(Replaced content with "{{:USB Gadget Mass Storage}}")
 
Line 1: Line 1:
The SBC must be setup prior to connection to a host PC. These steps are outline below.
{{:USB Gadget Mass Storage}}
 
1.) Create a mount point and then mount the first partition of SD card where the storage element exists.
<source lang=bash>
mkdir /mnt/vfat; mount /dev/nbd1 /mnt/vfat
</source>
 
Install the g_file_storage driver with storage element details
<source lang=bash>
modprobe g_file_storage file=/mnt/vfat/usb_storage_file
</source>
 
After following these steps for preparing the SBC storage element, plug the SBC into the host PC with a A to B USB Cable (ISB Cable). You will see the newly mounted volume and should be able to access it.
 
When you have completed using the device on the Linux or Windows System, you will need to eject volume using either umount on Linux, or "Safely Remove Hardware" on Windows and then unplug the USB cable.
 
After transferring data from a host PC to the SBC through the USB Mass Storage Device Linux gadget, you can access the data on the SBC by using the following steps.
 
1.) Remove the g_file_storage driver allowing local access to storage element
<source lang=bash>
rmmod g_file_storage
</source>
 
2.) Create a mount point and then mount the storage element (assuming "/dev/nbd1" is still mounted to "/mnt/vfat" from steps above)
 
<source lang=bash>
mkdir /mnt/usbdev
mount -t vfat -o loop=/dev/loop0,offset=4096 /mnt/vfat/usb_storage_file /mnt/usbdev/
</source>
 
The kernel should already have support for loop block devices. If not, you will need to insert the loop.ko module with modprobe or insmod.
 
You can now locally access /mnt/usbdev.
 
When finished with the device, or to allow access via the USB Device port, you must un-mount the device using:
 
<source lang=bash>
umount /mnt/usbdev
</source>

Latest revision as of 22:15, 10 February 2012

The USB Gadget file storage device will allow you to allow access to a block device (file or otherwise) over USB. To use this functionality, you must first have a block device to give to the driver. In this example I will use a 100MB file on the Debian filesystem.

dd if=/dev/zero of=/root/usbstorage.img bs=1MB count=100

Load the driver with the file as an argument

modprobe g_file_storage file=/root/usbstorage.img

If you now, or are have already connected the USB device cable to a host pc, you should now see the USB device. Like inserting any other usb drive you should now have a new device on your system. From a linux host pc:

[690892.624575] sd 23:0:0:0: Attached scsi generic sg3 type 0
[690892.626160] sd 23:0:0:0: [sdd] 195312 512-byte logical blocks: (99.9 MB/95.3 MiB)
[690892.628419] sd 23:0:0:0: [sdd] Write Protect is off
[690892.628424] sd 23:0:0:0: [sdd] Mode Sense: 0f 00 00 00
[690892.628911] sd 23:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[690892.644202]  sdd: unknown partition table
[690892.647287] sd 23:0:0:0: [sdd] Attached SCSI disk

Now on your workstation you can use this device as any other usb storage. As this file contains all zeros, you will need to format it and create a partition/filesystem to be able to store data on it. See the documentation for your workstation for more details. Keep in mind you cannot mount the same block device or file twice so this will not allow you to share your live filesystem over USB.