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.

241 lines
6.4KB

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