[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/meta/meta-mediatek-mt2731/recipes-devtools/android-tools/android-tools-conf/android-gadget-setup b/meta/meta-mediatek-mt2731/recipes-devtools/android-tools/android-tools-conf/android-gadget-setup
new file mode 100755
index 0000000..a719804
--- /dev/null
+++ b/meta/meta-mediatek-mt2731/recipes-devtools/android-tools/android-tools-conf/android-gadget-setup
@@ -0,0 +1,92 @@
+#!/bin/busybox sh
+
+if [ "$1" == "pre" ]; then
+    echo "=== Initial: USB Configuration Start ===" > /dev/kmsg
+
+    if [ -e "/dev/usb-ffs" ] ; then
+        echo "=== Bypass Pre Configuration ===" > /dev/kmsg
+    else # first boot
+        mkdir -p /dev/usb-ffs
+        mkdir -p /dev/usb-ffs/adb
+        mount none /sys/kernel/config -t configfs
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ffs.adb
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/rndis.gs4
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ncm.f0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/ecm.f0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/eem.f0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs1
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs2
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/acm.gs3
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_modem.gs0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_ets.gs0
+        mkdir -p /sys/kernel/config/usb_gadget/g1/functions/via_atc.gs0
+        mount adb /dev/usb-ffs/adb -t functionfs -o uid=2000,gid=2000
+    fi
+
+elif [ "$1" == "post" ];then
+
+    echo 0x0e8d > /sys/kernel/config/usb_gadget/g1/idVendor
+    echo 0x0223 > /sys/kernel/config/usb_gadget/g1/bcdDevice
+    echo 0x0200 > /sys/kernel/config/usb_gadget/g1/bcdUSB
+    mkdir -p /sys/kernel/config/usb_gadget/g1/strings/0x409
+
+    if [ "$(cat /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber)" == "" ]; then
+        if [[ "$(cat /etc/hostname)" == "auto2731evb-ivt-vp1" || "$(cat /etc/hostname)" == "auto2731evb-ivt-vp2" ]]; then
+            echo "MT-96533493F01B518C" > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber
+        else
+            echo 0123456789ABCDEF > /sys/kernel/config/usb_gadget/g1/strings/0x409/serialnumber
+        fi
+    else
+        echo "=== usb serial number exist, keep it ===" > /dev/kmsg
+    fi
+
+    echo MediaTek > /sys/kernel/config/usb_gadget/g1/strings/0x409/manufacturer
+    echo auto2731-ivt > /sys/kernel/config/usb_gadget/g1/strings/0x409/product
+
+    mkdir -p /sys/kernel/config/usb_gadget/g1/configs/b.1
+    mkdir -p /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409
+    echo 500 > /sys/kernel/config/usb_gadget/g1/configs/b.1/MaxPower
+
+    if [ -n "$(cat /proc/boot_mode | grep META)" ] ; then # META mode: META_BOOT_SKIP_PRELOADER
+
+        # ADB + CDC-ACM*2 (META mode)
+        #setprop sys.usb.config adb,meta,elt
+        #################### START ####################
+        sleep 1
+        echo meta_elt_adb > /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409/configuration
+        echo 0x2040 > /sys/kernel/config/usb_gadget/g1/idProduct
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/mass_storage.usb0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f1
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/b.1/f2
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f3
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs3 /sys/kernel/config/usb_gadget/g1/configs/b.1/f4
+        echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC
+        #################### END ####################
+        sleep 1
+        echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC
+
+    else # Normal mode
+
+        # ADB + CDC-ACM*3 (normal mode)
+        #setprop sys.usb.config adb,acm
+        #################### START ####################
+        sleep 1
+        echo gs1gs3_dual_acm > /sys/kernel/config/usb_gadget/g1/configs/b.1/strings/0x409/configuration
+        echo 0x202f > /sys/kernel/config/usb_gadget/g1/idProduct
+        echo 1 > /sys/devices/platform/soc/mt_usb/saving
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/ffs.adb /sys/kernel/config/usb_gadget/g1/configs/b.1/f1
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs0 /sys/kernel/config/usb_gadget/g1/configs/b.1/f2
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs1 /sys/kernel/config/usb_gadget/g1/configs/b.1/f3
+        ln -sf /sys/kernel/config/usb_gadget/g1/functions/acm.gs3 /sys/kernel/config/usb_gadget/g1/configs/b.1/f4
+        #################### END ####################
+        sleep 1
+        echo musb-hdrc > /sys/kernel/config/usb_gadget/g1/UDC
+    fi
+
+    if [ -e "/proc/bootprof" ] ; then
+        echo usb_active > /proc/bootprof
+    fi
+
+    echo "=== Initial: USB Configuration End ===" > /dev/kmsg
+fi