2

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:

  1. with insmod

    sudo insmod /link/to/g_mass_storage.ko file=/tmp/filebin.img stall=0 removable=y

In dmesg: udc-core: couldn't find an available UDC - added [g_mass_storage] to list of pending drivers

  1. with 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.

  2. I have also tried with dummy_hcd:

    $ sudo modprobe dummy_hcd modprobe: 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 set

Result: After compiling the kernel, I was able to modprobe dummy_hcd and to emulate an usb with a binary file.

4

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_hcd

gives you a new root hub

$ lsusb
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now 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=123

and it will show up under the new root hub

$ lsusb
Bus 005 Device 002: ID 0525:a4a5 Netchip Technology, Inc. Pocketbook Pro 903
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Note 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).

  • I forgot to say I tried dummy_hcd too. But : modprobe: FATAL: Module dummy_hcd not found. I don't know why I don't have this module. – Alexis_FR_JP Jun 27 '17 at 6:38
  • Verify that CONFIG_USB_DUMMY_HCD=m, and set and recompile if it isn't. – dirkt Jun 27 '17 at 6:41
  • It's not, Im gonna recompile. I'll let you keep informed. Thanks. – Alexis_FR_JP Jun 27 '17 at 6:50
  • It's working, thank you ! Btw how to "eject" the usb without rebooting ? – Alexis_FR_JP Jun 27 '17 at 23:24
  • 1
    sudo modprobe -r g_mass_storage works. – Alexis_FR_JP Jun 28 '17 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.