Skip to content

Instantly share code, notes, and snippets.

Forked from geekman/myusbgadget
Last active June 1, 2020 14:39
What would you like to do?
Pi Zero multiple USB gadgets minimal example
#!/bin/bash -e
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir g && cd g
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB 2.0
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol
mkdir -p strings/0x409
echo "deadbeef00115599" > strings/0x409/serialnumber
echo "irq5 labs" > strings/0x409/manufacturer
echo "Pi Zero Gadget" > strings/0x409/product
# OS descriptors
echo 1 > os_desc/use
echo 0xcd > os_desc/b_vendor_code
echo MSFT100 > os_desc/qw_sign
mkdir -p configs/c.1
echo 250 > configs/c.1/MaxPower
ln -s configs/c.1 os_desc
#serial device
mkdir -p functions/acm.usb0 # serial
ln -s functions/acm.usb0 configs/c.1/
#RNDIS device
#mkdir -p functions/rndis.usb0 # network
#echo RNDIS > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
#echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
#ln -s functions/rndis.usb0 configs/c.1/
#Mass Storage Device
mkdir -p functions/mass_storage.usb0
echo 1 > functions/mass_storage.usb0/stall
echo 0 > functions/mass_storage.usb0/lun.0/cdrom
echo 0 > functions/mass_storage.usb0/lun.0/ro
echo 0 > functions/mass_storage.usb0/lun.0/nofua
echo /mnt/usbdisk.img > functions/mass_storage.usb0/file
ln -s functions/mass_storage.usb0 configs/c.1/
udevadm settle -t 5 || :
ls /sys/class/udc/ > UDC
# /usr/lib/systemd/system/myusbgadget.service
Description=My USB gadget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment