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.

Porting USB GadgetFS software to Processor SDK 2.00.02.11

Hi,

I have been developing my application using SDK 1.00.00.03. It uses USB GadgetFS to connect to host PC and it's been working ok. Now I want to upgrade the SDK to the latest released version and found out that USB stuff has changed a lot. The newer version of linux seems to be using ConfigFS. Is there a tutorial/example for developing custom firmware application using this new USB stack?

I have found "Kernel USB Gadget Configfs Interface - The Linux Foundation" pdf but it uses libusbg which I couldn't compile for SDK. It uses libconfig-dev and that package was not available in the file system. I'm using custom board based on Beagle Bone Black.

Any help would be appreciated.

  • Hi,

    I will forward this to the USB experts.
  • Brain,

    ConfigFS and GadgetFS are completely two different things. ConfigFS is not a replacement of GadgetFS. GadgetFS support is still there in P-SDK 2.0.2.11.

  • Hi Bin,
    Thanks for your response. How do I use GadgetFS with SDK2.0.2.11? I tried to configure and enable only GadgetFS in SDK2 and, when I ran my code, the machine locks up with bunch of garbage printout filling up my console continuously. Am I doing it correctly? When I was using SDK1, I reconfigured kernel to enable GadgetFS module and it just worked. Is there a way to use GadgetFS without rebuilding SDK2 kernel? Could you give me some pointers?

    Thanks.
  • Brian Park75 said:
    Is there a way to use GadgetFS without rebuilding SDK2 kernel? Could you give me some pointers?

    You don't have to rebuild the kernel, once you boot the board with the prebuilt image and rootfs in the release, run command 'modprobe gadgetfs', which will load the gadgetfs driver.

  • OK.
    It looks like usb.c example has been updated to work with newer kernel. I initially started my code from www.linux-usb.org/.../usb.c example and I see that it has since been updated. However, even when trying out the latest code, I get the following error message.

    ```
    root@am335x-evm:~# mkdir /dev/gadget
    root@am335x-evm:~# modprobe gadgetfs
    [ 188.509592] gadgetfs: USB Gadget filesystem, version 24 Aug 2004
    root@am335x-evm:~# mount -t gadgetfs gadgetfs /dev/gadget
    [ 195.434647] udc musb-hdrc.0.auto: registering UDC driver [(null)]
    root@am335x-evm:~# ./usb_test
    ?? don't recognize /dev/gadget bulk device
    ```

    You can find my usb_test code from this link (onedrive.live.com/redir. I took usb.c and converted it to .cpp and compiled it with SDK2. What is wrong with this code?
  • Ok. Figured out that "?? don't recognize /dev/gadget bulk device" is because the example code was looking for "musb_hdrc" when the actual device name is "musb-hdrc". However with that change, this example also seems to crash the kernel.

    I get continuous flow of the following error messages.

    ```

    [ 4134.286537] CPU: 0 PID: 665 Comm: usb_test Tainted: G D W O 4.1.18-gbbe8cfc #1
    [ 4134.294586] Hardware name: Generic AM33XX (Flattened Device Tree)
    [ 4134.300702] Backtrace:
    [ 4134.303185] [<c0012b18>] (dump_backtrace) from [<c0012d38>] (show_stack+0x18/0x1c)
    [ 4134.310784] r7:ddbf1c0c r6:c08abb00 r5:dcc56400 r4:00000000
    [ 4134.316517] [<c0012d20>] (show_stack) from [<c0634524>] (dump_stack+0x20/0x28)
    [ 4134.323790] [<c0634504>] (dump_stack) from [<c0053d94>] (__schedule_bug+0x48/0x60)
    [ 4134.331395] [<c0053d4c>] (__schedule_bug) from [<c06360e0>] (__schedule+0x414/0x4c0)
    [ 4134.339178] r5:dcc56400 r4:c06361d0
    [ 4134.342781] [<c0635ccc>] (__schedule) from [<c06361d0>] (schedule+0x44/0x9c)
    [ 4134.349865] r9:00000000 r8:00000000 r7:ddbf1c0c r6:00000000 r5:00000000 r4:ddbf0000
    [ 4134.357684] [<c063618c>] (schedule) from [<c0639140>] (schedule_hrtimeout_range_clock+0x124/0x130)
    [ 4134.366687] r5:00000000 r4:00000000
    [ 4134.370288] [<c063901c>] (schedule_hrtimeout_range_clock) from [<c0639160>] (schedule_hrtimeout_range+0x14/0x18)
    [ 4134.380510] r6:00000000 r5:00000000 r4:ddbf1cfc
    [ 4134.385175] [<c063914c>] (schedule_hrtimeout_range) from [<c01167ac>] (poll_schedule_timeout+0x3c/0x64)
    [ 4134.394621] [<c0116770>] (poll_schedule_timeout) from [<c0117d3c>] (do_sys_poll+0x3d0/0x4a8)
    [ 4134.403098] r5:00000000 r4:ddbf1c0c
    [ 4134.406699] [<c011796c>] (do_sys_poll) from [<c0117ee4>] (SyS_poll+0x78/0x100)
    [ 4134.413956] r10:00000000 r9:ddbf0000 r8:c000fa24 r7:000000a8 r6:00000000 r5:bef56b94
    [ 4134.421847] r4:00000001
    [ 4134.424407] [<c0117e6c>] (SyS_poll) from [<c000f880>] (ret_fast_syscall+0x0/0x3c)
    [ 4134.431916] r5:00000000 r4:00000008
    [ 4134.435532] BUG: scheduling while atomic: usb_test/665/0xfffffffe
    [ 4134.441646] Modules linked in: gadgetfs ipv6 pvrsrvkm(O) usb_f_acm u_serial usb_f_ecm usb_f_mass_storage usb_f_rndis u_ether libcomposite cryptodev(O) musb_dsps musb_hdrc udc_core usbcore omap_aes_driver(+) omap_sham(+) omap_rng(+) pruss(+) pm33xx rng_core rtc_omap omap_wdt musb_am335x ti_am335x_tsc ti_am335x_tscadc leds_gpio
    [ 4134.472197] CPU: 0 PID: 665 Comm: usb_test Tainted: G D W O 4.1.18-gbbe8cfc #1
    [ 4134.480245] Hardware name: Generic AM33XX (Flattened Device Tree)
    [ 4134.486371] Backtrace:
    [ 4134.488845] [<c0012b18>] (dump_backtrace) from [<c0012d38>] (show_stack+0x18/0x1c)
    [ 4134.496453] r7:ddbf1c0c r6:c08abb00 r5:dcc56400 r4:00000000
    [ 4134.502167] [<c0012d20>] (show_stack) from [<c0634524>] (dump_stack+0x20/0x28)
    [ 4134.509435] [<c0634504>] (dump_stack) from [<c0053d94>] (__schedule_bug+0x48/0x60)
    [ 4134.517052] [<c0053d4c>] (__schedule_bug) from [<c06360e0>] (__schedule+0x414/0x4c0)
    [ 4134.524834] r5:dcc56400 r4:c06361d0
    [ 4134.528438] [<c0635ccc>] (__schedule) from [<c06361d0>] (schedule+0x44/0x9c)
    [ 4134.535523] r9:00000000 r8:00000000 r7:ddbf1c0c r6:00000000 r5:00000000 r4:ddbf0000
    [ 4134.543340] [<c063618c>] (schedule) from [<c0639140>] (schedule_hrtimeout_range_clock+0x124/0x130)
    [ 4134.552334] r5:00000000 r4:00000000
    [ 4134.555947] [<c063901c>] (schedule_hrtimeout_range_clock) from [<c0639160>] (schedule_hrtimeout_range+0x14/0x18)
    [ 4134.566170] r6:00000000 r5:00000000 r4:ddbf1cfc
    [ 4134.570825] [<c063914c>] (schedule_hrtimeout_range) from [<c01167ac>] (poll_schedule_timeout+0x3c/0x64)
    [ 4134.580270] [<c0116770>] (poll_schedule_timeout) from [<c0117d3c>] (do_sys_poll+0x3d0/0x4a8)
    [ 4134.588749] r5:00000000 r4:ddbf1c0c
    [ 4134.592349] [<c011796c>] (do_sys_poll) from [<c0117ee4>] (SyS_poll+0x78/0x100)
    [ 4134.599608] r10:00000000 r9:ddbf0000 r8:c000fa24 r7:000000a8 r6:00000000 r5:bef56b94
    [ 4134.607507] r4:00000001
    [ 4134.610055] [<c0117e6c>] (SyS_poll) from [<c000f880>] (ret_fast_syscall+0x0/0x3c)
    [ 4134.617574] r5:00000000 r4:00000008
    [ 4134.621181] BUG: scheduling while atomic: usb_test/665/0xfffffffe
    [ 4134.627307] Modules linked in: gadgetfs ipv6 pvrsrvkm(O) usb_f_acm u_serial usb_f_ecm usb_f_mass_storage usb_f_rndis u_ether libcomposite cryptodev(O) musb_dsps musb_hdrc udc_core usbcore omap_aes_driver(+) omap_sham(+) omap_rng(+) pruss(+) pm33xx
    ```

    The error message kept repeating until I issued a reboot command from another shell. Then, it caused kernel panic.

    ```
    [ 4143.332875] Modules linked in: gadgetfs ipv6 pvrsrvkm(O) usb_f_acm u_serial uINIT: Sending processes the TERM signal
    u_ether libcomposite cryptodev(O) musb_dsps musb_hdrc udc_core usbcore omap_aes_driver(+) omap_sham(+) omap_rng(+) pruss(+) pm33xx rng_core rtc_omap omap_wdt musb_am335x ti_am335x_tsc ti_am335x_tscadc leds_gpio
    [ 4143.370571] CPU: 0 PID: 665 Comm: usb_test Tainted: G D W O 4.1.18-gbbe8cfc #1
    [ 4143.378637] Hardware name: Generic AM33XX (Flattened Device Tree)
    [ 4143.384763] Backtrace:
    [ 4143.387251] [<c0012b18>] (dump_backtrace) from [<c0012d38>] (show_stack+0x18/0x1c)
    [ 4143.394868] r7:ddbf1c0c r6:c08abb00 r5:dcc56400 r4:00000000
    [ 4143.400588] [<c0012d20>] (show_stack) from [<c0634524>] (dump_stack+0x20/0x28)
    [ 4143.407868] [<c0634504>] (dump_stack) from [<c0053d94>] (__schedule_bug+0x48/0x60)
    [ 4143.415487] [<c0053d4c>] (__schedule_bug) from [<c06360e0>] (__schedule+0x414/0x4c0)
    [ 4143.423268] r5:dcc56400 r4:c06361d0
    [ 4143.426868] [<c0635ccc>] (__schedule) from [<c06361d0>] (schedule+0x44/0x9c)
    [ 4143.433953] r9:00000000 r8:00000000 r7:ddbf1c0c r6:00000000 r5:00000000 r4:ddbf0000
    [ 4143.441765] [<c063618c>] (schedule) from [<c0639140>] (schedule_hrtimeout_range_clock+0x124/0x130)
    [ 4143.450767] r5:00000000 r4:00000000
    [ 4143.454378] [<c063901c>] (schedule_hrtimeout_range_clock) from [<c0639160>] (schedule_hrtimeout_range+0x14/0x18)
    [ 4143.464603] r6:00000000 r5:00000000 r4:ddbf1cfc
    [ 4143.469260] [<c063914c>] (schedule_hrtimeout_range) from [<c01167ac>] (poll_schedule_timeout+0x3c/0x64)
    [ 4143.478705] [<c0116770>] (poll_schedule_timeout) from [<c0117d3c>] (do_sys_poll+0x3d0/0x4a8)
    [ 4143.487185] r5:00000000 r4:ddbf1c0c
    [ 4143.490787] [<c011796c>] (do_sys_poll) from [<c0117ee4>] (SyS_poll+0x78/0x100)
    [ 4143.498046] r10:00000000 r9:ddbf0000 r8:c000fa24 r7:000000a8 r6:00000000 r5:bef56b94
    [ 4143.505945] r4:00000001
    [ 4143.508494] [<c0117e6c>] (SyS_poll) from [<c000f880>] (ret_fast_syscall+0x0/0x3c)
    [ 4143.516015] r5:00000000 r4:00000008
    [ 4143.520603] Kernel panic - not syncing: Aiee, killing interrupt handler!
    [ 4143.527358] ---[ end Kernel panic - not syncing: Aiee, killing interrupt handler!
    ```

    Please, help.
  • Bin,

    Were you able to duplicate the problem? I'd like to get some indication where the problem is and whether it can be solved/worked around.

    Thank you.

  • Brain,

    I don't have time on this yet. I will update here once I am on it or find anything about the problem.
  • Bin,

    Could you at least give me some idea when you will have time to check this out? I recently found out that USB communication using SDK1 is has some problems. If I can upgrade to SDK2 and USB communication is reliable, I don't have to spend time investigating the issue with SDK1. If you can give me some idea when you can take a look at this issue, I'd appreciate it.

    Thank you.

    Brian

  • Brain,

    Probably in a week or two. Sorry for the delay.
  • Brain,

    I am able to reproduce the kernel crash with gadgetfs and Processor SDK v2.x, and will update here when I find the root cause.
  • Bin,

    Thank you for the update. Hopefully, it's something that can be easily fixed.

    Brian

  • Brian,

    Please test the following patch, and let me know.

    diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
    index 2030565..69d5889 100644
    --- a/drivers/usb/gadget/legacy/inode.c
    +++ b/drivers/usb/gadget/legacy/inode.c
    @@ -934,8 +934,10 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
                            struct usb_ep           *ep = dev->gadget->ep0;
                            struct usb_request      *req = dev->req;
     
    +                       spin_unlock_irq (&dev->lock);
                            if ((retval = setup_req (ep, req, 0)) == 0)
                                    retval = usb_ep_queue (ep, req, GFP_ATOMIC);
    +                       spin_lock_irq (&dev->lock);
                            dev->state = STATE_DEV_CONNECTED;
     
                            /* assume that was SET_CONFIGURATION */
    @@ -1134,10 +1136,9 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
                                                    dev->gadget->ep0, dev->req,
                                                    GFP_KERNEL);
                                    }
    +                               spin_lock_irq(&dev->lock);
                                    if (retval < 0) {
    -                                       spin_lock_irq (&dev->lock);
                                            clean_req (dev->gadget->ep0, dev->req);
    -                                       spin_unlock_irq (&dev->lock);
                                    } else
                                            retval = len;
     
    
    
  • Bin,

    I tried your fix and it did fix the kernel panic. However, I still can't communicate with the host. As soon as the host sends a message, I get the following error message.

    read: Bad address
    get fifo status: Invalid argument
    fd 5, unclaimed = 0
    

    I'm trying to come up with a simple test program that will show the problem. Do you have your own GadgetFS test program?

    Thanks

  • Brian,

    I use usb.c in http://www.linux-usb.org/gadget/, but I only tested enumeration while debugging the kernel crash problem. I will try data traffic if I get time next week.

  • Hello Bin,

    Have you had chance to look at the data transfer issue? I'd appreciate a update.

    Thank you.

    Brian

  • Brian,

    I just tried testusb for data transfer and the test failed. I suspect that usb.c is out of date. You might want to get the support from the community - linux-usb@vger.kernel.org.