USB Mass Storage Gadget (or MSG)

From Wiki-DB
Revision as of 10:25, 27 January 2014 by Lzenz (talk | contribs) (moved USB Gadget File-backed Storage to USB Mass Storage Gadget (or MSG): File-backed Storage Gadget is obsolete and replaced by the Mass-Storage Gadget.)
Jump to navigationJump to search

The USB Gadget File-backed Storage Driver implements the USB Mass Storage class. The System appears to the host as a SCSI disk drive. A file or a block device is used as a backing store for the drive.

General Information

For further information about details of the USB Gadget File-backed Storage Driver have a look at www.linux-usb.org/gadget/file_storage.html. It is possible to work with kernel-modules. The steps below descripe how to compile the driver statically into the kernel because it is easier to handle.

Configure the USB-OTG Port

To use USB Gadget features the USB-OTG Port has to be initialized in USB slave mode. Add "otg_mode=device" to the kernel commandline on the bootloader console.

On DHCOM boards it is possible to use the u-boot environment variable "linux_add_param":

  1. enter bootloader console with DEL/BS Key
  2. setenv linux_add_param otg_mode=device
  3. saveenv

Prepare the Kernel

Prepare the Linux Kernel Sources to be able to compile.

Open a console window and go to the root directory of the kernel sources and start the kernel configuration dialog:

  • ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make menuconfig

Enable the following items:

  • Device Drivers --> USB Support --> USB Gadget Support
  • Device Drivers --> USB Support --> USB Gadget Support --> USB Peripheral Controller
choose the matching device controller:
* DHCOM AM35x: OMAP USB Device Controller
* DHCOM iMX25: Freescale Highspeed USB DR Peripheral Controller
  • Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> File-backed Storage Gadget

Apply the following changes to the file linux-2.6.38/drivers/usb/gadget/file_storage.c in the lines 332 and 333:

- .removable        = 0,
- .can_stall        = 1, 
+ .removable        = 1, // old value = 0,
+ .can_stall        = 0, // old value = 1, 


Start building the kernel:

  • ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make uImage

Install the kernel on your board.


Using USB Gadget File-backed Storage

On the running device you can use the following line to add the FAT32 partition of the microSD-card to the usb gadget driver:

  • i.mx25# echo /dev/mmcblk0p1 > /sys/devices/platform/fsl-usb2-udc/gadget/gadget-lun0/file

If you do not work the i.mx25 maybe there are some tiny differences in the path of the sysfs.


Now, if you connect the USB-OTG port to your host pc the specified device appears as a drive.  

Remark:

  • If you run windows then you can only use block devices with filesystems supported by windows (FAT32).
  • Do not use the rootfilesystem partition of your microSD card. This will cause damage to the used microSD-Card partition.

  Have a look at www.linux-usb.org/gadget/file_storage.html to get a step by step guide how to work with „Backing Storage Files“.