USB Mass Storage Gadget (or MSG): Difference between revisions
m 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. |
No edit summary |
||
Line 1: | Line 1: | ||
The | The Mass Storage Gadget (MSG) provides support for 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. | ||
__TOC__ | __TOC__ | ||
Line 5: | Line 5: | ||
== General Information == | == General Information == | ||
For further information about details of the USB Gadget | For further information about details of the USB Mass Storage Gadget Driver and how to use it have a look at [http://www.linux-usb.org/gadget/file_storage.html www.linux-usb.org/gadget/file_storage.html]. It is possible to run the driver as loadable kernel module. The steps below descripe how to compile the driver statically into the kernel. | ||
== Configure the USB-OTG Port == | == Configure the USB-OTG Port == | ||
Line 29: | Line 29: | ||
::: * DHCOM AM35x: OMAP USB Device Controller | ::: * DHCOM AM35x: OMAP USB Device Controller | ||
::: * DHCOM iMX25: Freescale Highspeed USB DR Peripheral Controller | ::: * DHCOM iMX25: Freescale Highspeed USB DR Peripheral Controller | ||
* Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> | * Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> Mass Storage Gadget | ||
<!-- | |||
Obsolete, does not apply to the MSG (file-backed gadget is obsolete) | |||
Apply the following changes to the file <code>linux-2.6.38/drivers/usb/gadget/file_storage.c</code> in the lines 332 and 333: | Apply the following changes to the file <code>linux-2.6.38/drivers/usb/gadget/file_storage.c</code> in the lines 332 and 333: | ||
Line 37: | Line 39: | ||
<font color="#00FF10">+ .removable = 1, // old value = 0, | <font color="#00FF10">+ .removable = 1, // old value = 0, | ||
+ .can_stall = 0, // old value = 1, </font></code> | + .can_stall = 0, // old value = 1, </font></code> | ||
--> | |||
Line 46: | Line 49: | ||
== Using USB Gadget | == Using USB Mass Storage Gadget == | ||
On the running device you can use the following line to add the FAT32 partition of the microSD-card to the usb gadget driver: | On the running device you can use the following line to add the FAT32 partition of the microSD-card to the usb gadget driver: | ||
* <code> | * <code>am35x# echo /dev/mmcblk0p1 > >/sys/devices/platform/omap/musb-am35x/musb-hdrc/gadget/lun0/file</code> | ||
If you do not work the | If you do not work the AM35x maybe there are some tiny differences in the path of the sysfs. | ||
Line 59: | Line 62: | ||
* If you run windows then you can only use block devices with filesystems supported by windows (FAT32). | * 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. | * Do not use the rootfilesystem partition of your microSD card. This will cause damage to the used microSD-Card partition. | ||
'''AN 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 [http://www.linux-usb.org/gadget/file_storage.html www.linux-usb.org/gadget/file_storage.html] to get a step by step guide how to work with „Backing Storage Files“. | Have a look at [http://www.linux-usb.org/gadget/file_storage.html www.linux-usb.org/gadget/file_storage.html] to get a step by step guide how to work with „Backing Storage Files“. |
Revision as of 10:50, 27 January 2014
The Mass Storage Gadget (MSG) provides support for 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 Mass Storage Gadget Driver and how to use it have a look at www.linux-usb.org/gadget/file_storage.html. It is possible to run the driver as loadable kernel module. The steps below descripe how to compile the driver statically into the kernel.
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"
:
- enter bootloader console with DEL/BS Key
setenv linux_add_param otg_mode=device
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
- choose the matching device controller:
- Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> Mass Storage Gadget
Start building the kernel:
ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make uImage
Install the kernel on your board.
Using USB Mass Storage Gadget
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 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.
AN 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“.