Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 3 | # SPDX-FileCopyrightText: 2016 The CyanogenMod Project |
| 4 | # SPDX-FileCopyrightText: 2017-2024 The LineageOS Project |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | # |
| 7 | |
| 8 | set -e |
| 9 | |
Michael Bestas | 9e3d0d6 | 2024-05-28 03:47:26 +0300 | [diff] [blame] | 10 | DEVICE=otter |
| 11 | VENDOR=shift |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 12 | |
| 13 | # Load extract_utils and do some sanity checks |
| 14 | MY_DIR="${BASH_SOURCE%/*}" |
| 15 | if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi |
| 16 | |
| 17 | ANDROID_ROOT="${MY_DIR}/../../.." |
| 18 | |
| 19 | HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" |
| 20 | if [ ! -f "${HELPER}" ]; then |
| 21 | echo "Unable to find helper script at ${HELPER}" |
| 22 | exit 1 |
| 23 | fi |
| 24 | source "${HELPER}" |
| 25 | |
| 26 | # Default to sanitizing the vendor folder before extraction |
| 27 | CLEAN_VENDOR=true |
| 28 | |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 29 | ONLY_FIRMWARE= |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 30 | KANG= |
| 31 | SECTION= |
| 32 | |
| 33 | while [ "${#}" -gt 0 ]; do |
| 34 | case "${1}" in |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 35 | --only-firmware) |
| 36 | ONLY_FIRMWARE=true |
| 37 | ;; |
| 38 | -n | --no-cleanup) |
| 39 | CLEAN_VENDOR=false |
| 40 | ;; |
| 41 | -k | --kang) |
| 42 | KANG="--kang" |
| 43 | ;; |
| 44 | -s | --section) |
| 45 | SECTION="${2}" |
| 46 | shift |
| 47 | CLEAN_VENDOR=false |
| 48 | ;; |
| 49 | *) |
| 50 | SRC="${1}" |
| 51 | ;; |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 52 | esac |
| 53 | shift |
| 54 | done |
| 55 | |
| 56 | if [ -z "${SRC}" ]; then |
| 57 | SRC="adb" |
| 58 | fi |
| 59 | |
| 60 | function blob_fixup() { |
| 61 | case "${1}" in |
LuK1337 | 27b24af | 2024-10-12 17:42:02 +0200 | [diff] [blame] | 62 | system_ext/lib/libwfdmmsrc_system.so) |
| 63 | [ "$2" = "" ] && return 0 |
| 64 | grep -q "libgui_shim.so" "${2}" || "${PATCHELF}" --add-needed "libgui_shim.so" "${2}" |
| 65 | ;; |
Michael Bestas | 98ac4c9 | 2024-08-25 21:46:46 +0300 | [diff] [blame] | 66 | system_ext/lib/libwfdservice.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 67 | [ "$2" = "" ] && return 0 |
Michael Bestas | 98ac4c9 | 2024-08-25 21:46:46 +0300 | [diff] [blame] | 68 | "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}" |
| 69 | ;; |
Michael Bestas | c3ad1cd | 2023-10-03 15:27:40 +0300 | [diff] [blame] | 70 | system_ext/lib64/libwfdnative.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 71 | [ "$2" = "" ] && return 0 |
Michael Bestas | c3ad1cd | 2023-10-03 15:27:40 +0300 | [diff] [blame] | 72 | sed -i "s/android.hidl.base@1.0.so/libhidlbase.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/" "${2}" |
LuK1337 | 27b24af | 2024-10-12 17:42:02 +0200 | [diff] [blame] | 73 | grep -q "libinput_shim.so" "${2}" || "${PATCHELF}" --add-needed "libinput_shim.so" "${2}" |
Michael Bestas | c3ad1cd | 2023-10-03 15:27:40 +0300 | [diff] [blame] | 74 | ;; |
Michael Bestas | 9743229 | 2024-08-27 00:21:27 +0300 | [diff] [blame] | 75 | vendor/lib64/hw/fingerprint.lahaina.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 76 | [ "$2" = "" ] && return 0 |
Michael Bestas | 9743229 | 2024-08-27 00:21:27 +0300 | [diff] [blame] | 77 | "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}" |
| 78 | ;; |
Michael Bestas | c91a86b | 2024-09-11 00:04:13 +0300 | [diff] [blame] | 79 | vendor/lib64/libwvhidl.so) |
| 80 | [ "$2" = "" ] && return 0 |
| 81 | "${PATCHELF}" --add-needed "libcrypto_shim.so" "${2}" |
| 82 | ;; |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 83 | *) |
| 84 | return 1 |
| 85 | ;; |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 86 | esac |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 87 | |
| 88 | return 0 |
| 89 | } |
| 90 | |
| 91 | function blob_fixup_dry() { |
| 92 | blob_fixup "$1" "" |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | # Initialize the helper |
| 96 | setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" |
| 97 | |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 98 | if [ -z "${ONLY_FIRMWARE}" ]; then |
| 99 | extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" |
| 100 | fi |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 101 | |
Michael Bestas | bfccf73 | 2022-02-22 19:22:26 +0200 | [diff] [blame] | 102 | if [ -z "${SECTION}" ]; then |
| 103 | extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}" |
| 104 | fi |
| 105 | |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 106 | "${MY_DIR}/setup-makefiles.sh" |