Advertisement
zefie

Pi0 USB Multi-Gadget config (serial+ethernet)

Jul 26th, 2018
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ID_VENDOR="0x1d6b"
  4. ID_PRODUCT="0x0104"
  5.  
  6. SERIAL="$(grep Serial /proc/cpuinfo | sed 's/Serial\s*: 0000\(\w*\)/\1/')"
  7. MAC="$(echo ${SERIAL} | sed 's/\(\w\w\)/:\1/g' | cut -b 2-)"
  8. MAC_HOST="12$(echo ${MAC} | cut -b 3-)"
  9. MAC_DEV="02$(echo ${MAC} | cut -b 3-)"
  10. g="/sys/kernel/config/usb_gadget/g"
  11.  
  12. modprobe libcomposite
  13.  
  14. write_config() {
  15.     if [ ! -d "${g}/$(dirname $2)" ]; then
  16.         mkdir -p ${g}/$(dirname $2)
  17.     fi
  18.     if [ -f "${g}/$2" ]; then
  19.         if [ "$(cat ${g}/$2)" != "$1" ]; then
  20.             echo "$1" > "${g}/$2"
  21.         fi
  22.     else
  23.         echo "$1" > "${g}/$2"
  24.     fi
  25. }
  26.  
  27. write_config "" UDC
  28.  
  29. write_config ${ID_VENDOR} idVendor  # Linux Foundation
  30. write_config ${ID_PRODUCT} idProduct # Multifunction Composite Gadget
  31. write_config 0x0100 bcdDevice
  32. write_config 0x0200 bcdUSB
  33. write_config 0xEF bDeviceClass
  34. write_config 0x02 bDeviceSubClass
  35. write_config 0x01 bDeviceProtocol
  36.  
  37. mkdir -p ${g}/strings/0x409
  38. write_config "${SERIAL}" strings/0x409/serialnumber
  39. write_config "Zefie Networks" strings/0x409/manufacturer
  40. write_config "Raspberry Pi Zero Gadget" strings/0x409/product
  41.  
  42. write_config 1 os_desc/use
  43. write_config 0xcd os_desc/b_vendor_code
  44. write_config MSFT100 os_desc/qw_sign
  45.  
  46. mkdir -p ${g}/functions/acm.GS0  # serial
  47. mkdir -p ${g}/functions/rndis.usb0 # network
  48.  
  49. write_config $MAC_HOST functions/rndis.usb0/host_addr
  50. write_config $MAC_DEV functions/rndis.usb0/dev_addr
  51. write_config RNDIS functions/rndis.usb0/os_desc/interface.rndis/compatible_id
  52. write_config 5162001 functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
  53.  
  54. write_config 250 configs/c.1/MaxPower
  55. ln -s ${g}/configs/c.1 ${g}/os_desc
  56. ln -s ${g}/functions/rndis.usb0 ${g}/configs/c.1/
  57. ln -s ${g}/functions/acm.GS0 ${g}/configs/c.1/
  58.  
  59. udevadm settle -t 5 || :
  60. write_config $(ls -1 /sys/class/udc) UDC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement