You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
6.8 KiB

  1. #!/sbin/sh
  2. # Get file descriptor for output
  3. OUTFD=$(ps | grep -v "grep" | grep -o -E "update-binary(.*)" | cut -d " " -f 3);
  4. # Try looking for a differently named updater binary
  5. if [ -z $OUTFD ]; then
  6. OUTFD=$(ps | grep -v "grep" | grep -o -E "updater(.*)" | cut -d " " -f 3);
  7. fi
  8. # same as ui_print command in updater_script, for example:
  9. #
  10. # ui_print "hello world!"
  11. #
  12. # will output "hello world!" to recovery, while
  13. #
  14. # ui_print
  15. #
  16. # outputs an empty line
  17. ui_print() {
  18. if [ $OUTFD != "" ]; then
  19. echo "ui_print ${1} " 1>&$OUTFD;
  20. echo "ui_print " 1>&$OUTFD;
  21. else
  22. echo "${1}";
  23. fi;
  24. }
  25. system_mount=/mnt/system
  26. vendor_path=/vendor
  27. device_variant=
  28. device_supported=false
  29. default_network=
  30. block_allow_data=
  31. # If we have system-as-root the system is mounted at /system/system in twrp
  32. check_vendor_on_system() {
  33. ui_print "Checking whether /vendor is on /system (Pre-Treble)"
  34. # Variant 1: Non-System-as-Root
  35. # Variant 2: Q System-as-Root, system partition contains ramdisk, vendor inside own folder
  36. if [ -f ${system_mount}/vendor/etc/vintf/manifest.xml ]
  37. then
  38. vendor_path=${system_mount}/vendor
  39. # Variant 3: System-as-Root, system partition contains ramdisk, /vendor still inside /system/vendor
  40. elif [ -f ${system_mount}/system/vendor/etc/vintf/manifest.xml ]
  41. then
  42. vendor_path=${system_mount}/system/vendor
  43. fi
  44. }
  45. check_oem_as_vendor() {
  46. ui_print "Checking whether /oem is used as /vendor (Fake Treble)"
  47. if [ -f /oem/etc/vintf/manifest.xml ]
  48. then
  49. vendor_path=/oem
  50. fi
  51. }
  52. # Sanity check - was this patch already flashed?
  53. check_already_patched() {
  54. ui_print "Checking if already patched"
  55. if [ ! -z "$(cat ${vendor_path}/etc/vintf/manifest.xml | grep slot2)" ]
  56. then
  57. ui_print "Already patched"
  58. exit 0
  59. else
  60. ui_print "Not yet patched"
  61. fi
  62. }
  63. # Detect the exact model from the LTALabel partition
  64. # This looks something like:
  65. # 1284-8432_5-elabel-f8332-row.html
  66. # Output will be e.g. f8332
  67. # (Not 100% sure about the lowercase f8332 though,
  68. # so use tr to convert to all-lowercase to make sure)
  69. get_lta_label() {
  70. ui_print "Mounting LTALabel partition"
  71. mkdir /lta-label
  72. mount -t ext4 /dev/block/bootdevice/by-name/LTALabel /lta-label
  73. device_variant=$(\
  74. ls /lta-label/*.html | \
  75. sed 's/.*-elabel-//' | \
  76. sed 's/-.*.html//' | \
  77. tr -d '\n\r' | \
  78. tr '[:upper:]' '[:lower:]' \
  79. );
  80. umount /lta-label
  81. rm -r /lta-label
  82. ui_print "Device variant is ${device_variant}"
  83. }
  84. assign_props() {
  85. case ${device_variant} in
  86. # voyager, pioneer, discovery, kirin(2x), mermaid(2x), pdx201
  87. h4413|h4113|h4213|i4113|i4193|i4213|i4293|xqau52)
  88. default_network="9,0"
  89. device_supported=true
  90. ;;
  91. # suzu, kagura, dora, keyaki, maple, poplar
  92. f5122|f8332|f8132|g8232|g8142|g8342)
  93. default_network="9,1"
  94. device_supported=true
  95. ;;
  96. # apollo, akatsuki(2x), akari(2x)
  97. h8324|h9436|h9493|h8266|h8296)
  98. default_network="9,9"
  99. device_supported=true
  100. ;;
  101. # griffin, bahamut
  102. j9110|j9210)
  103. default_network="9,9"
  104. block_allow_data=0
  105. device_supported=true
  106. ;;
  107. esac
  108. }
  109. set_build_prop_dual_sim_values() {
  110. rm -f /tmp/build.prop
  111. ui_print "Setting multisim config to dsds"
  112. echo "persist.vendor.radio.multisim.config=dsds" >> /tmp/build.prop
  113. ui_print "Setting default_network to $default_network"
  114. echo "ro.telephony.default_network=$default_network" >> /tmp/build.prop
  115. if [ ! -z $block_allow_data ]
  116. # kumano devices
  117. then
  118. ui_print "Setting block_allow_data to $block_allow_data"
  119. echo "persist.vendor.radio.block_allow_data=$block_allow_data" >> /tmp/build.prop
  120. fi
  121. model=$(\
  122. cat ${vendor_path}/build.prop | \
  123. grep "ro.product.vendor.model" | \
  124. head -n 1 \
  125. )
  126. model=$(echo ${model} | sed 's/(AOSP)/Dual (AOSP)/')
  127. echo "$model" >> /tmp/build.prop
  128. ui_print "Substituting props in $vendor_path/build.prop"
  129. # Prevent prop names with spaces in them being split into multiple fields
  130. IFS=$'\n'
  131. for prop in `cat /tmp/build.prop`
  132. do
  133. propname=$(echo "$prop" | cut -d '=' -f 1)
  134. sed -i "/$propname/d" ${vendor_path}/build.prop
  135. echo "$prop" >> ${vendor_path}/build.prop
  136. done
  137. }
  138. substitute_in_build_prop() {
  139. sed -i "s/$1/$2/g" ${vendor_path}/build.prop
  140. }
  141. # VINTF manifest patching
  142. # Add a second instance of every needed HAL
  143. patch_vintf_manifest() {
  144. ui_print "Patching VINTF manifest"
  145. sed -i -r 's/( +<(fqname|instance)>[^<>]*(slot)[^<>]*)1(<\/[^<>]+>)/\11\4\n\12\4/i' ${vendor_path}/etc/vintf/manifest.xml
  146. sed -i -r 's/( +<(fqname|instance)>[^<>]*(hook|radio|ril|uim|iiwlan|idataconnection)[^<>]*)0(<\/[^<>]+>)/\10\4\n\11\4/i' ${vendor_path}/etc/vintf/manifest.xml
  147. }
  148. ui_print ""
  149. check_vendor_on_system;
  150. check_oem_as_vendor;
  151. ui_print "/vendor located at $vendor_path"
  152. get_lta_label;
  153. check_already_patched;
  154. assign_props;
  155. if [ $device_supported = false ]
  156. then
  157. ui_print ""
  158. ui_print "############################################"
  159. ui_print "FAIL: Device $device_variant not supported"
  160. ui_print "Are you trying to flash a single-sim device?"
  161. ui_print "############################################"
  162. ui_print ""
  163. exit 1
  164. fi
  165. set_build_prop_dual_sim_values;
  166. # pdx201
  167. substitute_in_build_prop xqau51 xqau52;
  168. substitute_in_build_prop XQAU51 XQAU52;
  169. substitute_in_build_prop XQ-AU51 XQ-AU52;
  170. # griffin
  171. substitute_in_build_prop j8110 j9110;
  172. substitute_in_build_prop J8110 J9110;
  173. # bahamut
  174. substitute_in_build_prop j8210 j9210;
  175. substitute_in_build_prop J8210 J9210;
  176. # kirin
  177. substitute_in_build_prop i3113 i4113;
  178. substitute_in_build_prop I3113 I4113;
  179. # mermaid
  180. substitute_in_build_prop i3213 i4213;
  181. substitute_in_build_prop I3213 I4213;
  182. # akari
  183. substitute_in_build_prop h8216 h8266;
  184. substitute_in_build_prop H8216 H8266;
  185. # apollo
  186. substitute_in_build_prop h8314 h8324;
  187. substitute_in_build_prop H8314 H8324;
  188. # akatsuki
  189. substitute_in_build_prop h8416 h9436;
  190. substitute_in_build_prop H8416 H9436;
  191. # pioneer
  192. substitute_in_build_prop h3113 h4113;
  193. substitute_in_build_prop H3113 H4113;
  194. # discovery
  195. substitute_in_build_prop h3213 h4213;
  196. substitute_in_build_prop H3213 H4213;
  197. # voyager
  198. substitute_in_build_prop h3413 h4413;
  199. substitute_in_build_prop H3413 H4413;
  200. # maple
  201. substitute_in_build_prop g8131 g8142;
  202. substitute_in_build_prop G8131 G8142;
  203. # poplar
  204. substitute_in_build_prop g8341 g8342;
  205. substitute_in_build_prop G8341 G8342;
  206. # dora
  207. substitute_in_build_prop f8131 f8132;
  208. substitute_in_build_prop F8131 F8132;
  209. # kagura
  210. substitute_in_build_prop f8331 f8332;
  211. substitute_in_build_prop F8331 F8332;
  212. # keyaki
  213. substitute_in_build_prop g8231 g8232;
  214. substitute_in_build_prop G8231 G8232;
  215. # suzu
  216. substitute_in_build_prop f5121 f5122;
  217. substitute_in_build_prop F5121 F5122;
  218. patch_vintf_manifest;