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