extract-files.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. # Define the default patchelf version used to patch blobs
  17. # This will also be used for utility functions like FIX_SONAME
  18. # Older versions break some camera blobs for us
  19. export PATCHELF_VERSION=0_17_2
  20. HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh"
  21. if [ ! -f "${HELPER}" ]; then
  22. echo "Unable to find helper script at ${HELPER}"
  23. exit 1
  24. fi
  25. source "${HELPER}"
  26. # Default to sanitizing the vendor folder before extraction
  27. CLEAN_VENDOR=true
  28. ONLY_COMMON=
  29. ONLY_FIRMWARE=
  30. ONLY_TARGET=
  31. KANG=
  32. SECTION=
  33. CARRIER_SKIP_FILES=()
  34. while [ "${#}" -gt 0 ]; do
  35. case "${1}" in
  36. --only-common)
  37. ONLY_COMMON=true
  38. ;;
  39. --only-firmware)
  40. ONLY_FIRMWARE=true
  41. ;;
  42. --only-target)
  43. ONLY_TARGET=true
  44. ;;
  45. -n | --no-cleanup)
  46. CLEAN_VENDOR=false
  47. ;;
  48. -k | --kang)
  49. KANG="--kang"
  50. ;;
  51. -s | --section)
  52. SECTION="${2}"
  53. shift
  54. CLEAN_VENDOR=false
  55. ;;
  56. *)
  57. SRC="${1}"
  58. ;;
  59. esac
  60. shift
  61. done
  62. if [ -z "${SRC}" ]; then
  63. SRC="adb"
  64. fi
  65. function blob_fixup() {
  66. case "${1}" in
  67. system_ext/lib64/libwfdservice.so)
  68. [ "$2" = "" ] && return 0
  69. "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
  70. ;;
  71. vendor/bin/hw/android.hardware.security.keymint-service-qti|vendor/lib64/libqtikeymint.so)
  72. [ "$2" = "" ] && return 0
  73. "${PATCHELF}" --replace-needed "android.hardware.security.keymint-V1-ndk_platform.so" "android.hardware.security.keymint-V1-ndk.so" "${2}"
  74. "${PATCHELF}" --replace-needed "android.hardware.security.secureclock-V1-ndk_platform.so" "android.hardware.security.secureclock-V1-ndk.so" "${2}"
  75. "${PATCHELF}" --replace-needed "android.hardware.security.sharedsecret-V1-ndk_platform.so" "android.hardware.security.sharedsecret-V1-ndk.so" "${2}"
  76. grep -q "android.hardware.security.rkp-V1-ndk.so" "${2}" || "${PATCHELF}" --add-needed "android.hardware.security.rkp-V1-ndk.so" "${2}"
  77. ;;
  78. vendor/bin/qcc-trd)
  79. [ "$2" = "" ] && return 0
  80. "${PATCHELF}" --replace-needed "libgrpc++_unsecure.so" "libgrpc++_unsecure_prebuilt.so" "${2}"
  81. ;;
  82. vendor/etc/media_codecs_c2_audio.xml)
  83. [ "$2" = "" ] && return 0
  84. sed -i '/media_codecs_dolby_audio/d' "${2}"
  85. ;;
  86. 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)
  87. [ "$2" = "" ] && return 0
  88. sed -i -E '/media_codecs_(google_audio|google_c2|google_telephony|vendor_audio)/d' "${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/vendor.libdpmframework.so)
  95. [ "$2" = "" ] && return 0
  96. "${PATCHELF}" --add-needed "libhidlbase_shim.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"