I am using AM3715 and and 2.6.32 kernel, I have tested usb otg gadget (mass storage) by building as module & inserting the module as insmod g_file_storage.ko file=/dev/mmcblk0 stall=0.
I selected the usb gadget driver as built in kernel module:
--- USB Gadget Support [ ] Debugging messages (DEVELOPMENT) [ ] Debugging information files (DEVELOPMENT) [ ] Debugging information files in debugfs (DEVELOPMENT) (2) Maximum VBUS Power usage (2-500 mA) USB Peripheral Controller (Inventra HDRC USB Peripheral (TI, ADI, ...)) ---> <*> USB Gadget Drivers (File-backed Storage Gadget) ---> File-backed Storage Gadget [ ] File-backed Storage Gadget testing version
built the uImage, and booted the kernel, but usb gadget (AM3715) is not getting detected at host side.
Thanks Jitendra
what console log you get after inserting the module? You should select file storage gadget as module and not builtin.
<M> USB Gadget Drivers () ---> File-backed Storage Gadget [M] File-backed Storage Gadget testing version
Regards,
ajay
If my reply answers your question then please click on the green button "Verify Answer"
I had tested the usb file storage gadget as module and it is working for me.
Now. I want to build usb file storage as built-in kernel module, and test the same. To do this, I modified the default "mod_data" in "drivers/usb/gadget/file_storage.c"
mod_data = { // Default values .transport_parm = "BBB", .protocol_parm = "SCSI", .removable = 0, .can_stall = 1, .cdrom = 0, .vendor = FSG_VENDOR_ID, .product = FSG_PRODUCT_ID, .release = 0xffff, // Use controller chip type .buflen = 16384, };
To
mod_data = { // Default values .transport_parm = "BBB", .protocol_parm = "SCSI", .removable = 1, .can_stall = 0, .cdrom = 0, .vendor = FSG_VENDOR_ID, .product = FSG_PRODUCT_ID, .release = 0xffff, // Use controller chip type .buflen = 16384, };
And built and booted the kernel, And grepped for "storage" as:
root@omap3evm:~# dmesg | grep storageusbcore: registered new interface driver usb-storageg_file_storage gadget: File-backed Storage Gadget, version: 20 November 2008g_file_storage gadget: Number of LUNs=1
Now, using the sysfs, echoed the usb_backed_file_storage path as:
root@omap3evm:~# echo /dev/mmcblk0p1 > /sys/module/g_file_storage/parameters/file
And, then, connected the usb otg cable. The usb got detected at the host side (on windows, able to see usb detect icon on taskbar and Removable Disk(E:) folder). But when try browse the Removable Disk (E:) folder it shows "Please insert a disk into drive E:".
On the debug console, as usb-otg cable is connected, following message appears.
root@omap3evm:~# g_file_storage gadget: high speed config #1
The cat for usb file storage shows
root@omap3evm:~# cat /sys/module/g_file_storage/parameters/*N/dev/mmcblk0p10YNroot@omap3evm:~#
I do not see any error message, still usb file storage gadget not working, will it only work if it is build as module?
Or, missed some configuration??
I have no experience with the procfs or sysfs. In theory, your "file" parameter should have been picked when you plug in, ie bind().Maybe initialize the module parameter "file" as well. This line says what to initialize:module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,S_IRUGO);MODULE_PARM_DESC(file, "names of backing files or devices");And add this to your mod_data initializers:.file = {"/dev/mmcblk0"},.num_filenames = 1;
I have tried the adding file parameter initialization but it failed with error message
unable to open backing file: /dev/mmcblk0
It might have failed because the MMC has still not been detected and mounted by kernel while g_file_storage module being loaded in kernel. May loading of the "g_file_storage" module once file system has been loaded, help.
Can the "file" parameter for g_file_storage module be specified from "bootargs" ?
You are probably right. The File Storage Gadget is loading before MMC. Googled about and the kernel loads builtin modules in the order that they were linked. Modifiying the link order sounds like a very grim task. Some notes here "http://www.spinics.net/lists/linux-usb/msg20860.html" but it doesn't look like a real solution.
I don't know of any bootargs that might help. I've used "rootdelay" and/or "rootwait" to wait for SD Card root device. In your case, the SD Card isn't the root device. The bootargs are documented in your Linux source in Documentation/kernel-parameters.txt.
I suppose you could modify file_storage.c to try again. I would not know how to do this properly. A work-around test is to boot-up with USB unplugged. Once boot-up, plug in the USB. The File Storage Gadget should not try to open backing store until it is plugged in, ie bind() is called.
Thanks Wong, The patch referred by you which delays the bind() operation till file system is not mounted worked. But With this approach I have to initialize the file parameter statically.
If I pass the file parameter from sysFs enrty. I see the same old Problem. The USB gadget is getting detected at Host, but when the USB gadget is browsed, it gives error "insert the disk". I modified the "mod_data" as :
mod_data = { // Default values .transport_parm = "BBB", .protocol_parm = "SCSI",#ifdef CONFIG_USB_FILE_STORAGE .file ={"/dev/mmcblk0p1"}, .removable = 1, .can_stall = 0,#else .removable = 0, .can_stall = 1,#endif .cdrom = 0, .vendor = FSG_VENDOR_ID, .product = FSG_PRODUCT_ID, .release = 0xffff, // Use controller chip type .buflen = 16384, };
I think to support the initialization of file parameter by sysFs, The bind() operation show be delayed till the file parameter has not been initialized via sysfs.
Thanks
Jitendra
The problem is that soon after init(), bind() occurs automatically after the USB setup phase. The key would be to delay init() until the backing store is ready. I don't know what the "Linux" way to do such a thing. A direct hack would be to call the File Storage init() from where-ever the SD driver figures out it is mounted. Another direct hack would have File Storage init() spawn a thread that periodically checks the backing store before really starting the real init process. Neither seem particularily elegant. I have no experience with sysfs. Can't comment on that.
I read up on the kernel boot args. It is suppose to be possible to pass in parameters to built-in modules.
g_file_storage.file=/dev/mmcblk0p1g_file_storage.num_filenames=1g_file_storage.removable=1g_file_storage.can_stall=0
In theory, adding the above to your u-boot bootarg should work. Never tried such a thing myself though. I cannot say if it works.
With my limited knowledge of the Gadget/Linux, I am not sure there is an easy way to implement a built-in File Storage Gadget. The way that Gadgets are designed, they seem to demand runtime modules.
EDIT:
Oops. Disregard g_file_storage.num_filenames as it is a structure member and not a module parameter.
Hi Norman,
I am able to test the g_file_storage as usb gadget with g_file_storage being built-in with kernel itself without applying the suggested patch for delayed binding of fsg_bind() once the file system is mounted.
To test g_file_storage as built-in kernel, update the kernel bootargs with
g_file_storage.removable=1g_file_storage.can_stall=0
And, boot the kernel.
Then, use following sysFs entry, to insert the file-backed storage path name as:
echo <file_backed_storage_path> > /sys/devices/platform/musb_hdrc/gadget/gadget-lun0/file
This will export the <file_backed_storage> drive at host.
To remove the path file_backed storage pass null to /sys/devices/platform/musb_hdrc/gadget/gadget-lun0/file as:
echo "" > /sys/devices/platform/musb_hdrc/gadget/gadget-lun0/file
That's good news. I think I sort of understand the functional intent now. It looks like you are building a card reader where you can control the host access to the card. Thanks for the sysfs info.