• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » Linux » Linux forum » testing usb otg gadget (mass storage) as built in kernel module
Share
Linux
  • Forum
Options
  • Subscribe via RSS

testing usb otg gadget (mass storage) as built in kernel module

testing usb otg gadget (mass storage) as built in kernel module

This question is answered
Jitendra Kumar
Posted by Jitendra Kumar
on Apr 21 2011 00:38 AM
Intellectual285 points

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

USB OMAP AM3715 USB Gadget Mass Storage
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Ajay
    Posted by Ajay
    on Apr 21 2011 00:43 AM
    Genius9470 points

    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"

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jitendra Kumar
    Posted by Jitendra Kumar
    on Apr 21 2011 08:52 AM
    Intellectual285 points

    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 storage
    usbcore: registered new interface driver usb-storage
    g_file_storage gadget: File-backed Storage Gadget, version: 20 November 2008
    g_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/mmcblk0p1

    0
    Y
    N
    root@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??

    Thanks                                                                                                                                                                                                                                                                                                                  Jitendra

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Apr 21 2011 10:24 AM
    Guru14920 points

    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;

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jitendra Kumar
    Posted by Jitendra Kumar
    on Apr 22 2011 00:23 AM
    Intellectual285 points

    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" ?

    Thanks                                                                                                                                                                                                                                                                                                                       Jitendra

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Apr 22 2011 01:34 AM
    Guru14920 points

    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.

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jitendra Kumar
    Posted by Jitendra Kumar
    on Apr 25 2011 01:21 AM
    Intellectual285 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Apr 25 2011 02:12 AM
    Verified Answer
    Verified by Anonymous
    Guru14920 points

    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/mmcblk0p1
    g_file_storage.num_filenames=1
    g_file_storage.removable=1
    g_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.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Jitendra Kumar
    Posted by Jitendra Kumar
    on Apr 27 2011 06:08 AM
    Verified Answer
    Verified by Jitendra Kumar
    Intellectual285 points

    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=1
    g_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

    Thanks

    Jitendra

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Apr 27 2011 09:10 AM
    Guru14920 points

    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.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use