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:
dummy_hcd
The gadget can finally be controlled using the /dev/gadget/dummy_udc file.
Awesome work. Thanks for your time and effort.
Hi,
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: https://github.com/libusbgx/libusbgx
I will now start to develop a PS4 pad emulator.
Johns
Hi,
Yes, I did some preliminary work in the gadget branch of my serialusb project:
https://github.com/matlo/serialusb/tree/gadget
https://github.com/matlo/serialusb/tree/gadget/sw/lib/gasync/src/gadget/linux/gadget.c
configfs only allows to create devices that implement standard functions (e.g. an ethernet function, a serial function…). It does not provide full control, which is required for emulating devices with vendor-specific functions.
Thanks for the hints.
You may be right, but there is functionfs see linuxDocumentation/usb/functionfs.txt
Which should do what we want.
I have the problem on the device that the gadgetfs hangs after removing a device
.
functionfs and configfs seems to work better.
An example for ffs is in the linux kernel: tools/usb/ffs-test.c
Johns
I’m unsure if functionfs supports non blocking IO. I avoid threading as much as I can as it adds complexity and overhead. gadgetfs has non blocking IO through AIO.
Did you check if your gadgetfs issue is fixed in newer kernels?
Looks like AIO is also available for functionfs:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/tools/usb/ffs-aio-example/simple/device_app/aio_simple.c
I knew that i can’t use poll/select with normal gadgetfs.
Nice to know that i can use AIO with poll and select.
I hoped that I can use normal IO and poll/select, will be the first test.
The boards that i have A20 with kernel 3.4.x and S905 with kernel 3.14.x use these custom kernels. Only these Kernels support all features.
But on all is mainline linux kernel running, with missing features.
I haven’t tested it yet.
Johns
Too bad linux 3.4.x didn’t support configs and linux 3-14.x didn’t support AIO with functionfs.
Johns
I sent you a mail to the address you provided when posting.
Got only an email from postmaster about this new post.
Hiring [url=https://contractorfinder.geappliances.com/contractors-wernersville-pa ]GE Appliances Contractors Wernersville PA[/url] was a game-changer after my home renovation project. From the initial consultation to the ultimate walkthrough, their professionalism and know-how were evident. The team was communicative, ensuring I was aware of at every stage. Their concentration to item was spotless, transforming my perception into fact with precision. Consideration a handful unexpected challenges, they adapted swiftly, keeping the estimate on track. The grade of undertaking exceeded my expectations, making the investment worthwhile.
I tried [url=https://greenrevolutioncbd.com/cbd-products/ ]best cbd products[/url] as a service to the beginning term last week, and I’m genuinely surprised by means of the results. I’ve struggled with hunger and incidental sleeplessness, and CBD seemed to offering a subtle, still efficient, quickness of stillness and relaxation. There was no ‘capital,’ perfectly a undisturbed easing of my concern symptoms and a more soporific night’s sleep. It tasted a atom crude, but that’s a miniature trade-off in search understanding more at peace. I’m looking step up to seeing how it helps in the desire run.
I tried https://greenrevolutioncbd.com/cbd-products/cbd-tinctures/ for the treatment of the in the first place term model week, and I’m genuinely surprised by means of the results. I’ve struggled with nervousness and occasional sleeplessness, and CBD seemed to offering a nice, despite everything efficient, quickness of composure and relaxation. There was no ‘capital,’ perfectly a undisturbed easing of my concern symptoms and a more sedative incessantly’s sleep. It tasted a atom crude, but that’s a miniature trade-off looking for belief more at peace. I’m looking step up to seeing how it helps in the desire run.
Hiring GE Appliances Contractors Lisle IL was a game-changer against my poorhouse renovation project. https://contractorfinder.geappliances.com/contractors-farmville-va From the beginning consultation to the final walkthrough, their professionalism and savvy were evident. The team was communicative, ensuring I was in the know at every stage. Their acclaim to delegate was spotless, transforming my delusion into actuality with precision. Teeth of a infrequent unexpected challenges, they adapted unexpectedly, keeping the concoct on track. The quality of work exceeded my expectations, making the investment worthwhile.