Gadget API. However I quickly discovered that this feature was not present in Ubuntu, even in the form of a kernel module in linux-extra. The only solution remaining was to rebuild the missing kernel module manually.
The main issue with a Linux kernel is that both the API and the ABI are not stable, meaning:
Now the proces was fairly simple.
linux-source
to have the kernel sources matching the currently installed kernel.This part is fairly easy.
dummy_hcd
kmod from these sources and,For a Makefile, you can retrieve the current version of the kernel from uname
plus some grep
.
Then extract and move the dummy_hcd.c
file from the current kernel source to the current folder.
dummy_hcd.c: /usr/src/linux-source-$(SVERSION)/linux-source-$(SVERSION).tar.bz2
tar -xjvf $^ linux-source-$(SVERSION)/drivers/usb/gadget/udc/dummy_hcd.c &&\
cp linux-source-$(SVERSION)/drivers/usb/gadget/udc/dummy_hcd.c $@
Following the basic example found in the documentation.
obj-m := dummy_hcd.o
KVERSION := $(shell uname -r)
all: dummy_hcd.c
$(MAKE) -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
$(MAKE) -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
First we should install DKMS.
Then add a dkms.conf
to ls /usr/src/dummy_hcd-0.1/
along with the Makefile we previously created.
PACKAGE_NAME="dummy_hcd"
PACKAGE_VERSION="0.1"
CLEAN="make clean"
MAKE[0]="make all KVERSION=$kernelver"
BUILT_MODULE_NAME[0]="dummy_hcd"
DEST_MODULE_LOCATION[0]="/extra"
AUTOINSTALL="yes"
We can then add our DKMS module to be built and added to our kernel modules.
Finally, we can test our module is working by loading it and mounting the Gadget Filesystem.
The complete project is published on Github.