blob: 9a85469fae3b6dc2105686c7fdf82c6f3fdc724e [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
LuK133727b24af2024-10-12 17:42:02 +020062 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 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}"
LuK133727b24af2024-10-12 17:42:02 +020073 grep -q "libinput_shim.so" "${2}" || "${PATCHELF}" --add-needed "libinput_shim.so" "${2}"
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030074 ;;
Michael Bestas97432292024-08-27 00:21:27 +030075 vendor/lib64/hw/fingerprint.lahaina.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030076 [ "$2" = "" ] && return 0
Michael Bestas97432292024-08-27 00:21:27 +030077 "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}"
78 ;;
Michael Bestasc91a86b2024-09-11 00:04:13 +030079 vendor/lib64/libwvhidl.so)
80 [ "$2" = "" ] && return 0
81 "${PATCHELF}" --add-needed "libcrypto_shim.so" "${2}"
82 ;;
Michael Bestas7830bc12024-08-27 22:51:30 +030083 *)
84 return 1
85 ;;
Michael Bestas411537b2020-12-28 00:58:46 +020086 esac
Michael Bestas7830bc12024-08-27 22:51:30 +030087
88 return 0
89}
90
91function blob_fixup_dry() {
92 blob_fixup "$1" ""
Michael Bestas411537b2020-12-28 00:58:46 +020093}
94
95# Initialize the helper
96setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
97
Michael Bestas7830bc12024-08-27 22:51:30 +030098if [ -z "${ONLY_FIRMWARE}" ]; then
99 extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
100fi
Michael Bestas411537b2020-12-28 00:58:46 +0200101
Michael Bestasbfccf732022-02-22 19:22:26 +0200102if [ -z "${SECTION}" ]; then
103 extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}"
104fi
105
Michael Bestas411537b2020-12-28 00:58:46 +0200106"${MY_DIR}/setup-makefiles.sh"