USB Mass Storage Gadget (or MSG)

From Wiki-DB
Jump to navigationJump to search

The Mass Storage Gadget (MSG) provides support for the USB Mass Storage class. The System appears to the host (PC) as a SCSI disk drive if the USB-OTG port is used for the connection. 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 Mass Storage Gadget Driver and how to use it have a look at www.linux-usb.org/gadget/file_storage.html and www.kernel.org. It is possible to run the driver as loadable kernel module. The steps below descripe how to compile the g_mass_storage module statically into the kernel image.

Configure the USB-OTG Port

On i.MX25 and AM35x 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

Remark: The DHCOM i.MX6 and AM335x have dual role usb controllers und drivers. It is not necessary to specify the otg_mode if you use this platforms.

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, AM335x: Inventra HDRC USB Peripheral (TI, ADI, ...)
* DHCOM iMX25, iMX6: Freescale Highspeed USB DR Peripheral Controller
  • Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> Mass Storage Gadget

Rebuild the Linux kernel and install the kernel to your board. (See DHCOM Update for details.)

How to Use?

Static Kernel Module

If the g_mass_storage module has been statically built into the kernel image you have to provide the following parameters to the kernel module via kernel command line (bootargs in u-boot):

  • g_mass_storage.removable=1
  • g_mass_storage.luns=1

Apply Backing 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:

  • am35x# echo /dev/mmcblk0p1 > /sys/devices/platform/omap/musb-am35x/musb-hdrc/gadget/lun0/file

If you do not work the AM35x there are some differences in the path of the sysfs. (Easy to find when you go to cd /sys and type find . -name "lun*" )

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. This will cause damage to the filesystem. Only one "Writer" on each Filesystem is allowed!

IMPORTANT WARNING!

  • While MSG is running and the gadget is connected to a USB host, that USB host will use the backing storage as a private disk drive. It will not expect to see any changes in the backing storage other than the ones it makes. Extraneous changes are liable to corrupt the filesystem and may even crash the host. Only one system (normally, the USB host) may write to the backing storage, and if one system is writing that data, no other should be reading it. The only safe way to share the backing storage between the host and the gadget's operating system at the same time is to make it read-only on both sides.

  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“.