首页 安卓教程

入手Pixel后发现TWRP有一些问题,遂写此文,如有错误,欢迎指出

注意:没有特殊标注,本文将以Arch Linux为蓝本

环境准备

ArchWiki的Android篇写的非常详细,可以参考Wiki的方案配置

sudo pacman -Syy
sudo pacman -S yay #如果未找到软件包,请配置archlinuxcn源
yay -S aosp-devel lineageos-devel maven gradle

设备树的准备

在Pixel 2(XL)系列,common设备树是wahoo,而wahoo里有两个问题,MTP和CPU温度正显问题
所以,我们同步设备树

设备树修复(痛苦面具系列)

CPU温度正显问题

这个问题要引用Custom Temp
首先我们要确定位置,连接电脑,手机开启USB调试,然后运行

adb shell

进入手机shell后,我们获取超级用户权限

su

然后获取TEMP位置

ls /sys/devices/virtual/thermal/

然后像下图这样,我们可以一个一个试(反正我试到7才成功,正常试到1温度就正显了,痛苦面具+1)
QQ图片20210307000046.png
最后在BoardConfig加入

 TW_CUSTOM_CPU_TEMP_PATH := /sys/devices/virtual/thermal/thermal_zone7/temp

MTP问题

因为msm8998的init.recovery.usb.rc在正常情况下是通用的,而设备树正好没有此文件,所以我们进行添加,文件内容如下,保存为init.recovery.usb.rc

 # Copyright (C) 2012 The Android Open Source Project
 #
 # USB configuration common for all android devices
 #
 
 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
     mkdir /config/usb_gadget/g1/strings/0x409 0770 shell shell
     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.model}
     mkdir /config/usb_gadget/g1/functions/mass_storage.0
     mkdir /config/usb_gadget/g1/functions/mtp.gs0
     mkdir /config/usb_gadget/g1/functions/ptp.gs1
     mkdir /config/usb_gadget/g1/functions/accessory.gs2
     mkdir /config/usb_gadget/g1/functions/audio_source.gs2
     mkdir /config/usb_gadget/g1/functions/audio_source.gs3
     mkdir /config/usb_gadget/g1/functions/midi.gs5
     mkdir /config/usb_gadget/g1/functions/ffs.adb
     mkdir /config/usb_gadget/g1/functions/diag.diag
     mkdir /config/usb_gadget/g1/functions/cser.dun.0
     mkdir /config/usb_gadget/g1/functions/cser.nmea.1
     mkdir /config/usb_gadget/g1/functions/gsi.rmnet
     mkdir /config/usb_gadget/g1/functions/gsi.rndis
     mkdir /config/usb_gadget/g1/functions/gsi.dpl
     mkdir /config/usb_gadget/g1/functions/qdss.qdss
     mkdir /config/usb_gadget/g1/functions/rndis_bam.rndis
     mkdir /config/usb_gadget/g1/functions/rmnet_bam.rmnet
     mkdir /config/usb_gadget/g1/functions/rmnet_bam.dpl
     mkdir /config/usb_gadget/g1/functions/ncm.0
     mkdir /config/usb_gadget/g1/functions/ccid.ccid
     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"
     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
     write /sys/class/android_usb/android0/f_ffs/aliases adb

 on property:sys.usb.config=none
     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
     setprop sys.usb.state ${sys.usb.config}

 on property:sys.usb.config=adb
     start adbd

 on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb
     write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
     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
     write /config/usb_gadget/g1/idVendor 0x18d1
     write /config/usb_gadget/g1/idProduct 0x4ee7
     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
     write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp"
     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
     write /config/usb_gadget/g1/idVendor 0x18d1
     write /config/usb_gadget/g1/idProduct 0x2d00
     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
     start adbd

 on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb
     write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb"
     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
     write /config/usb_gadget/g1/idVendor 0x18d1
     write /config/usb_gadget/g1/idProduct 0x2d01
     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}

然后在device.mk中添加,在编译rec时复制此文件,当然有些树不用加

 PRODUCT_COPY_FILES += \
     device/google/wahoo/init.recovery.usb.rc:root/init.recovery.usb.rc

删除或注释BoardConfg.mk中此变量

 TW_EXCLUDE_MTP := true

重新编译后将会发现MTP可用(如果你认为这就结束了,那你就太天真了,痛苦面具+1)

MTP写文件问题修复

MTP有两种模式,一种是mtp.gs0,一种是ffs.mtp,所以我们要确定自己的手机是用啥模式,不然会导致无法写入等一系列奇怪问题
首先,我们还是用ADB进入shell然后超级用户查看挂载点

 adb shell
 su
 ls /config/usb_gadget/g1/functions/

然后如图,Pixel 2(XL)使用ffs.mtp
QQ截图20210307001525.png

所以,我们将mtp.gs0更换为ffs.mtp,参考此commit添加如下(肯定不如Github直观)

 +mkdir /dev/usb-ffs/mtp 0770 shell shell
 +mkdir /dev/usb-ffs/ptp 0770 shell shell

 -mkdir /config/usb_gadget/g1/functions/mtp.gs0
 -mkdir /config/usb_gadget/g1/functions/ptp.gs1
 +mkdir /config/usb_gadget/g1/functions/ffs.mtp
 +mkdir /config/usb_gadget/g1/functions/ffs.ptp

 +mount functionfs mtp /dev/usb-ffs/mtp uid=2000,gid=2000
 +mount functionfs ptp /dev/usb-ffs/ptp uid=2000,gid=2000

 -symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
 +symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1

 -on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb
 +on property:sys.usb.ffs.ready=1 && property:sys.usb.ffs.mtp.ready=1 && property:sys.usb.config=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.mtp /config/usb_gadget/g1/configs/b.1/f1

然后重新编译,就差不多了(痛苦面具+1)

最后

只要多动手,多看commit,多搜索,应该.....我编不下去了
修复一些东西需要手机调试,这也是为啥我真的不爱接没机子的ROM制作。

参考

https://github.com/TeamWin
https://github.com/LineageOS
忘了看了多少个commit,也忘了是哪个库的commit(不要打我)




文章评论

目录