extract-files.sh 4.3 KB

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