extract-files.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # Define the default patchelf version used to patch blobs
  13. # This will also be used for utility functions like FIX_SONAME
  14. # Older versions break some camera blobs for us
  15. export PATCHELF_VERSION=0_17_2
  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/libwfdmmsrc_system.so)
  64. [ "$2" = "" ] && return 0
  65. grep -q "libgui_shim.so" "${2}" || "${PATCHELF}" --add-needed "libgui_shim.so" "${2}"
  66. ;;
  67. system_ext/lib64/libwfdnative.so)
  68. [ "$2" = "" ] && return 0
  69. grep -q "libinput_shim.so" "${2}" || "${PATCHELF}" --add-needed "libinput_shim.so" "${2}"
  70. ;;
  71. system_ext/lib64/libwfdservice.so)
  72. [ "$2" = "" ] && return 0
  73. "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
  74. ;;
  75. vendor/bin/hw/android.hardware.security.keymint-service-qti|vendor/lib64/libqtikeymint.so)
  76. [ "$2" = "" ] && return 0
  77. "${PATCHELF}" --replace-needed "android.hardware.security.keymint-V1-ndk_platform.so" "android.hardware.security.keymint-V1-ndk.so" "${2}"
  78. "${PATCHELF}" --replace-needed "android.hardware.security.secureclock-V1-ndk_platform.so" "android.hardware.security.secureclock-V1-ndk.so" "${2}"
  79. "${PATCHELF}" --replace-needed "android.hardware.security.sharedsecret-V1-ndk_platform.so" "android.hardware.security.sharedsecret-V1-ndk.so" "${2}"
  80. grep -q "android.hardware.security.rkp-V1-ndk.so" "${2}" || "${PATCHELF}" --add-needed "android.hardware.security.rkp-V1-ndk.so" "${2}"
  81. ;;
  82. vendor/bin/qcc-trd)
  83. [ "$2" = "" ] && return 0
  84. "${PATCHELF}" --replace-needed "libgrpc++_unsecure.so" "libgrpc++_unsecure_prebuilt.so" "${2}"
  85. ;;
  86. vendor/etc/media_codecs_c2_audio.xml)
  87. [ "$2" = "" ] && return 0
  88. sed -i '/media_codecs_dolby_audio/d' "${2}"
  89. ;;
  90. 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)
  91. [ "$2" = "" ] && return 0
  92. sed -i -E '/media_codecs_(google_audio|google_c2|google_telephony|vendor_audio)/d' "${2}"
  93. ;;
  94. vendor/etc/seccomp_policy/[email protected])
  95. [ "$2" = "" ] && return 0
  96. grep -q "gettid: 1" "${2}" || echo "gettid: 1" >> "${2}"
  97. ;;
  98. vendor/etc/seccomp_policy/c2audio.vendor.ext-arm64.policy)
  99. [ "$2" = "" ] && return 0
  100. grep -q "setsockopt: 1" "${2}" || echo "setsockopt: 1" >> "${2}"
  101. ;;
  102. vendor/etc/vintf/manifest/c2_manifest_vendor.xml)
  103. [ "$2" = "" ] && return 0
  104. sed -i '/dolby/d' "${2}"
  105. ;;
  106. vendor/lib64/vendor.libdpmframework.so)
  107. [ "$2" = "" ] && return 0
  108. "${PATCHELF}" --add-needed "libhidlbase_shim.so" "${2}"
  109. ;;
  110. *)
  111. return 1
  112. ;;
  113. esac
  114. return 0
  115. }
  116. function blob_fixup_dry() {
  117. blob_fixup "$1" ""
  118. }
  119. if [ -z "${ONLY_FIRMWARE}" ] && [ -z "${ONLY_TARGET}" ]; then
  120. # Initialize the helper for common device
  121. setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}"
  122. extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
  123. fi
  124. if [ -z "${ONLY_COMMON}" ] && [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then
  125. # Reinitialize the helper for device
  126. source "${MY_DIR}/../../${VENDOR}/${DEVICE}/extract-files.sh"
  127. setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
  128. if [ -z "${ONLY_FIRMWARE}" ]; then
  129. extract "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
  130. fi
  131. if [ -z "${SECTION}" ] && [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then
  132. extract_firmware "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" "${SRC}"
  133. fi
  134. fi
  135. "${MY_DIR}/setup-makefiles.sh"