modern usb gadget with custom usb functions
TRANSCRIPT
![Page 1: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/1.jpg)
Modern USB Gadget with Custom USB Functions...
...and its integration with systemd
Andrzej Pietrasiewicz <[email protected]> ELC 2019
![Page 2: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/2.jpg)
2
USB Device user?
A Linux machine connected to a PC
![Page 3: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/3.jpg)
3
Overview
● Composition and components+ your own USB functionality
● Tools
● systemd integration+ your own USB functionality
![Page 4: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/4.jpg)
4
Composition and components
![Page 5: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/5.jpg)
5
Endpoints
● Control
● Bulk
● Interrupt
● Isochronous
USB HOST
USB DEVICE
0 0 1 1 2 2
Data for “1”
![Page 6: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/6.jpg)
6
Interface
● Collection of endpoints for a particular purpose
● Implemented as “USB function” in Linux kernel
![Page 7: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/7.jpg)
7
Configuration
● Collection of 1+ interface(s)
● Device contains 1+ configuration(s)
– Only 1 active at a time
– Rarely > 1
![Page 8: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/8.jpg)
8
FunctionFS
● A USB function
● A filesystem with ep0 and epX….
![Page 9: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/9.jpg)
9
Theoretical # combinations
(201 )+(202 )+(203 )+...+(2020)=ALOT
![Page 10: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/10.jpg)
10
Tools
![Page 11: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/11.jpg)
11
Configfs
● /sys/kernel/config/usb_gadget
● mkdir, echo, ln -s, rmdir
![Page 12: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/12.jpg)
12
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 13: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/13.jpg)
13
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 14: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/14.jpg)
14
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 15: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/15.jpg)
15
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 16: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/16.jpg)
16
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 17: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/17.jpg)
17
mkdir g1cd g1
echo 0x1d6b > idVendorecho 0x104 > idProduct
mkdir strings/0x409 # US English, others rarely seenecho "Collabora" > strings/0x409/manufacturerecho "ECM" > strings/0x409/product
mkdir configs/c.1 # dot and number mandatory
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0/ configs/c.1/
# bind!# ls /sys/class/udc to see available UDCsecho 12480000.hsotg > UDC
![Page 18: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/18.jpg)
18
gt
● github.com/kopasiak/gt
● github.com/libusbgx/libusbgx.git
● gadget “schemes”
![Page 19: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/19.jpg)
19
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 20: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/20.jpg)
20
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 21: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/21.jpg)
21
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 22: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/22.jpg)
22
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 23: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/23.jpg)
23
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 24: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/24.jpg)
24
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "ECM"; });functions : { ecm_usb0 : { instance = "usb0"; type = "ecm"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ecm.usb0"; function = "ecm_usb0"; } ); } );
![Page 25: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/25.jpg)
25
systemd integration
![Page 26: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/26.jpg)
26
systemd
● Various units
– service, mount, target, socket, ...
● Tracked dependencies
● High parallelization
● Lazy initialization (socket units)
![Page 27: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/27.jpg)
27
The “glue layer”
● usb-gadget.target
● udev event
![Page 28: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/28.jpg)
28
The “glue layer”
● usb-gadget.target
● udev event
[Unit] Description=Hardware activated USB gadget Documentation=man:systemd.special(7)
![Page 29: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/29.jpg)
29
The “glue layer”
● usb-gadget.target
● udev event
[Unit] Description=Hardware activated USB gadget Documentation=man:systemd.special(7)
SUBSYSTEM=="udc", ACTION=="add", TAG+="systemd", \ENV{SYSTEMD_WANTS}+="usb-gadget.target"
![Page 30: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/30.jpg)
30
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
![Page 31: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/31.jpg)
31
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
![Page 32: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/32.jpg)
32
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
![Page 33: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/33.jpg)
33
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
![Page 34: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/34.jpg)
34
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
![Page 35: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/35.jpg)
35
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
systemctl [en|dis]able usb-gadget.service
![Page 36: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/36.jpg)
36
Service unit[Unit]Description=Load USB gadget scheme for ecmRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load ecm.scheme ecmRemainAfterExit=yesExecStop=/bin/gt rm -rf ecmType=simple
[Install]WantedBy=usb-gadget.target
systemctl [en|dis]able usb-gadget.service
![Page 37: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/37.jpg)
37
Service unit templatized[Unit]Description=Load USB gadget scheme for %iRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load %i.scheme %iRemainAfterExit=yesExecStop=/bin/gt rm -rf %iType=simple
[Install]WantedBy=usb-gadget.target
![Page 38: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/38.jpg)
38
Service unit templatized[Unit]Description=Load USB gadget scheme for %iRequires=sys-kernel-config.mountAfter=sys-kernel-config.mountDefaultDependencies=no
[Service]ExecStart=/bin/gt load %i.scheme %iRemainAfterExit=yesExecStop=/bin/gt rm -rf %iType=simple
[Install]WantedBy=usb-gadget.target
systemctl [en|dis]able [email protected]
![Page 39: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/39.jpg)
39
systemd integrationYour own USB function
![Page 40: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/40.jpg)
40
FunctionFS vs systemd
● Gadget scheme
● Service unit (create gadget, gt load -o)
● Mount unit (FunctionFS instance)
● Socket unit (start its service unit, enable the gadget)
● Service unit (spawn userspace daemon)
![Page 41: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/41.jpg)
41
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "MTP Gadget"; });functions : { ffs_mtp : { instance = "mtp"; type = "ffs"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ffs.mtp"; function = "ffs_mtp"; } ); } );
![Page 42: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/42.jpg)
42
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "MTP Gadget"; });functions : { ffs_mtp : { instance = "mtp"; type = "ffs"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ffs.mtp"; function = "ffs_mtp"; } ); } );
![Page 43: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/43.jpg)
43
attrs : { idVendor = 0x1D6B; idProduct = 0x104;};strings = ( { lang = 0x409; manufacturer = "Collabora"; product = "MTP Gadget"; });functions : { ffs_mtp : { instance = "mtp"; type = "ffs"; };};
configs = ( { id = 1; name = "c"; functions = ( { name = "ffs.mtp"; function = "ffs_mtp"; } ); } );
![Page 44: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/44.jpg)
44
Mount unit[Unit]Description=FunctionFS instance for ffs_mtpRequires=usb-gadget-ffs@ffs_mtp.serviceAfter=usb-gadget-ffs@ffs_mtp.serviceBefore=ffs@ffs_mtp.socket
[Mount]What=mtpWhere=/run/ffs_mtpType=functionfsOptions=defaultsTimeoutSec=5
![Page 45: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/45.jpg)
45
Mount unit[Unit]Description=FunctionFS instance for ffs_mtpRequires=usb-gadget-ffs@ffs_mtp.serviceAfter=usb-gadget-ffs@ffs_mtp.serviceBefore=ffs@ffs_mtp.socket
[Mount]What=mtpWhere=/run/ffs_mtpType=functionfsOptions=defaultsTimeoutSec=5
![Page 46: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/46.jpg)
46
Mount unit[Unit]Description=FunctionFS instance for ffs_mtpRequires=usb-gadget-ffs@ffs_mtp.serviceAfter=usb-gadget-ffs@ffs_mtp.serviceBefore=ffs@ffs_mtp.socket
[Mount]What=mtpWhere=/run/ffs_mtpType=functionfsOptions=defaultsTimeoutSec=5
![Page 47: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/47.jpg)
47
Mount unit[Unit]Description=FunctionFS instance for ffs_mtpRequires=usb-gadget-ffs@ffs_mtp.serviceAfter=usb-gadget-ffs@ffs_mtp.serviceBefore=ffs@ffs_mtp.socket
[Mount]What=mtpWhere=/run/ffs_mtpType=functionfsOptions=defaultsTimeoutSec=5
![Page 48: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/48.jpg)
48
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 49: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/49.jpg)
49
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 50: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/50.jpg)
50
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 51: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/51.jpg)
51
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 52: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/52.jpg)
52
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 53: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/53.jpg)
53
Socket unit[Unit]Description=USB FunctionFS socket for %iRequires=run-%i.mountAfter=run-%i.mountDefaultDependencies=no
[Socket]ListenUSBFunction=/run/%iService=%i.serviceExecStartPost=/bin/gt enable %iTriggerLimitIntervalSec=0
[Install]WantedBy=usb-gadget.target
![Page 54: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/54.jpg)
54
Service unit
[Unit]Description=MTP responderStartLimitIntervalSec=0
[Service]Type=simpleExecStart=/usr/bin/cmtp-responderUSBFunctionDescriptors=/etc/cmtp-responder/descsUSBFunctionStrings=/etc/cmtp-responder/strsKillMode=processRestartSec=3Restart=on-failure
![Page 55: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/55.jpg)
55
Service unit
[Unit]Description=MTP responderStartLimitIntervalSec=0
[Service]Type=simpleExecStart=/usr/bin/cmtp-responderUSBFunctionDescriptors=/etc/cmtp-responder/descsUSBFunctionStrings=/etc/cmtp-responder/strsKillMode=processRestartSec=3Restart=on-failure
![Page 56: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/56.jpg)
56
Service unit
[Unit]Description=MTP responderStartLimitIntervalSec=0
[Service]Type=simpleExecStart=/usr/bin/cmtp-responderUSBFunctionDescriptors=/etc/cmtp-responder/descsUSBFunctionStrings=/etc/cmtp-responder/strsKillMode=processRestartSec=3Restart=on-failure
![Page 57: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/57.jpg)
57
Service unit
[Unit]Description=MTP responderStartLimitIntervalSec=0
[Service]Type=simpleExecStart=/usr/bin/cmtp-responderUSBFunctionDescriptors=/etc/cmtp-responder/descsUSBFunctionStrings=/etc/cmtp-responder/strsKillMode=processRestartSec=3Restart=on-failure
include/uapi/linux/usb/functionfs.h
![Page 58: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/58.jpg)
58
Descriptors and strings
● github.com/kopasiak/gt/pull/8
● Declarative config → blob
– USBFunctionDescriptors, USBFunctionStrings
![Page 59: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/59.jpg)
59
Demo
![Page 60: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/60.jpg)
60
MTP Device
● github.com/cmtp-responder/cmtp-responder.git
● Odroid U2
![Page 61: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/61.jpg)
61
Summary
● Composition and components+ your own USB functionality
● Tools
● systemd integration+ your own USB functionality
![Page 62: Modern USB Gadget with Custom USB Functions](https://reader030.vdocuments.net/reader030/viewer/2022012522/61961fa6cbea7a7a6b18ee70/html5/thumbnails/62.jpg)
62
Thank you!