Home Uncategorized Food Using dummy-hcd on Linux to play with USB gadgets

Food Using dummy-hcd on Linux to play with USB gadgets

Food Using dummy-hcd on Linux to play with USB gadgets


Food Andrzej Pietrasiewicz avatar

Andrzej Pietrasiewicz
June 24, 2019

In this post, I promised to tell you how to use dummy_hcd, which is composed of a software-emulated host controller and a UDC chip. In other text, this signifies you can perform with USB gizmos even if you will not have the acceptable components, for the reason that your Computer can act as each a USB host and a USB device.

Of program we also have to have some gadget to operate, so why you should not we use cmtp-responder? You could also want to examine about USB gizmos below and in this article. The description will be Debian-dependent, so for other techniques you have to have to change it accordingly.


We will have to have a bunch of offers:

gcc # we require a compiler to compile everything
g++ # to fulfill cmake the straightforward way, but if not not utilized)
libconfig-dev # libusbgx and gt need to have libconfig
cmake # gt and cmtp-responder use cmake to create Makefiles
git # we will be cloning from git.kernel.org and github.com
autoconf # libusbgx wants it
libtool # libusbgx wants it
asciidoc-base (for a2x) # gt builds its manpage with it
libncurses-dev # compiling the kernel
libglib2.-dev # gt needs it
libsystemd-dev # gt demands it
usbutils # for lsusb

Run this:

apt-get put in gcc g++ libconfig-dev cmake git autoconf libtool asciidoc-foundation libncurses-dev flex bison make-essential fakeroot libelf-dev libssl-dev bc libglib2.-dev libsystemd-dev usbutils
apt-get clean up

Once complete, you can then put in libusbgx and gt.


git clone https://github.com/libusbgx/libusbgx.git
cd libusbgx
autoreconf -i
./configure  --prefix=/usr
make put in # as root


git clone https://github.com/kopasiak/gt.git
cd gt/resource
cmake -DCMAKE_Set up_PREFIX=.
make set up # as root

Sad to say, the default kernel has neither ConfigFS nor dummy_hcd help turned on. Let us take care of it!

The kernel

Make sure the following alternatives are established in the kernel config:

CONFIG_CONFIGFS_FS=y               # ConfigFS aid
CONFIG_USB=y                       # USB support
CONFIG_USB_GADGET=y                # USB gadget framework
CONFIG_USB_DUMMY_HCD=y             # dummy_hcd, our emulated USB host and machine
CONFIG_USB_CONFIGFS=y              # composing USB gizmos with ConfigFS
CONFIG_USB_CONFIGFS_F_FS=y         # make FunctionFS a ingredient for making USB gadgets with ConfigFS

Compile and put in the kernel your beloved way.


Many thanks to the actuality that we enabled the relevant bits of the kernel, we must have dummy_hcd up and running now. To ensure, do this:

ls -l /sys/class/udc

dummy_udc. must be there. If it is not, validate that all the previous methods have succeeded.

gt udc

This really should also exhibit dummy_udc..

At the time dummy_udc. is there, your Computer system is completely ready to emulate USB gadget hardware!


We have chosen to empower ConfigFS aid. As latest Debian releases occur by default with systemd, your ConfigFS should be quickly mounted by/lib/systemd/procedure/sys-kernel-coonfig.mountdevice below/sys/kernel/config.

Many thanks to the enabled USB gadget, and the existence of our virtual UDC,/sys/kernel/configought to now consist ofusb_gadgetdirectory. From this instant on gizmos can be composed, for case in point with the gt.


We will create an MTP machine with cmtp-responder. When it runs, if you chose to put in graphical desktop environment, you will be able to click on on its icon and use it as if it have been, for example, the storage place of a linked smartphone.

The guidance for cmtp-responder are right here, but I supply a quick summary for you underneath:

git clone https://github.com/cmtp-responder/cmtp-responder.git
cd cmtp-responder
make install # as root

All the beneath as root:

mkdir /and so on/gt/templates
cp systemd/mtp-ffs.scheme /and many others/gt/templates
cp systemd/*.socket /etc/systemd/technique
cp systemd/*.company /etcetera/systemd/program
cp systemd/*.mount /etc/systemd/program
systemctl help usb-gadget.services
systemctl empower operate-ffs_mtp.mount
systemctl allow ffs.socket

Generate/and many others/systemd/system/usb-gadget.goalif you really don’t have it in/lib/systemd/procedure:

Description=Harware activated USB gadget

And develop/and many others/udev/principles.d/99-systemd.ruleswith the underneath contents if your/lib/udev/policies.d/99-systemd.rulesdoes not contain the adhering to line:

SUBSYSTEM=="udc", Action=="include", TAG+="systemd", ENVSYSTEMD_Wishes+="usb-gadget.concentrate on"

After reboot your cmtp-responder need to activate immediately. You can verify its existence withlsusb(run as root):

Bus 001 Product 002: ID 1d6b:0100 Linux Foundation PTP Gadget
System Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass             (Described at Interface amount)
  bMaxPacketSize0        sixty four
  idVendor           0x1d6b Linux Basis
  idProduct          0x0100 PTP Gadget
  bcdDevice            five.01
  iManufacturer           one Collabora
  iProduct                two MTP Gadget
  iSerial                 three 000000001
  bNumConfigurations      one
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           39
    bNumInterfaces          one
    bConfigurationValue     1
    bmAttributes         0x80
      (Bus Run)
    MaxPower                2mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         four
      bNumEndpoints           three
      bInterfaceClass         6 Imaging
      bInterfaceSubClass      one Even now Picture Capture
      bInterfaceProtocol      1 Image Transfer Protocol (PIMA 15470)
      iInterface              four Collabora MTP
      Endpoint Descriptor:
        bLength                 seven
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Sort            Bulk
          Synch Kind               None
          Usage Form               Information
        wMaxPacketSize     0x0200  1x 512 bytes
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         five
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            two
          Transfer Type            Bulk
          Synch Variety               None
          Usage Variety               Information
        wMaxPacketSize     0x0200  1x 512 bytes
      Endpoint Descriptor:
        bLength                 seven
        bDescriptorType         five
        bEndpointAddress     0x85  EP 5 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Kind               None
          Use Form               Details
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               6
Gadget Qualifier (for other gadget pace):
  bLength                10
  bDescriptorType         six
  bcdUSB               two.00
  bDeviceClass             (Defined at Interface amount)
  bMaxPacketSize0        64
  bNumConfigurations      1
Unit Status:     0x0000
  (Bus Run)

This screenshot illustrates copying a more substantial file to our MTP gadget.

Food Screenshot illustrating copying a larger file to MTP gadget.

The backing storage is/media/card, and can be configured at compile time ininvolve/mtp_config_h (MTP_External_Route_CHAR).

Pleased actively playing with cmtp-responder!

In the up coming installment, I will notify you how to run it on actual ARM components, so remain tuned.

Previous articleBlizzard president apologizes for ‘failure’ in Hong Kong debacle
Next articleGradual ringtones make their way to Google Pixel phones


Please enter your comment!
Please enter your name here