blob: fcb9c71af59796456fdbfeeb0c825fbe20ab711c [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
Aaron Kling6411f242024-08-14 01:44:45 -050019export TARGET_ENABLE_CHECKELF=true
20
Michael Bestas7830bc12024-08-27 22:51:30 +030021# 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
23export TARGET_DISABLE_XML_FIXING=true
24
Michael Bestas411537b2020-12-28 00:58:46 +020025HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh"
26if [ ! -f "${HELPER}" ]; then
27 echo "Unable to find helper script at ${HELPER}"
28 exit 1
29fi
30source "${HELPER}"
31
32# Default to sanitizing the vendor folder before extraction
33CLEAN_VENDOR=true
34
Michael Bestas7830bc12024-08-27 22:51:30 +030035ONLY_FIRMWARE=
Michael Bestas411537b2020-12-28 00:58:46 +020036KANG=
37SECTION=
38
39while [ "${#}" -gt 0 ]; do
40 case "${1}" in
Michael Bestas7830bc12024-08-27 22:51:30 +030041 --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 Bestas411537b2020-12-28 00:58:46 +020058 esac
59 shift
60done
61
62if [ -z "${SRC}" ]; then
63 SRC="adb"
64fi
65
66function blob_fixup() {
67 case "${1}" in
Michael Bestas98ac4c92024-08-25 21:46:46 +030068 system_ext/lib/libwfdservice.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030069 [ "$2" = "" ] && return 0
Michael Bestas98ac4c92024-08-25 21:46:46 +030070 "${PATCHELF}" --replace-needed "android.media.audio.common.types-V2-cpp.so" "android.media.audio.common.types-V3-cpp.so" "${2}"
71 ;;
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030072 system_ext/lib64/libwfdnative.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030073 [ "$2" = "" ] && return 0
Michael Bestasc3ad1cd2023-10-03 15:27:40 +030074 sed -i "s/android.hidl.base@1.0.so/libhidlbase.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/" "${2}"
75 ;;
Michael Bestas97432292024-08-27 00:21:27 +030076 vendor/lib64/hw/fingerprint.lahaina.so)
Michael Bestas7830bc12024-08-27 22:51:30 +030077 [ "$2" = "" ] && return 0
Michael Bestas97432292024-08-27 00:21:27 +030078 "${PATCHELF}" --set-soname fingerprint.lahaina.so "${2}"
79 ;;
Michael Bestas7830bc12024-08-27 22:51:30 +030080 *)
81 return 1
82 ;;
Michael Bestas411537b2020-12-28 00:58:46 +020083 esac
Michael Bestas7830bc12024-08-27 22:51:30 +030084
85 return 0
86}
87
88function blob_fixup_dry() {
89 blob_fixup "$1" ""
Michael Bestas411537b2020-12-28 00:58:46 +020090}
91
92# Initialize the helper
93setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}"
94
Michael Bestas7830bc12024-08-27 22:51:30 +030095if [ -z "${ONLY_FIRMWARE}" ]; then
96 extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}"
97fi
Michael Bestas411537b2020-12-28 00:58:46 +020098
Michael Bestasbfccf732022-02-22 19:22:26 +020099if [ -z "${SECTION}" ]; then
100 extract_firmware "${MY_DIR}/proprietary-firmware.txt" "${SRC}"
101fi
102
Michael Bestas411537b2020-12-28 00:58:46 +0200103"${MY_DIR}/setup-makefiles.sh"