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

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

  • In reply to Ajay:

    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

     

  • In reply to Jitendra Kumar:

    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;

     

  • In reply to Norman Wong:

    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

     

  • In reply to Jitendra Kumar:

    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.

     

  • In reply to Norman Wong:

    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

  • In reply to Jitendra Kumar:

    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.

  • In reply to Norman Wong:

    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

  • In reply to Jitendra Kumar:

    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.

  • In reply to Norman Wong:

    hi all,

    i am using BBB with ti sdk 07 with arago minimal file system

    i want to test the usb gadget mass storage option, the target is export eMMC block1 as usb storage

    the kernel version is 3.12

    i g_mass_storage module is inbuilt to kernel

    i tried as below and got error

     echo "/dev/mmcblk1p1" > /sys/module/g_mass_storage/parameters
    -sh: /sys/module/g_mass_storage/parameters/file: Permission denied

    i tried by passing " g_file_storage.can_stall=0  g_file_storage.removable=1" to cmd line , but no use

    can u plz help me ?

    regards

    Nagendra