rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/bin/busybox sh |
| 2 | |
| 3 | if [ "$1" == "pre" ]; then |
| 4 | echo "=== Initial: USB Configuration Start ===" > /dev/kmsg |
| 5 | |
| 6 | if [ -e "/dev/usb-ffs" ] ; then |
| 7 | echo "=== Bypass Pre Configuration ===" > /dev/kmsg |
| 8 | else # first boot |
| 9 | mkdir -p /dev/usb-ffs |
| 10 | mkdir -p /dev/usb-ffs/adb |
| 11 | mount none /sys/kernel/config -t configfs |
| 12 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ffs.adb |
| 13 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4 |
| 14 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ncm.f0 |
| 15 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ecm.f0 |
| 16 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/eem.f0 |
| 17 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 |
| 18 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 |
| 19 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs1 |
| 20 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs2 |
| 21 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs3 |
| 22 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_modem.gs0 |
| 23 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_ets.gs0 |
| 24 | mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_atc.gs0 |
| 25 | mount adb /dev/usb-ffs/adb -t functionfs -o uid=2000,gid=2000 |
| 26 | fi |
| 27 | |
| 28 | elif [ "$1" == "post" ];then |
| 29 | |
| 30 | echo 0x0e8d > /sys/kernel/config/usb_gadget/g1/idVendor |
| 31 | echo 0x0223 > /sys/kernel/config/usb_gadget/g1/bcdDevice |
| 32 | echo 0x0200 > /sys/kernel/config/usb_gadget/g1/bcdUSB |
| 33 | mkdir -p /sys/kernel/config/usb_gadget/g1/strings/0x409 |
| 34 | |
| 35 | if [ "$(cat /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber)" == "" ]; then |
| 36 | if [[ "$(cat /etc/hostname)" == "auto2731evb-ivt-vp1" || "$(cat /etc/hostname)" == "auto2731evb-ivt-vp2" ]]; then |
| 37 | echo "MT-96533493F01B518C" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber |
| 38 | else |
| 39 | echo 0123456789ABCDEF > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber |
| 40 | fi |
| 41 | else |
| 42 | echo "=== usb serial number exist, keep it ===" > /dev/kmsg |
| 43 | fi |
| 44 | |
| 45 | echo MediaTek > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer |
| 46 | echo auto2731-ivt > /sys/kernel/config/usb_gadget/g1/strings/0x409/product |
| 47 | |
| 48 | mkdir -p /sys/kernel/config/usb_gadget/g1/configs/b.1 |
| 49 | mkdir -p /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409 |
| 50 | echo 500 > /sys/kernel/config/usb_gadget/g1/configs/b.1/MaxPower |
| 51 | |
| 52 | if [ -n "$(cat /proc/boot_mode | grep META)" ] ; then # META mode: META_BOOT_SKIP_PRELOADER |
| 53 | |
| 54 | # ADB + CDC-ACM*2 (META mode) |
| 55 | #setprop sys.usb.config adb,meta,elt |
| 56 | #################### START #################### |
| 57 | sleep 1 |
| 58 | echo meta_elt_adb > /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409/configuration |
| 59 | echo 0x2040 > /sys/kernel/config/usb_gadget/g1/idProduct |
| 60 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f1 |
| 61 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/b.1/f2 |
| 62 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f3 |
| 63 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs3 /sys/kernel/config/usb_gadget/g1/configs/b.1/f4 |
| 64 | echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC |
| 65 | #################### END #################### |
| 66 | sleep 1 |
| 67 | echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC |
| 68 | |
| 69 | else # Normal mode |
| 70 | |
| 71 | # ADB + CDC-ACM*3 (normal mode) |
| 72 | #setprop sys.usb.config adb,acm |
| 73 | #################### START #################### |
| 74 | sleep 1 |
| 75 | echo gs1gs3_dual_acm > /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409/configuration |
| 76 | echo 0x202f > /sys/kernel/config/usb_gadget/g1/idProduct |
| 77 | echo 1 > /sys/devices/platform/soc/mt_usb/saving |
| 78 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/b.1/f1 |
| 79 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f2 |
| 80 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs1 /sys/kernel/config/usb_gadget/g1/configs/b.1/f3 |
| 81 | ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs3 /sys/kernel/config/usb_gadget/g1/configs/b.1/f4 |
| 82 | #################### END #################### |
| 83 | sleep 1 |
| 84 | echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC |
| 85 | fi |
| 86 | |
| 87 | if [ -e "/proc/bootprof" ] ; then |
| 88 | echo usb_active > /proc/bootprof |
| 89 | fi |
| 90 | |
| 91 | echo "=== Initial: USB Configuration End ===" > /dev/kmsg |
| 92 | fi |