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 | 1037453 | 2023-08-29 19:41:38 +0300 | [diff] [blame] | 10 | DEVICE=FP5 |
merothh | fb168c8 | 2022-01-02 18:18:04 +0530 | [diff] [blame] | 11 | VENDOR=fairphone |
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 | |
Aaron Kling | 6411f24 | 2024-08-14 01:44:45 -0500 | [diff] [blame] | 19 | export TARGET_ENABLE_CHECKELF=true |
| 20 | |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 21 | # If XML files don't have comments before the XML header, use this flag |
| 22 | # Can still be used with broken XML files by using blob_fixup |
| 23 | export TARGET_DISABLE_XML_FIXING=true |
| 24 | |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 25 | HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" |
| 26 | if [ ! -f "${HELPER}" ]; then |
| 27 | echo "Unable to find helper script at ${HELPER}" |
| 28 | exit 1 |
| 29 | fi |
| 30 | source "${HELPER}" |
| 31 | |
| 32 | # Default to sanitizing the vendor folder before extraction |
| 33 | CLEAN_VENDOR=true |
| 34 | |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 35 | ONLY_FIRMWARE= |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 36 | KANG= |
| 37 | SECTION= |
| 38 | |
| 39 | while [ "${#}" -gt 0 ]; do |
| 40 | case "${1}" in |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 41 | --only-firmware) |
| 42 | ONLY_FIRMWARE=true |
| 43 | ;; |
| 44 | -n | --no-cleanup) |
| 45 | CLEAN_VENDOR=false |
| 46 | ;; |
| 47 | -k | --kang) |
| 48 | KANG="--kang" |
| 49 | ;; |
| 50 | -s | --section) |
| 51 | SECTION="${2}" |
| 52 | shift |
| 53 | CLEAN_VENDOR=false |
| 54 | ;; |
| 55 | *) |
| 56 | SRC="${1}" |
| 57 | ;; |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 58 | esac |
| 59 | shift |
| 60 | done |
| 61 | |
| 62 | if [ -z "${SRC}" ]; then |
| 63 | SRC="adb" |
| 64 | fi |
| 65 | |
| 66 | function blob_fixup() { |
| 67 | case "${1}" in |
Michael Bestas | 98ac4c9 | 2024-08-25 21:46:46 +0300 | [diff] [blame] | 68 | system_ext/lib/libwfdservice.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 69 | [ "$2" = "" ] && return 0 |
Michael Bestas | 98ac4c9 | 2024-08-25 21:46:46 +0300 | [diff] [blame] | 70 | "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}" |
| 71 | ;; |
Michael Bestas | c3ad1cd | 2023-10-03 15:27:40 +0300 | [diff] [blame] | 72 | system_ext/lib64/libwfdnative.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 73 | [ "$2" = "" ] && return 0 |
Michael Bestas | c3ad1cd | 2023-10-03 15:27:40 +0300 | [diff] [blame] | 74 | sed -i "s/android.hidl.base@1.0.so/libhidlbase.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/" "${2}" |
| 75 | ;; |
Rohit Sekhar | 2864746 | 2023-09-10 13:31:18 +0530 | [diff] [blame] | 76 | vendor/etc/libnfc-hal-st.conf) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 77 | [ "$2" = "" ] && return 0 |
Rohit Sekhar | 2864746 | 2023-09-10 13:31:18 +0530 | [diff] [blame] | 78 | sed -i 's|STNFC_HAL_LOGLEVEL=.*|STNFC_HAL_LOGLEVEL=0x12|g' "${2}" |
| 79 | ;; |
Michael Bestas | 9743229 | 2024-08-27 00:21:27 +0300 | [diff] [blame] | 80 | vendor/lib64/hw/fingerprint.lahaina.so) |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 81 | [ "$2" = "" ] && return 0 |
Michael Bestas | 9743229 | 2024-08-27 00:21:27 +0300 | [diff] [blame] | 82 | "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}" |
| 83 | ;; |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 84 | *) |
| 85 | return 1 |
| 86 | ;; |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 87 | esac |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 88 | |
| 89 | return 0 |
| 90 | } |
| 91 | |
| 92 | function blob_fixup_dry() { |
| 93 | blob_fixup "$1" "" |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | # Initialize the helper |
| 97 | setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" |
| 98 | |
Michael Bestas | 7830bc1 | 2024-08-27 22:51:30 +0300 | [diff] [blame] | 99 | if [ -z "${ONLY_FIRMWARE}" ]; then |
| 100 | extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" |
| 101 | fi |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 102 | |
Michael Bestas | bfccf73 | 2022-02-22 19:22:26 +0200 | [diff] [blame] | 103 | if [ -z "${SECTION}" ]; then |
| 104 | extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}" |
| 105 | fi |
| 106 | |
Michael Bestas | 411537b | 2020-12-28 00:58:46 +0200 | [diff] [blame] | 107 | "${MY_DIR}/setup-makefiles.sh" |