This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

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

Other Parts Discussed in Thread: AM3715

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

  • 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

     

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

    Thanks                                                                                                                                                                                                                                                                                                                       Jitendra

     

  • 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/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.

  • 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

  • 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.

  • 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

  • hi all

    i am able to test usb-gadget mass storage on BBB using modules with TI sdk 07

    but this  is working with only with linux

    the FAT partition of eMMC is detected in Linux machine but not in windows machine

    window unable to allocate drive letter for this

    window is showing Linux mass storage device in device Manager but not in Mycomputer


    what would be the reason for this ?

    regards

    Nagendra

  • I think you have to be careful to make the distinction between g_file_storage and g_mass_storage. I believe g_file_storage has been deprecated in favor of the newer g_mass_storage. Kernel command parameters must use the module name that is actually installed. It has been while since I have used this gadget. Back then, Windows required stall=0 and removable=1. Otherwise, Windows would not recognize it. Check the gadget doc in the kernel source documentation directory to get the exact parameter names.

  • hi  Norman,


    thanks!

    it is working. I tried as below 

     insmod g_mass_storage.ko file=/dev/mmcblk0p1 stall=0 removable=1

    regards

    Nagendra

  • hi all,


    i am flashing eMM of BBB using  image and dd command working fine, but taking time (10 mins for 2GB)

    i want to format eMMC while booting from uSD card itself, i tried it but not working, means the eMMC formatting is proper,  system can mount the partitions properly but unable to boot from the eMMC


    the sameprocedure is working if i do it for uSD card using linux host machine

    commands used

    root@am335x-evm:~# dd if=/dev/zero of=/dev/mmcblk1 bs=1024 count=4000

    root@am335x-evm:~# sfdisk -D  -H 255 -S 63 -C 233 /dev/mmcblk1 << EOF

    >0,90,C,*

    >,,,-

    >EOF

    root@am335x-evm:~# mkfs.vfat -F 32 /dev/mmcblk1p1 -n boot

     root@am335x-evm:~# mkfs.ext4 /dev/mmcblk1p2 -L "root"

    and copying MLO first to boot partition, but in vain

    any ideas ?

    regards

    nagendra

  • I am unsure what you are asking. Can you start a new forum thread? Clearly separate what you have done on the host and on the target. Show the results on success and failure.