Add minimal USB init RC for QMAA
To facilitate early bringup on pre-silicon platforms, introduce
init.qti.usb.qmaa.rc which is a stripped-down init script that
performs only the necessary configuration to bring up ADB over USB.
This avoids unnecessary dependencies on Android init and other
framework services which may not be stable. Note the ADB-only
composition is supported at this time.
This is generally enabled when the global TARGET_USES_QMAA flag
is set to true. It can be overridden (that is, enable the full
USB scripts, HALs, etc) when TARGET_USES_QMAA_OVERRIDE_USB is also
set to true.
Change-Id: Idd39efafdbaaa8a9f407abc04b4270fdfa15960e
diff --git a/etc/Android.bp b/etc/Android.bp
index e90b151..fbb2503 100644
--- a/etc/Android.bp
+++ b/etc/Android.bp
@@ -23,3 +23,10 @@
src: "init.qti.usb.debug.sh",
vendor: true,
}
+
+prebuilt_etc {
+ name: "init.qti.usb.qmaa.rc",
+ src: "init.qti.usb.qmaa.rc",
+ vendor: true,
+ sub_dir: "init",
+}
diff --git a/etc/init.qti.usb.qmaa.rc b/etc/init.qti.usb.qmaa.rc
new file mode 100644
index 0000000..c56dee4
--- /dev/null
+++ b/etc/init.qti.usb.qmaa.rc
@@ -0,0 +1,32 @@
+# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-3-Clause-Clear
+
+on init
+ mount configfs none /config
+ mkdir /config/usb_gadget/g1 0770
+ mkdir /config/usb_gadget/g1/strings/0x409 0770
+ write /config/usb_gadget/g1/bcdUSB 0x0200
+ write /config/usb_gadget/g1/os_desc/use 1
+ write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
+ write /config/usb_gadget/g1/strings/0x409/manufacturer ${ro.product.manufacturer}
+ write /config/usb_gadget/g1/strings/0x409/product ${ro.product.name}
+ mkdir /config/usb_gadget/g1/functions/ffs.adb
+ mkdir /config/usb_gadget/g1/configs/b.1 0770
+ mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770
+ write /config/usb_gadget/g1/configs/b.1/MaxPower 900
+ write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1
+ write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100"
+ mkdir /dev/usb-ffs 0775 shell system
+ mkdir /dev/usb-ffs/adb 0770 shell system
+ mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=1000,rmode=0770,fmode=0660
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
+ symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
+ write /config/usb_gadget/g1/idVendor 0x18d1
+ write /config/usb_gadget/g1/idProduct 0x4ee7
+ symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
+ start adbd
+ setprop sys.usb.configfs -1
+
+on property:sys.usb.ffs.ready=1
+ write /config/usb_gadget/g1/UDC ${vendor.usb.controller}
+ setprop sys.usb.state adb
diff --git a/vendor_product.mk b/vendor_product.mk
index 82df4e2..e3ced91 100644
--- a/vendor_product.mk
+++ b/vendor_product.mk
@@ -1,24 +1,3 @@
-# USB init scripts
-PRODUCT_PACKAGES += init.qcom.usb.rc init.qcom.usb.sh
-
-# additional debugging on userdebug/eng builds
-ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
- PRODUCT_PACKAGES += init.qti.usb.debug.sh
- PRODUCT_PACKAGES += init.qti.usb.debug.rc
-endif
-
-ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.9 4.14))
- PRODUCT_PACKAGES += android.hardware.usb@1.2-service-qti
-endif
-
-ifneq ($(filter taro kalama,$(TARGET_BOARD_PLATFORM)),)
- PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=1
- PRODUCT_PACKAGES += android.hardware.usb.gadget@1.1-service-qti
- PRODUCT_PACKAGES += usb_compositions.conf
-else
- PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=0
-endif
-
#
# Default property overrides for various function configurations
# These can be further overridden at runtime in init*.rc files as needed
@@ -49,3 +28,37 @@
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_ffs_mtp=0
endif
+ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.9 4.14))
+ PRODUCT_PACKAGES += android.hardware.usb@1.2-service-qti
+endif
+
+USB_USES_QMAA = $(TARGET_USES_QMAA)
+ifeq ($(TARGET_USES_QMAA_OVERRIDE_USB),true)
+ USB_USES_QMAA = false
+endif
+
+# USB init scripts
+ifeq ($(USB_USES_QMAA),true)
+ PRODUCT_PACKAGES += init.qti.usb.qmaa.rc
+else
+ PRODUCT_PACKAGES += init.qcom.usb.rc init.qcom.usb.sh
+
+ #
+ # USB Gadget HAL is enabled on newer targets and takes the place
+ # of the init-based configfs rules for setting USB compositions
+ #
+ ifneq ($(filter taro kalama,$(TARGET_BOARD_PLATFORM)),)
+ PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=1
+ PRODUCT_PACKAGES += android.hardware.usb.gadget@1.1-service-qti
+ PRODUCT_PACKAGES += usb_compositions.conf
+ else
+ PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=0
+ endif
+
+endif
+
+# additional debugging on userdebug/eng builds
+ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
+ PRODUCT_PACKAGES += init.qti.usb.debug.sh
+ PRODUCT_PACKAGES += init.qti.usb.debug.rc
+endif