Switch to configfs_usb

Replaces legacy g_ffs driver

Bug: 27477999
Change-Id: If649292b71c6a11ed3b8cf20f613737aebd65a34
diff --git a/soc/fs1130/init.fs1130.rc b/soc/fs1130/init.fs1130.rc
index ff93d28..beacd9f 100644
--- a/soc/fs1130/init.fs1130.rc
+++ b/soc/fs1130/init.fs1130.rc
@@ -14,6 +14,8 @@
 # limitations under the License.
 #
 
+import init.usb.${ro.hardware}.rc
+
 on init
     # Android creates by-name disk links with the disk controller
     # in the generated path, so that the names pulled out of the GPT
@@ -23,8 +25,3 @@
 
 on fs
     mount_all /fstab.${ro.hardware}
-    mkdir /dev/usb-ffs 0770 shell shell
-    mkdir /dev/usb-ffs/adb 0770 shell shell
-    mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
-    write /sys/class/android_usb/android0/f_ffs/aliases adb
-    write /sys/class/android_usb/android0/iSerial ${ro.hardware}${ro.serialno}
diff --git a/soc/fs1130/init.usb.fs1130.rc b/soc/fs1130/init.usb.fs1130.rc
new file mode 100644
index 0000000..00375da
--- /dev/null
+++ b/soc/fs1130/init.usb.fs1130.rc
@@ -0,0 +1,42 @@
+#
+# Copyright 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+on boot
+    mkdir /dev/usb-ffs 0770 shell shell
+    mkdir /dev/usb-ffs/adb 0770 shell shell
+    mount configfs none /config
+    mkdir /config/usb_gadget/g1 0770 shell shell
+    write /config/usb_gadget/g1/idVendor 0x149a
+    mkdir /config/usb_gadget/g1/strings/0x409 0770
+    write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.hardware}${ro.serialno}
+    write /config/usb_gadget/g1/strings/0x409/manufacturer ${ro.product.manufacturer}
+    write /config/usb_gadget/g1/strings/0x409/product ${ro.product.model}
+    mkdir /config/usb_gadget/g1/functions/ffs.adb
+    mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell
+    mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell
+    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/ffs.adb
+    mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
+    setprop sys.usb.configfs 1
+    setprop sys.usb.controller "18120000.usb"
+
+on property:sys.usb.config=none && property:sys.usb.configfs=1
+    setprop sys.usb.ffs.ready 0
+
+on property:init.svc.adbd=stopped
+    setprop sys.usb.ffs.ready 0
+
+on property:sys.usb.config=adb && property:sys.usb.configfs=1
+    write /config/usb_gadget/g1/idProduct 0x0006
diff --git a/soc/fs1130/sepolicy/file.te b/soc/fs1130/sepolicy/file.te
new file mode 100644
index 0000000..485b666
--- /dev/null
+++ b/soc/fs1130/sepolicy/file.te
@@ -0,0 +1,2 @@
+# Configfs /config
+type configfs, fs_type;
diff --git a/soc/fs1130/sepolicy/genfs_contexts b/soc/fs1130/sepolicy/genfs_contexts
new file mode 100644
index 0000000..50c7cd7
--- /dev/null
+++ b/soc/fs1130/sepolicy/genfs_contexts
@@ -0,0 +1 @@
+genfscon configfs / u:object_r:configfs:s0
diff --git a/soc/fs1130/sepolicy/init.te b/soc/fs1130/sepolicy/init.te
new file mode 100644
index 0000000..d7a2e61
--- /dev/null
+++ b/soc/fs1130/sepolicy/init.te
@@ -0,0 +1,3 @@
+#============= init ==============
+allow init configfs:dir create_dir_perms;
+allow init configfs:{ file lnk_file } create_file_perms;
diff --git a/soc/fs1130/soc.kconf b/soc/fs1130/soc.kconf
index 006e6f6..f182709 100644
--- a/soc/fs1130/soc.kconf
+++ b/soc/fs1130/soc.kconf
@@ -57,8 +57,14 @@
 # [   89.274810] [<80c270f8>] nl80211_new_station+0x3b4/0x494
 # CONFIG_MAC80211_DEBUGFS is not set
 
-# Use generic functionsfs for adb gadget
-CONFIG_USB_FUNCTIONFS=y
-# CONFIG_USB_FUNCTIONFS_ETH is not set
-# CONFIG_USB_FUNCTIONFS_RNDIS is not set
-CONFIG_USB_FUNCTIONFS_GENERIC=y
+CONFIG_USB_CONFIGFS=y
+CONFIG_USB_CONFIGFS_ACM=y
+CONFIG_USB_CONFIGFS_F_ACC=y
+CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y
+CONFIG_USB_CONFIGFS_F_FS=y
+CONFIG_USB_CONFIGFS_F_MIDI=y
+CONFIG_USB_CONFIGFS_F_MTP=y
+CONFIG_USB_CONFIGFS_F_PTP=y
+CONFIG_USB_CONFIGFS_MASS_STORAGE=y
+CONFIG_USB_CONFIGFS_RNDIS=y
+CONFIG_USB_CONFIGFS_UEVENT=y
diff --git a/soc/fs1130/soc.mk b/soc/fs1130/soc.mk
index b248dbd..687bb31 100644
--- a/soc/fs1130/soc.mk
+++ b/soc/fs1130/soc.mk
@@ -29,10 +29,6 @@
 
 BOARD_KERNEL_CMDLINE := console=ttyS1,115200n8 earlycon=uart8250,mmio32,0x18101500,115200 androidboot.console=ttyS1 androidboot.hardware=fs1130 security=selinux androidboot.selinux=enforcing
 
-# Should be in bootloader DTB... firmware/android/
-BOARD_KERNEL_CMDLINE += androidboot.serialno=4567
-BOARD_KERNEL_CMDLINE += g_ffs.idVendor=0x18d1 g_ffs.idProduct=0xc141 g_ffs.iSerialNumber=4567
-
 TARGET_USERIMAGES_USE_EXT4 := true
 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
 BOARD_FLASH_BLOCK_SIZE := 131072
@@ -40,6 +36,8 @@
 PRODUCT_COPY_FILES += \
   $(LOCAL_PATH)/init.fs1130.rc:root/init.fs1130.rc \
   system/core/rootdir/init.usb.rc:root/init.usb.rc \
+  system/core/rootdir/init.usb.configfs.rc:root/init.usb.configfs.rc \
+  $(LOCAL_PATH)/init.usb.fs1130.rc:root/init.usb.fs1130.rc \
   system/core/rootdir/ueventd.rc:root/ueventd.rc \
   $(LOCAL_PATH)/ueventd.fs1130.rc:root/ueventd.fs1130.rc \