blob: d2f491adfd9e6277ad54843e6a7b86c21baf67a4 [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 Bestas9e3d0d62024-05-28 03:47:26 +030010DEVICE=otter
11VENDOR=shift
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
19HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh"
20if [ ! -f "${HELPER}" ]; then
21 echo "Unable to find helper script at ${HELPER}"
22 exit 1
23fi
24source "${HELPER}"
25
26# Default to sanitizing the vendor folder before extraction
27CLEAN_VENDOR=true
28
Michael Bestas7830bc12024-08-27 22:51:30 +030029ONLY_FIRMWARE=
Michael Bestas411537b2020-12-28 00:58:46 +020030KANG=
31SECTION=
32
33while [ "${#}" -gt 0 ]; do
34 case "${1}" in
Michael Bestas7830bc12024-08-27 22:51:30 +030035 --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 Bestas411537b2020-12-28 00:58:46 +020052 esac
53 shift
54done
55
56if [ -z "${SRC}" ]; then
57 SRC="adb"
58fi
59
60function blob_fixup() {
61 case "${1}" in
Michael Bestas98ac4c92024-08-25 21:46:46 +030062 system_ext/lib/libwfdservice.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030063 [ "$2" = "" ] && return 0
Michael Bestas98ac4c92024-08-25 21:46:46 +030064 "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
65 ;;
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030066 system_ext/lib64/libwfdnative.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030067 [ "$2" = "" ] && return 0
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030068 sed -i "s/android.hidl.base@1.0.so/libhidlbase.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/" "${2}"
69 ;;
Michael Bestas97432292024-08-27 00:21:27 +030070 vendor/lib64/hw/fingerprint.lahaina.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030071 [ "$2" = "" ] && return 0
Michael Bestas97432292024-08-27 00:21:27 +030072 "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}"
73 ;;
Michael Bestasc91a86b2024-09-11 00:04:13 +030074 vendor/lib64/libwvhidl.so)
75 [ "$2" = "" ] && return 0
76 "${PATCHELF}" --add-needed "libcrypto_shim.so" "${2}"
77 ;;
Michael Bestas7830bc12024-08-27 22:51:30 +030078 *)
79 return 1
80 ;;
Michael Bestas411537b2020-12-28 00:58:46 +020081 esac
Michael Bestas7830bc12024-08-27 22:51:30 +030082
83 return 0
84}
85
86function blob_fixup_dry() {
87 blob_fixup "$1" ""
Michael Bestas411537b2020-12-28 00:58:46 +020088}
89
90# Initialize the helper
91setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
92
Michael Bestas7830bc12024-08-27 22:51:30 +030093if [ -z "${ONLY_FIRMWARE}" ]; then
94 extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
95fi
Michael Bestas411537b2020-12-28 00:58:46 +020096
Michael Bestasbfccf732022-02-22 19:22:26 +020097if [ -z "${SECTION}" ]; then
98 extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}"
99fi
100
Michael Bestas411537b2020-12-28 00:58:46 +0200101"${MY_DIR}/setup-makefiles.sh"