I would like to emulate an USB from an image file.I am using Centos7 with the Kernel 4.11.7 installed through kernel-ml and kernel-ml-devel elrepo 4.11.7-1.el7.elrepo.x86_64 (actually I tried with 3.10.* 4.10.* 4.11.1 too)We have 2 solutions:with insmodsudo insmod /link/to/g_mass_storage.ko file=/tmp/filebin.img stall=0 removable=yIn dmesg:udc-core: couldn't find an available UDC - added [g_mass_storage] to list of pending driverswith modprobe$ sudo modprobe g_mass_storage file=/tmp/testusb.img stall=0 removable=y modprobe: FATAL: Module g_mass_storage not found.Nothing in dmesg.I have also tried with dummy_hcd:$ sudo modprobe dummy_hcdmodprobe: FATAL: Module dummy_hcd not found.How can I fix this problem ?I tried many things like recompiling the Kernel 4.11.1 by enabling everything with gadget etc.../usr/src/kernels/4.11.7-1.el7.elrepo.x86_64 $ cat .config | grep CONFIG_USB_DUMMY_HCD# CONFIG_USB_DUMMY_HCD is not setResult:After compiling the kernel, I was able to modprobe dummy_hcd and to emulate an usb with a binary file.
Emulating usb device with a file using g_mass_storage => udc-core: couldn't find an available UDC - added [g_mass_storage] to list of pending drivers
kernel modules
You need the dummy_hcd dummy (loopback) host controller device. The gadget USB drivers are meant for real USB hardware, and on normal PCs this hardware doesn't exist. The loopback controller provides both the framework for the gadget controller, and a USB host controller to access them. So:$ sudo modprobe dummy_hcdgives you a new root hub$ lsusbBus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubNow you can modprobe the gadget driver$ sudo modprobe g_mass_storage file=/path/to/backing_file idVendor=0x1d6b idProduct=0x0104 iManufacturer=Myself iProduct=VirtualBlockDevice iSerialNumber=123and it will show up under the new root hub$ lsusbBus 005 Device 002: ID 0525:a4a5 Netchip Technology, Inc. Pocketbook Pro 903Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubNote that you don't need to simulate a USB mass storage device if you are just interested in the contents of the file, you can mount that directly (via the loop device, but that happens automatically).