Created
July 13, 2018 10:45
-
-
Save eballetbo/1bed3ae3165a26e6a47b66074ee7cb0e to your computer and use it in GitHub Desktop.
Create a CDC ECM Ethernet device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# mount configfs | |
mount -t configfs none /sys/kernel/config | |
# load libcomposite module | |
modprobe libcomposite | |
# create a gadget | |
mkdir /sys/kernel/config/usb_gadget/g1 | |
# cd to its configfs node | |
cd /sys/kernel/config/usb_gadget/g1 | |
# configure it (vid/pid can be anything if USB Class is used for driver compat) | |
echo 0xabcd > idVendor | |
echo 0x1234 > idProduct | |
# configure its serial/mfg/product | |
mkdir strings/0x409 | |
echo myserial > strings/0x409/serialnumber | |
echo mymfg > strings/0x409/manufacturer | |
echo myproduct > strings/0x409/product | |
# create a config | |
mkdir configs/c.1 | |
# configure it with attributes if needed | |
echo 120 > configs/c.1/MaxPower | |
# ensure function is loaded | |
modprobe usb_f_ecm | |
# create the function (name must match a usb_f_<name> module such as 'ecm') | |
mkdir functions/ecm.0 | |
# associate function with config | |
ln -s functions/ecm.0 configs/c.1 | |
# enable gadget by binding it to a UDC from /sys/class/udc | |
echo 0000:01:00.0 > UDC | |
# to unbind it: echo "" UDC; sleep 1; rm -rf /sys/kernel/config/usb_gadget/g1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment