@@ -4,37 +4,45 @@ configfs_init()
44{
55 modprobe libcomposite
66
7+ mkdir -p " /sys/kernel/config/usb_gadget/radxa-otgutils"
8+ pushd " /sys/kernel/config/usb_gadget/radxa-otgutils"
9+
10+ echo " 0x1d6b" > " idVendor" # Linux Foundation
11+ echo " 0x0104" > " idProduct" # Multifunction Composite Gadget
12+ echo " 0x0100" > " bcdDevice" # v1.0.0
13+ echo " 0x0200" > " bcdUSB" # USB 2.0
14+ echo " 0xEF" > " bDeviceClass"
15+ echo " 0x02" > " bDeviceSubClass"
16+ echo " 0x01" > " bDeviceProtocol"
17+
18+ mkdir -p " strings/0x409"
19+ echo " 0123456789ABCDEF" > " strings/0x409/serialnumber"
20+ echo " Radxa" > " strings/0x409/manufacturer"
21+ echo " OTG Utils" > " strings/0x409/product"
22+
23+ mkdir -p " configs/r.1/strings/0x409"
24+ echo " 500" > " configs/r.1/MaxPower"
25+ echo " adb" > " configs/r.1/strings/0x409/configuration"
26+
27+ popd
28+ }
29+
30+ function_init ()
31+ {
732 case " $MODE " in
833 adbd)
9- local VENDOR=" 0x18d1"
10- local PRODUCT=" 0x0001"
34+ local GADGET=" ffs.adb"
1135 ;;
1236 usbnet)
13- local VENDOR=" 0x1d6b"
14- local PRODUCT=" 0x0104"
37+ local GADGET=" ecm.usb0"
1538 ;;
1639 esac
1740
18- mkdir -p " /sys/kernel/config/usb_gadget/radxa-$MODE "
19- chmod 0770 " /sys/kernel/config/usb_gadget/radxa-$MODE "
20- echo " $VENDOR " > " /sys/kernel/config/usb_gadget/radxa-$MODE /idVendor"
21- echo " $PRODUCT " > " /sys/kernel/config/usb_gadget/radxa-$MODE /idProduct"
22- mkdir -p " /sys/kernel/config/usb_gadget/radxa-$MODE /strings/0x409"
23- chmod 0770 " /sys/kernel/config/usb_gadget/radxa-$MODE /strings/0x409"
24- echo " Radxa" > " /sys/kernel/config/usb_gadget/radxa-$MODE /strings/0x409/manufacturer"
25- echo " $MODE " > " /sys/kernel/config/usb_gadget/radxa-$MODE /strings/0x409/product"
26- mkdir -p " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1"
27- chmod 0770 " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1"
28-
29- case " $MODE " in
30- adbd)
31- echo " 0123456789ABCDEF" > " /sys/kernel/config/usb_gadget/radxa-$MODE /strings/0x409/serialnumber"
32- mkdir -p " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1/strings/0x409"
33- chmod 0770 " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1/strings/0x409"
34- echo " 500" > " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1/MaxPower"
35- echo " adb" > " /sys/kernel/config/usb_gadget/radxa-$MODE /configs/r.1/strings/0x409/configuration"
36- ;;
37- esac
41+ if [ ! -e " /sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1/$GADGET " ];
42+ then
43+ mkdir -p " /sys/kernel/config/usb_gadget/radxa-otgutils/functions/$GADGET "
44+ ln -s " /sys/kernel/config/usb_gadget/radxa-otgutils/functions/$GADGET " " /sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1"
45+ fi
3846}
3947
4048function_stop ()
@@ -79,12 +87,17 @@ start()
7987 echo " No USB Device Controller was detected. Did you set your OTG port to host mode?"
8088 exit 1
8189 fi
82- echo " $UDC " > " /sys/kernel/config/usb_gadget/radxa-$MODE /UDC"
90+ echo " $UDC " > " /sys/kernel/config/usb_gadget/radxa-otgutils /UDC"
8391}
8492
8593stop ()
8694{
87- echo " none" > " /sys/kernel/config/usb_gadget/radxa-$MODE /UDC"
95+ function_stop
96+ if [[ ! -e " /sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1/" ]] || \
97+ (( $(find / sys/ kernel/ config/ usb_gadget/ radxa- otgutils/ configs/ r.1 /* - maxdepth 0 - type d | wc - l) == 0 ))
98+ then
99+ echo " none" > " /sys/kernel/config/usb_gadget/radxa-otgutils/UDC"
100+ fi
88101 case " $MODE " in
89102 adbd)
90103 start-stop-daemon --stop --oknodo --pidfile /var/run/adbd.pid --retry 5
0 commit comments