Skip to content

Commit

Permalink
USB接続の問題を解消
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseos authored May 23, 2024
1 parent 354a760 commit ecf8354
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 22 deletions.
287 changes: 265 additions & 22 deletions recovery/root/init.recovery.mt8168.rc
Original file line number Diff line number Diff line change
@@ -1,42 +1,285 @@
on early-init
wait /dev/.coldboot_done 1000

on init

on fs
setprop vendor.usb.vid "0x18D1"
mkdir /config
mount configfs none /config
mkdir /dev/usb-ffs 0770 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mkdir /config/usb_gadget/g1 0770 shell shell
write /config/usb_gadget/g1/idVendor 0x18d1
write /config/usb_gadget/g1/idProduct 0xd001
write /config/usb_gadget/g1/idVendor ${vendor.usb.vid}
write /config/usb_gadget/g1/bcdDevice 0x0223
write /config/usb_gadget/g1/bcdUSB 0x0200
mkdir /config/usb_gadget/g1/strings/0x409 0770
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.model}
mkdir /config/usb_gadget/g1/configs/b.1 0777 shell shell
mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell
mkdir /config/usb_gadget/g1/functions/accessory.gs2
mkdir /config/usb_gadget/g1/functions/audio_source.gs3
mkdir /config/usb_gadget/g1/functions/ffs.adb
mkdir /config/usb_gadget/g1/functions/mtp.gs0
write /config/usb_gadget/g1/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "MTP"
mkdir /config/usb_gadget/g1/functions/ptp.gs1
mkdir /config/usb_gadget/g1/functions/rndis.gs4
mkdir /config/usb_gadget/g1/functions/midi.gs5
mkdir /config/usb_gadget/g1/functions/acm.gs0
mkdir /config/usb_gadget/g1/functions/acm.gs1
mkdir /config/usb_gadget/g1/functions/acm.gs2
mkdir /config/usb_gadget/g1/functions/acm.gs3
mkdir /config/usb_gadget/g1/functions/mass_storage.usb0
mkdir /config/usb_gadget/g1/functions/hid.gs0
mkdir /config/usb_gadget/g1/functions/via_modem.gs0
mkdir /config/usb_gadget/g1/functions/via_ets.gs0
mkdir /config/usb_gadget/g1/functions/via_atc.gs0
mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell
mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell
write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1
write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100"
write /config/usb_gadget/g1/configs/b.1/MaxPower 500
symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
setprop sys.usb.configfs 1
setprop sys.usb.controller "11201000.usb"
setprop vendor.usb.acm_cnt 0
setprop vendor.usb.acm_port0 ""
setprop vendor.usb.acm_port1 ""
setprop vendor.usb.temp ""
setprop vendor.usb.acm_enable 0
setprop vendor.usb.clear boot
setprop persist.adb.notify 0
setprop sys.usb.config "adb"

on property:ro.debuggable=0
# distinguish USB shoulde connect or not, i.e. CDP vs SDP
write /sys/class/udc/musb-hdrc/device/cmode 2
# set charging free due to it wait for USB activation
start adbd
on post-fs-data
chown radio system /sys/class/usb_rawbulk/data/enable
chmod 0660 /sys/class/usb_rawbulk/data/enable
chown radio system /sys/class/usb_rawbulk/ets/enable
chmod 0660 /sys/class/usb_rawbulk/ets/enable
chown radio system /sys/class/usb_rawbulk/atc/enable
chmod 0660 /sys/class/usb_rawbulk/atc/enable
chown radio system /sys/class/usb_rawbulk/pcv/enable
chmod 0660 /sys/class/usb_rawbulk/pcv/enable
chown radio system /sys/class/usb_rawbulk/gps/enable
chmod 0660 /sys/class/usb_rawbulk/gps/enable
chown system radio /dev/ttyGS0
chmod 0660 /dev/ttyGS0
chown system radio /dev/ttyGS1
chmod 0660 /dev/ttyGS1
chown system radio /dev/ttyGS2
chmod 0660 /dev/ttyGS2
chown system radio /dev/ttyGS3
chmod 0660 /dev/ttyGS3

on charger
mkdir /config/usb_gadget/g1 0770 shell shell
write /config/usb_gadget/g1/idVendor 0x018D1
write /config/usb_gadget/g1/bcdDevice 0x0223
write /config/usb_gadget/g1/bcdUSB 0x0200
mkdir /config/usb_gadget/g1/strings/0x409 0770
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.model}
mkdir /config/usb_gadget/g1/functions/hid.gs0
mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell
mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell
write /config/usb_gadget/g1/configs/b.1/MaxPower 500
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
setprop sys.usb.configfs 1
setprop sys.usb.controller "11201000.usb"
setprop vendor.usb.acm_cnt 0
setprop vendor.usb.acm_port0 ""
setprop vendor.usb.acm_port1 ""
setprop vendor.usb.acm_enable 0
setprop vendor.usb.clear boot
setprop sys.usb.config hid

on property:sys.usb.ffs.ready=1
### more command at init.usb.configfs.rc ###
on property:sys.usb.config=none && property:sys.usb.configfs=1
write /config/usb_gadget/g1/idVendor ${vendor.usb.vid}
rm /config/usb_gadget/g1/configs/b.1/f4
rm /config/usb_gadget/g1/configs/b.1/f5
write /sys/devices/platform/mt_usb/saving 0

on property:vendor.usb.clear=1 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/UDC "none"
write /config/usb_gadget/g1/bDeviceClass 0
write /config/usb_gadget/g1/bDeviceSubClass 0
write /config/usb_gadget/g1/bDeviceProtocol 0
rm /config/usb_gadget/g1/configs/b.1/f1
rm /config/usb_gadget/g1/configs/b.1/f2
rm /config/usb_gadget/g1/configs/b.1/f3
rm /config/usb_gadget/g1/configs/b.1/f4
rm /config/usb_gadget/g1/configs/b.1/f5
rmdir /config/usb_gadget/g1/functions/rndis.gs4
write /sys/devices/platform/mt_usb/saving 0
setprop vendor.usb.clear 2

### main function : adb ###
### start adbd at init.usb.configfs.rc ###
on property:sys.usb.config=adb && property:vendor.usb.acm_cnt=0 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x201C
on property:sys.usb.config=adb && property:vendor.usb.acm_cnt=1 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2006
setprop vendor.usb.acm_port1 ""
on property:sys.usb.config=adb && property:vendor.usb.acm_cnt=2 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2029

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && \
property:vendor.usb.acm_enable=1 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb_acm"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /sys/devices/platform/mt_usb/saving 1
symlink /config/usb_gadget/g1/functions/mass_storage.usb0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port0} /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port1} /config/usb_gadget/g1/configs/b.1/f4
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && \
property:vendor.usb.acm_enable=0 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
write /config/usb_gadget/g1/idVendor 0x18d1
write /config/usb_gadget/g1/idProduct 0xd001
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC "musb-hdrc"
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

### main function : mtp ###
on property:sys.usb.config=mtp && property:vendor.usb.acm_cnt=0 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2008
on property:sys.usb.config=mtp && property:vendor.usb.acm_cnt=1 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2012
setprop vendor.usb.acm_port1 ""
on property:sys.usb.config=mtp && property:vendor.usb.acm_cnt=2 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x202A

on property:sys.usb.config=mtp && property:vendor.usb.acm_enable=1 && \
property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_acm"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /config/usb_gadget/g1/os_desc/use 1
write /sys/devices/platform/mt_usb/saving 1
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port0} /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port1} /config/usb_gadget/g1/configs/b.1/f3
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp && property:vendor.usb.acm_enable=0 && \
property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /config/usb_gadget/g1/os_desc/use 1
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

### start adbd at init.usb.configfs.rc ###
on property:sys.usb.config=mtp,adb && property:vendor.usb.acm_cnt=0 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x201D
on property:sys.usb.config=mtp,adb && property:vendor.usb.acm_cnt=1 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x200A
setprop vendor.usb.acm_port1 ""
on property:sys.usb.config=mtp,adb && property:vendor.usb.acm_cnt=2 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2026

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && \
property:vendor.usb.acm_enable=1 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb_acm"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /config/usb_gadget/g1/os_desc/use 1
write /sys/devices/platform/mt_usb/saving 1
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port0} /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port1} /config/usb_gadget/g1/configs/b.1/f4
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && \
property:vendor.usb.acm_enable=0 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /config/usb_gadget/g1/os_desc/use 1
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

### main function : mass_storage ###
on property:sys.usb.config=mass_storage && property:vendor.usb.acm_cnt=0 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2002
on property:sys.usb.config=mass_storage && property:vendor.usb.acm_cnt=1 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x200F
setprop vendor.usb.acm_port1 ""
on property:sys.usb.config=mass_storage && property:vendor.usb.acm_cnt=2 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x202D

on property:sys.usb.config=mass_storage && property:vendor.usb.acm_enable=1 && \
property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ums_acm"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /sys/devices/platform/mt_usb/saving 1
symlink /config/usb_gadget/g1/functions/mass_storage.usb0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port0} /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port1} /config/usb_gadget/g1/configs/b.1/f3
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mass_storage && property:vendor.usb.acm_enable=0 && \
property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ums"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
symlink /config/usb_gadget/g1/functions/mass_storage.usb0 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mass_storage,adb && property:vendor.usb.acm_cnt=0 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2003
on property:sys.usb.config=mass_storage,adb && property:vendor.usb.acm_cnt=1 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2006
setprop vendor.usb.acm_port1 ""
on property:sys.usb.config=mass_storage,adb && property:vendor.usb.acm_cnt=2 && \
property:sys.usb.configfs=1
setprop vendor.usb.pid 0x2029

on property:sys.usb.config=mass_storage,adb && property:sys.usb.configfs=1
start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mass_storage,adb && \
property:vendor.usb.acm_enable=1 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ums_adb_acm"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
write /sys/devices/platform/mt_usb/saving 1
symlink /config/usb_gadget/g1/functions/mass_storage.usb0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port0} /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/acm.gs${vendor.usb.acm_port1} /config/usb_gadget/g1/configs/b.1/f4
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mass_storage,adb && \
property:vendor.usb.acm_enable=0 && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ums_adb"
write /config/usb_gadget/g1/idProduct ${vendor.usb.pid}
symlink /config/usb_gadget/g1/functions/mass_storage.usb0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on fs
symlink /dev/block/platform/soc/11230000.mmc /dev/block/platform/bootdevice

on post-fs
# Support A/B feature for EMMC and UFS boot region
symlink /dev/block/sda /dev/block/mmcblk0boot0
symlink /dev/block/sdb /dev/block/mmcblk0boot1
symlink /dev/block/mmcblk0boot0 /dev/block/platform/bootdevice/by-name/preloader_a
symlink /dev/block/mmcblk0boot1 /dev/block/platform/bootdevice/by-name/preloader_b
45 changes: 45 additions & 0 deletions recovery/root/init.recovery.usb.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on property:sys.usb.config=none && property:sys.usb.configfs=1
write /config/usb_gadget/g1/UDC "none"
stop adbd
setprop sys.usb.ffs.ready 0
write /config/usb_gadget/g1/bDeviceClass 0
write /config/usb_gadget/g1/bDeviceSubClass 0
write /config/usb_gadget/g1/bDeviceProtocol 0
rm /config/usb_gadget/g1/configs/b.1/f1
rm /config/usb_gadget/g1/configs/b.1/f2
rm /config/usb_gadget/g1/configs/b.1/f3
rmdir /config/usb_gadget/g1/functions/rndis.gs4
setprop sys.usb.state ${sys.usb.config}

on property:init.svc.adbd=stopped
setprop sys.usb.ffs.ready 0

on property:sys.usb.config=adb && property:sys.usb.configfs=1
start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1
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/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp"
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb"
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}

# Used to set USB configuration at boot and to switch the configuration
# when changing the default configuration
on property:persist.sys.usb.config=*
setprop sys.usb.config ${persist.sys.usb.config}

0 comments on commit ecf8354

Please sign in to comment.