USB Mass Storage Gadget (or MSG): Difference between revisions
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
== General Information == | == General Information == | ||
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 | 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] and [https://www.kernel.org/doc/Documentation/usb/mass-storage.txt 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 == | == Configure the USB-OTG Port == | ||
Line 11: | Line 11: | ||
On i.MX25 and AM35x to use USB Gadget features the USB-OTG Port has to be initialized in USB slave mode. Add <code>"otg_mode=device"</code> to the kernel commandline on the bootloader console. | On i.MX25 and AM35x to use USB Gadget features the USB-OTG Port has to be initialized in USB slave mode. Add <code>"otg_mode=device"</code> to the kernel commandline on the bootloader console. | ||
On DHCOM boards it is possible to use the u-boot environment variable < | On DHCOM boards it is possible to use the u-boot environment variable <tt>"linux_add_param"</tt>: | ||
# enter bootloader console with DEL/BS Key | # enter bootloader console with DEL/BS Key | ||
# < | # <tt>setenv linux_add_param otg_mode=device</tt> | ||
# < | # <tt>saveenv</tt> | ||
'''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. | '''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. | ||
Line 23: | Line 23: | ||
Open a console window and go to the root directory of the kernel sources and start the kernel configuration dialog: | Open a console window and go to the root directory of the kernel sources and start the kernel configuration dialog: | ||
* < | * <tt> ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- make menuconfig </tt> | ||
Enable the following items: | Enable the following items: | ||
Line 29: | Line 29: | ||
* Device Drivers --> USB Support --> USB Gadget Support --> USB Peripheral Controller | * Device Drivers --> USB Support --> USB Gadget Support --> USB Peripheral Controller | ||
:: choose the matching device controller: | :: choose the matching device controller: | ||
::: * DHCOM AM35x: | ::: * DHCOM AM35x, AM335x: Inventra HDRC USB Peripheral (TI, ADI, ...) | ||
::: * DHCOM iMX25, iMX6: Freescale Highspeed USB DR Peripheral Controller | ::: * DHCOM iMX25, iMX6: Freescale Highspeed USB DR Peripheral Controller | ||
* Device Drivers --> USB Support --> USB Gadget Support --> USB Gadget Drivers --> Mass Storage Gadget | * 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): | |||
* <tt> g_mass_storage.removable=1 </tt> | |||
* <tt> g_mass_storage.luns=1 </tt> | |||
=== 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: | On the running device you can use the following line to add the FAT32 partition of the microSD-card to the usb gadget driver: | ||
* < | * <tt>am35x# echo /dev/mmcblk0p1 > /sys/devices/platform/omap/musb-am35x/musb-hdrc/gadget/lun0/file</tt> | ||
If you do not work the AM35x | If you do not work the AM35x there are some differences in the path of the sysfs. (Easy to find when you go to <tt> cd /sys </tt> and type <tt> find . -name "lun*" </tt>) | ||
Now, if you connect the USB-OTG port to your host pc the specified device appears as a drive. | Now, if you connect the USB-OTG port to your host pc the specified device appears as a drive. | ||
'''Remark:''' | '''Remark:''' | ||
* 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 | * 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. | * 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“. |
Latest revision as of 06:38, 9 June 2017
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":
- enter bootloader console with DEL/BS Key
- setenv linux_add_param otg_mode=device
- 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
- choose the matching device 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“.