how usb gadget driver upper layer driver get loaded? - linux

My embedded linux board has usb-net gadget functionality. From my host computer I am able to establish ethernet over usb connectivity. I am trying to understand how the different layers of the usb gadget subsystem layers work together.
In the device tree, I can see the platform specific udc driver and in the kernel configuration I can see the USB Gadget and Ethernet Gadget support being enabled in the kernel drivers. So as I understand the g_ether driver gets built-in part of the kernel.
What configuration creates the usb gadget interface and endpoint and links it to the upper layer driver (g_ether) and creates the usb-net gadget ethernet interface ?
Where to define the usb class function of the gadget and load a different upper layer driver ?

I am running version 5.10.36 kernel on my system. After some research and study, this is what I know so far.
So during linux kernel build, I have following option setup in menuconfig.
Symbol: USB_ETH [=m]
Prompt: Ethernet Gadget (with CDC Ethernet support)
Defined at drivers/usb/gadget/Kconfig:628
Depends on: <choice> && NET
Location:
-> Kernel configuration
-> Device Drivers
-> USB support (USB_SUPPORT [=y])
-> USB Gadget Support (USB_GADGET [=y])
-> USB Gadget Drivers (<choice> [=y])
This configuration gives a predefined USB net gadget interface with CDC ethernet support and required end-point configuration. This driver is g_ether.
The end point configuration is predefined in the file
drivers->usb->gadget->function->f_ecm.c
configFS can be used to configure a custom usb gadget interface from the user-space level.

Related

What do I need to do to set up usb audio gadget i/o on a beaglebone running debian?

I want to use alsa on a Beaglebone Black to send audio through usb audio out and receive it on my computer.
I have seen that there are some gadgets in a legacy folder in the kernel, and seen some tutorials on how to set up mass storage and network gadgets, but I am confused about what the state of audio gadgets is and what to compile and configure for this.
Can you explain the various components and configurations that need to go into place to make this happen, covering which kernel modules, drivers, kinds of scripts, and configurations that might be needed to do this?
You need to enable USB gadget subsystem in your Linux kernel for Beaglebone Black. Assuming of course that you have USB device controller and USB device connector on your Beaglebone. Here there are more information:
https://www.lynxbee.com/usb-audio-gadget-driver/
USB devices contains so called USB descriptors which tells USB host (PC) as a what device type it works. Audio gadget is one of the type of that descriptor that tells that this device (in this case BeagleBone) should be working as a audio device.

Creating custom virtual usb device using usb-vhci

I am new to working on virtual USB device simulation in Linux. So far I have installed the virtual host control (vhci) libraries as per this tutorial (http://sourceforge.net/p/usb-vhci/wiki/Home/) and can see a virtual USB device being created which has some typical specifications that the library implements (Bus 05 in the image with the vendor and product IDs being "dead" and "beef" respectively).
However I want the created virtual device to have the specifications of a real device I have at hand (a mouse, for example).
So how to enumerate and initialize a virtual USB device with the same credentials as another device?
The kernel module (vhci-hcd) is only a (virtual) host controller that you can attach virtual devices to.
If you want to emulate eg a mouse you should get the libusb_vhci from the same source, and look into the examples. These are bare minimum starting points that does nothing except for the basic usb device handling. You'll have to extend this with all descriptors and protocol handling for a USB HID mouse or whatever you want to emulate.
http://www.usbmadesimple.co.uk/ums_5.htm should be a good starting point.
you can use lsusb and in particular lsusb -D to dump the descriptors of devices you have connected.

Tracing traffic in Linux-based usb gadget (CDC/NCM)

I have a linux platform* that is connected as a usb device to an automotive device which acts as the USB host. The two devices should communicate over CDC/NCM, but the linux platform is not recognised by the automotive device and therefore the connection is not established. Surprisingly a connection to my computer is established correctly.
I now need to create a trace of that USB connection in order to check if there is an error in the USB handshake that can't be handled by the automotive device. As I cannot access the USB host, I need to create the trace from the gadget side.
I tried using usbmon and tcpdump, but this seems to work only for USB controllers configured as hosts on the tracing platform, not for ones configured as devices.
How can I configure usbmon to work also on devices?
If that is not possible are there any other possibilities to achieve this? (preferrably without hacking any drivers...)
Or do I have to use a Hardware USB sniffer?
BTW, all required modules (esp. g_ncm) are correctly loaded.
Thank you for your help!
stefan
*custom distribution on a freescale iMX6 processor (ARM), Kernel Version 3.0.35

Linux driver for embedded Linux

I'm looking to attach some USB devices to my embedded Linux board.
It is an TI-ARM processor running embedded Linux, but I guess it could be any embedded Linux board.
If I purchase an USB device which has Linux support/driver, can this driver (generally) be re-compiled to work with the ARM architecture? (Instead of Windows ect.).
Yes, USB drivers can generally be expected to compile for other architectures other than x86. Of course this presumes that your board does have a host USB port. There are a few boards that have only USB device ports, and many SoCs have both USB host & device ports.
But successfully compiling the (USB) driver may only be part of the task.
Some (USB) devices may require additional packages of libraries and other drivers for interfacing to application programs. For instance a USB digital TV tuner requires numerous packages (V4L, ALSA, I2C driver, userland firmware loading) to actually work.
Clarification
These additional dependencies that you may have to build are not because of USB.
The dependencies are related to the type of device.
An Ethernet interface, whether integrated into the SoC or offboard using USB, would be easily configured for full support in the kernel (e.g. protocol stack) and userland (e.g. Busybox has ifconfig, ping and routing apps).
A PCI TV tuner would have the same dependencies as the USB tuner. But the embedded environment typically means that you don't have any/most of these multimedia dependencies already built/installed.

driver requirments for a bsp. should a bsp contain drivers for devices run on spi?

I am developing a BSP for a Linux board. The boards contains a device which runs on SPI. can you please tell me if BSP should contain driver for that device or should I only provide SPI port driver in BSP?
Also if some device has user mode driver instead of kernel mode. Then this user mode driver will be part of BSP?

Resources