Home / Gadgets / Gadgets: The use of dummy-hcd on Linux to play with USB devices

Gadgets: The use of dummy-hcd on Linux to play with USB devices


Gadgets: Andrzej Pietrasiewicz avatar

Andrzej Pietrasiewicz

June 24, 2019

In this article, I promised to say you strategies to use dummy_hcd, which consists of a instrument-emulated host controller and a UDC chip. In thoroughly different phrases, this model it’s good to perhaps presumably also play with USB devices even as soon as you occur to bag now not receive the appropriate hardware, on narrative of your PC can act as both a USB host and a USB gadget.

Needless to articulate we also need some gadget to proceed, so why bag now not we use cmtp-responder? You doubtlessly also can just moreover are seeking to be taught USB devices right here and right here. The description will most likely be Debian-essentially essentially essentially based, so for thoroughly different programs it’s good to alter it accordingly.


We are able to need a bunch of packages:

gcc # we need a compiler to assemble anything
g++ # to satisfy cmake the straightforward intention, however otherwise now not broken-down)
libconfig-dev # libusbgx and gt need libconfig
cmake # gt and cmtp-responder use cmake to generate Makefiles
git # we are going to be cloning from git.kernel.org and github.com
autoconf # libusbgx desires it
libtool # libusbgx desires it
asciidoc-harmful (for a2x) # gt builds its manpage with it
libncurses-dev # compiling the kernel
libglib2.Zero-dev # gt desires it
libsystemd-dev # gt desires it
usbutils # for lsusb

Flee this:

correct-bag install gcc g++ libconfig-dev cmake git autoconf libtool asciidoc-harmful libncurses-dev flex bison kind-well-known fakeroot libelf-dev libssl-dev bc libglib2.Zero-dev libsystemd-dev usbutils
correct-bag dapper

Once total, it’s good to perhaps presumably also then install libusbgx and gt.


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


git clone https://github.com/kopasiak/gt.git
cd gt/source
manufacture install # as root

Sadly, the default kernel has neither ConfigFS nor dummy_hcd give a clutch to became on. Let’s fix it!

The kernel

Be obvious the next choices are bag within the kernel config:

CONFIG_CONFIGFS_FS=y               # ConfigFS give a clutch to
CONFIG_USB=y                       # USB give a clutch to
CONFIG_USB_GADGET=y                # USB gadget framework
CONFIG_USB_DUMMY_HCD=y             # dummy_hcd, our emulated USB host and gadget
CONFIG_USB_CONFIGFS=y              # composing USB devices with ConfigFS
CONFIG_USB_CONFIGFS_F_FS=y         # manufacture FunctionFS a component for establishing USB devices with ConfigFS

Bring together and install the kernel your favourite intention.


Thanks to the truth that we enabled the relevant bits of the kernel, we could perhaps also just mute receive dummy_hcd up and working now. To ascertain, attain this:

ls -l /sys/class/udc

dummy_udc.Zero could perhaps also just mute be there. If it is now not, test that every particular person the previous steps receive succeeded.

gt udc

This could also just mute also expose dummy_udc.Zero.

Once dummy_udc.Zero is there, your PC is ready to emulate USB gadget hardware!


We now receive got chosen to permit ConfigFS give a clutch to. As most contemporary Debian releases reach by default with systemd, your ConfigFS could perhaps also just mute be automatically mounted by /lib/systemd/machine/sys-kernel-coonfig.mount unit below /sys/kernel/config.

Thanks to the enabled USB gadget, and the presence of our digital UDC, /sys/kernel/config could perhaps also just mute now bear usb_gadget list. From this second on devices could even be mute, as an instance with the gt.


We are able to assemble an MTP gadget with cmtp-responder. When it runs, as soon as you occur to selected to put in graphical desktop ambiance, you will most likely be in a bag to click on its icon and use it as if it were, as an instance, the storage dwelling of a associated smartphone.

The directions for cmtp-responder are right here, however I provide a transient abstract for you below:

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

The total below as root:

mkdir /and masses others/gt/templates
cp systemd/mtp-ffs.intention /and masses others/gt/templates
cp systemd/*.socket /and masses others/systemd/machinecp systemd/*.service /and masses others/systemd/machinecp systemd/*.mount /and masses others/systemd/machinesystemctl allow usb-gadget.service
systemctl allow proceed-ffs_mtp.mount
systemctl allow ffs.socket

Save /and masses others/systemd/machine/usb-gadget.target as soon as you occur to bag now not receive it in /lib/systemd/machine:

Description=Harware activated USB gadget

And assemble /and masses others/udev/tips.d/Ninety nine-systemd.tips with the below contents in case your /lib/udev/tips.d/Ninety nine-systemd.tips does now not bear the next line:

SUBSYSTEM=="udc", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="usb-gadget.target"

After reboot your cmtp-responder could perhaps also just mute activate automatically. You doubtlessly can test its existence with lsusb (proceed as root):

Bus 001 Instrument 002: ID 1d6b:0100 Linux Foundation PTP Gadget
Instrument Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            Zero (Defined at Interface level)
  bDeviceSubClass         Zero 
  bDeviceProtocol         Zero 
  bMaxPacketSize0        sixty 4
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0100 PTP Gadget
  bcdDevice            5.01
  iManufacturer           1 Collabora
  iProduct                2 MTP Gadget
  iSerial                 three 000000001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           39
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          Zero 
    bmAttributes         0x80
      (Bus Powered)

Read More

About admin

Check Also

Gadgets: How to blur faces and remove metadata from your photos

Gadgets: How to blur faces and remove metadata from your photos

Credit: Wikimedia commons Welcome to TNW Basics, a collection of tips, guides, and advice on how to easily get the most out of your gadgets, apps, and other stuff. People all over the world have taken to the streets to support the Black Lives Matter movement and many of you might be taking photos to spread…

Leave a Reply

Your email address will not be published. Required fields are marked *