blob: b2c10f5df17fa6f02ee15d19aeee182e136f3aeb [file] [log] [blame]
Michael Bestas411537b2020-12-28 00:58:46 +02001#!/bin/bash
2#
Michael Bestas7830bc12024-08-27 22:51:30 +03003# SPDX-FileCopyrightText: 2016 The CyanogenMod Project
4# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
Michael Bestas411537b2020-12-28 00:58:46 +02005# SPDX-License-Identifier: Apache-2.0
6#
7
8set -e
9
Michael Bestas10374532023-08-29 19:41:38 +030010DEVICE=FP5
merothhfb168c82022-01-02 18:18:04 +053011VENDOR=fairphone
Michael Bestas411537b2020-12-28 00:58:46 +020012
13# Load extract_utils and do some sanity checks
14MY_DIR="${BASH_SOURCE%/*}"
15if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi
16
17ANDROID_ROOT="${MY_DIR}/../../.."
18
Michael Bestas7830bc12024-08-27 22:51:30 +030019# 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
21export TARGET_DISABLE_XML_FIXING=true
22
Michael Bestas411537b2020-12-28 00:58:46 +020023HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh"
24if [ ! -f "${HELPER}" ]; then
25 echo "Unable to find helper script at ${HELPER}"
26 exit 1
27fi
28source "${HELPER}"
29
30# Default to sanitizing the vendor folder before extraction
31CLEAN_VENDOR=true
32
Michael Bestas7830bc12024-08-27 22:51:30 +030033ONLY_FIRMWARE=
Michael Bestas411537b2020-12-28 00:58:46 +020034KANG=
35SECTION=
36
37while [ "${#}" -gt 0 ]; do
38 case "${1}" in
Michael Bestas7830bc12024-08-27 22:51:30 +030039 --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 Bestas411537b2020-12-28 00:58:46 +020056 esac
57 shift
58done
59
60if [ -z "${SRC}" ]; then
61 SRC="adb"
62fi
63
64function blob_fixup() {
65 case "${1}" in
Michael Bestas98ac4c92024-08-25 21:46:46 +030066 system_ext/lib/libwfdservice.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030067 [ "$2" = "" ] && return 0
Michael Bestas98ac4c92024-08-25 21:46:46 +030068 "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
69 ;;
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030070 system_ext/lib64/libwfdnative.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030071 [ "$2" = "" ] && return 0
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030072 sed -i "s/android.hidl.base@1.0.so/libhidlbase.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/" "${2}"
73 ;;
Rohit Sekhar28647462023-09-10 13:31:18 +053074 vendor/etc/libnfc-hal-st.conf)
Michael Bestas7830bc12024-08-27 22:51:30 +030075 [ "$2" = "" ] && return 0
Rohit Sekhar28647462023-09-10 13:31:18 +053076 sed -i 's|STNFC_HAL_LOGLEVEL=.*|STNFC_HAL_LOGLEVEL=0x12|g' "${2}"
77 ;;
Michael Bestas97432292024-08-27 00:21:27 +030078 vendor/lib64/hw/fingerprint.lahaina.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030079 [ "$2" = "" ] && return 0
Michael Bestas97432292024-08-27 00:21:27 +030080 "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}"
81 ;;
Michael Bestas7830bc12024-08-27 22:51:30 +030082 *)
83 return 1
84 ;;
Michael Bestas411537b2020-12-28 00:58:46 +020085 esac
Michael Bestas7830bc12024-08-27 22:51:30 +030086
87 return 0
88}
89
90function blob_fixup_dry() {
91 blob_fixup "$1" ""
Michael Bestas411537b2020-12-28 00:58:46 +020092}
93
94# Initialize the helper
95setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
96
Michael Bestas7830bc12024-08-27 22:51:30 +030097if [ -z "${ONLY_FIRMWARE}" ]; then
98 extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
99fi
Michael Bestas411537b2020-12-28 00:58:46 +0200100
Michael Bestasbfccf732022-02-22 19:22:26 +0200101if [ -z "${SECTION}" ]; then
102 extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}"
103fi
104
Michael Bestas411537b2020-12-28 00:58:46 +0200105"${MY_DIR}/setup-makefiles.sh"