To speed up my development, I’ll try using the dummy_hcd kernel module, which allows to emulate an OTG port connected to the computer.

dummy_hcd is missing on my GNU/Linux distribution (Linux Mint 17.3), so I had to build it myself:

apt-get source linux-image-`uname -r`
cd linux-lts-vivid-3.19.0
cp /boot/config-`uname -r` .config
cp /usr/src/linux-headers-`uname -r`/Module.symvers .
make menuconfig
# select → Device Drivers → USB support → USB Gadget Support → USB Peripheral Controller → Dummy HCD
make prepare
make scripts
make -j 4 M=drivers/usb/gadget
sudo cp drivers/usb/gadget/udc/dummy_hcd.ko /lib/modules/`uname -r`/kernel/drivers/usb/gadget/udc/
sudo depmod -a

Adding the following line to /etc/fstab makes it easier to mount the gadget file system:
gadget /dev/gadget gadgetfs noauto,user,group 0 0

Creating a udev rule in /etc/udev/rules.d/99-gadgetfs.rules allows to automatically mount the gadget filesystem when dummy_hcd is loaded:
ACTION=="add", DEVPATH=="/module/dummy_hcd" SUBSYSTEM=="module" RUN+="/bin/mkdir /dev/gadget" RUN+="/bin/mount /dev/gadget"
ACTION=="remove", DEVPATH=="/module/dummy_hcd" SUBSYSTEM=="module" RUN+="/bin/umount /dev/gadget" RUN+="/bin/rmdir /dev/gadget"

To apply this rule without rebooting:
sudo udevadm control --reload-rules

dummy_hcd can be loaded using modprobe:
sudo modprobe dummy_hcd

or automatically loaded at boot time adding this line to /etc/module:

The gadget can finally be controlled using the /dev/gadget/dummy_udc file.

This entry was posted in gadgetfs and tagged . Bookmark the permalink.

10 Responses to dummy_hcd

  1. Tr0Y says:

    Awesome work. Thanks for your time and effort.

  2. johns says:


    Any development work already done?

    I got a S905 TV Box for < 30 Euro, which supports OTG.
    Linux and some gadget experiments are running.

    It seems that configs is the successor of gadgetfs.
    There is an easier to use library:

    I will now start to develop a PS4 pad emulator.


  3. Johns says:

    Too bad linux 3.4.x didn’t support configs and linux 3-14.x didn’t support AIO with functionfs.


Leave a Reply

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