extract-files.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. #
  3. # SPDX-FileCopyrightText: 2016 The CyanogenMod Project
  4. # SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. set -e
  8. # Load extract_utils and do some sanity checks
  9. MY_DIR="${BASH_SOURCE%/*}"
  10. if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi
  11. ANDROID_ROOT="${MY_DIR}/../../.."
  12. export TARGET_ENABLE_CHECKELF="true"
  13. # If XML files don't have comments before the XML header, use this flag
  14. # Can still be used with broken XML files by using blob_fixup
  15. export TARGET_DISABLE_XML_FIXING=true
  16. HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh"
  17. if [ ! -f "${HELPER}" ]; then
  18. echo "Unable to find helper script at ${HELPER}"
  19. exit 1
  20. fi
  21. source "${HELPER}"
  22. # Default to sanitizing the vendor folder before extraction
  23. CLEAN_VENDOR=true
  24. ONLY_COMMON=
  25. ONLY_FIRMWARE=
  26. ONLY_TARGET=
  27. KANG=
  28. SECTION=
  29. CARRIER_SKIP_FILES=()
  30. while [ "${#}" -gt 0 ]; do
  31. case "${1}" in
  32. --only-common)
  33. ONLY_COMMON=true
  34. ;;
  35. --only-firmware)
  36. ONLY_FIRMWARE=true
  37. ;;
  38. --only-target)
  39. ONLY_TARGET=true
  40. ;;
  41. -n | --no-cleanup)
  42. CLEAN_VENDOR=false
  43. ;;
  44. -k | --kang)
  45. KANG="--kang"
  46. ;;
  47. -s | --section)
  48. SECTION="${2}"
  49. shift
  50. CLEAN_VENDOR=false
  51. ;;
  52. *)
  53. SRC="${1}"
  54. ;;
  55. esac
  56. shift
  57. done
  58. if [ -z "${SRC}" ]; then
  59. SRC="adb"
  60. fi
  61. function blob_fixup() {
  62. case "${1}" in
  63. system_ext/lib64/libwfdservice.so)
  64. [ "$2" = "" ] && return 0
  65. "${PATCHELF_0_17_2}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
  66. ;;
  67. vendor/bin/hw/android.hardware.security.keymint-service-qti|vendor/lib64/libqtikeymint.so)
  68. [ "$2" = "" ] && return 0
  69. "${PATCHELF_0_17_2}" --replace-needed "android.hardware.security.keymint-V1-ndk_platform.so" "android.hardware.security.keymint-V1-ndk.so" "${2}"
  70. "${PATCHELF_0_17_2}" --replace-needed "android.hardware.security.secureclock-V1-ndk_platform.so" "android.hardware.security.secureclock-V1-ndk.so" "${2}"
  71. "${PATCHELF_0_17_2}" --replace-needed "android.hardware.security.sharedsecret-V1-ndk_platform.so" "android.hardware.security.sharedsecret-V1-ndk.so" "${2}"
  72. grep -q "android.hardware.security.rkp-V1-ndk.so" "${2}" || "${PATCHELF_0_17_2}" --add-needed "android.hardware.security.rkp-V1-ndk.so" "${2}"
  73. ;;
  74. vendor/bin/qcc-trd)
  75. [ "$2" = "" ] && return 0
  76. "${PATCHELF_0_17_2}" --replace-needed "libgrpc++_unsecure.so" "libgrpc++_unsecure_prebuilt.so" "${2}"
  77. ;;
  78. vendor/etc/media_codecs_c2_audio.xml)
  79. [ "$2" = "" ] && return 0
  80. sed -i '/media_codecs_dolby_audio/d' "${2}"
  81. ;;
  82. vendor/etc/media_codecs_cape.xml|vendor/etc/media_codecs_diwali_v0.xml|vendor/etc/media_codecs_diwali_v1.xml|vendor/etc/media_codecs_diwali_v2.xml|vendor/etc/media_codecs_taro.xml|vendor/etc/media_codecs_ukee.xml)
  83. [ "$2" = "" ] && return 0
  84. sed -i -E '/media_codecs_(google_audio|google_c2|google_telephony|vendor_audio)/d' "${2}"
  85. ;;
  86. vendor/etc/qcril_database/upgrade/config/6.0_config.sql)
  87. [ "$2" = "" ] && return 0
  88. sed -i '/persist.vendor.radio.redir_party_num/ s/true/false/g' "${2}"
  89. ;;
  90. vendor/etc/vintf/manifest/c2_manifest_vendor.xml)
  91. [ "$2" = "" ] && return 0
  92. sed -i '/dolby/d' "${2}"
  93. ;;
  94. vendor/lib64/libgrpc++_unsecure_prebuilt.so)
  95. [ "$2" = "" ] && return 0
  96. "${PATCHELF_0_17_2}" --set-soname "libgrpc++_unsecure_prebuilt.so" "${2}"
  97. ;;
  98. *)
  99. return 1
  100. ;;
  101. esac
  102. return 0
  103. }
  104. function blob_fixup_dry() {
  105. blob_fixup "$1" ""
  106. }
  107. if [ -z "${ONLY_FIRMWARE}" ] && [ -z "${ONLY_TARGET}" ]; then
  108. # Initialize the helper for common device
  109. setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}"
  110. extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
  111. fi
  112. if [ -z "${ONLY_COMMON}" ] && [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then
  113. # Reinitialize the helper for device
  114. source "${MY_DIR}/../../${VENDOR}/${DEVICE}/extract-files.sh"
  115. setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
  116. if [ -z "${ONLY_FIRMWARE}" ]; then
  117. extract "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
  118. fi
  119. if [ -z "${SECTION}" ] && [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then
  120. extract_firmware "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" "${SRC}"
  121. fi
  122. fi
  123. "${MY_DIR}/setup-makefiles.sh"