From 220ebbfb073a8059ae7146873e7f08922812cd6e Mon Sep 17 00:00:00 2001 From: chaptsand Date: Sun, 29 Dec 2024 16:38:46 +0800 Subject: [PATCH] sm8550-common: Switch to python extract_utils Change-Id: I4f93f1609599ee0afe3eee21ae8ab19fff6f24db --- extract-files.py | 88 ++++++++++++++++++++++++++ extract-files.sh | 151 --------------------------------------------- setup-makefiles.py | 1 + setup-makefiles.sh | 94 ---------------------------- 4 files changed, 89 insertions(+), 245 deletions(-) create mode 100755 extract-files.py delete mode 100755 extract-files.sh create mode 100755 setup-makefiles.py delete mode 100755 setup-makefiles.sh diff --git a/extract-files.py b/extract-files.py new file mode 100755 index 0000000..717afba --- /dev/null +++ b/extract-files.py @@ -0,0 +1,88 @@ +#!/usr/bin/env -S PYTHONPATH=../../../tools/extract-utils python3 +# +# SPDX-FileCopyrightText: 2024 The LineageOS Project +# SPDX-License-Identifier: Apache-2.0 +# + +from extract_utils.fixups_blob import ( + blob_fixup, + blob_fixups_user_type, +) +from extract_utils.fixups_lib import ( + lib_fixup_remove, + lib_fixups, + lib_fixups_user_type, +) +from extract_utils.main import ( + ExtractUtils, + ExtractUtilsModule, +) + +namespace_imports = [ + 'device/samsung/sm8550-common', + 'hardware/qcom-caf/sm8550', + 'hardware/qcom-caf/wlan', + 'hardware/samsung', + 'vendor/qcom/opensource/commonsys-intf/display', + 'vendor/qcom/opensource/commonsys/display', + 'vendor/qcom/opensource/dataservices', + 'vendor/qcom/opensource/display', +] + +def lib_fixup_vendor_suffix(lib: str, partition: str, *args, **kwargs): + return f'{lib}_{partition}' if partition == 'vendor' else None + + +lib_fixups: lib_fixups_user_type = { + **lib_fixups, + ( + 'vendor.qti.diaghal@1.0', + 'libsecril-client', + 'vendor.qti.hardware.fm@1.0', + 'libhyper', + ): lib_fixup_vendor_suffix, + ( + 'libagmclient', + 'libpalclient', + 'libwpa_client', + ): lib_fixup_remove, +} + +blob_fixups: blob_fixups_user_type = { + ('vendor/bin/hw/android.hardware.security.keymint-service', 'vendor/lib64/libskeymint10device.so', 'vendor/lib64/libskeymint_cli.so'): blob_fixup() + .add_needed('android.hardware.security.rkp-V3-ndk.so') + .replace_needed('libcrypto.so', 'libcrypto-v33.so') + .replace_needed('libcppbor_external.so', 'libcppbor.so'), + 'vendor/lib64/hw/gatekeeper.mdfpp.so': blob_fixup() + .replace_needed('libcrypto.so', 'libcrypto-v33.so'), + 'vendor/lib64/libsec-ril.so': blob_fixup() + .binary_regex_replace(b'ril.dds.call.ongoing', b'vendor.calls.slot_id') + .sig_replace('60 0E 40 F9 E1 03 15 AA 82 0C 80 52 E3 03 14 AA', '60 0E 40 F9 E1 03 15 AA 82 0C 80 52 30 08 0D D2'), + 'vendor/etc/vintf/manifest/sec_c2_manifest_default0_1_0.xml': blob_fixup() + .regex_replace('default0', 'software'), + 'vendor/etc/init/vendor.qti.media.c2audio@1.0-service.rc': blob_fixup() + .regex_replace('.*disabled.*\n', ''), + ('vendor/etc/media_codecs_kalama.xml', 'vendor/etc/media_codecs_kalama_vendor.xml'): blob_fixup() + .regex_replace('.*media_codecs_(google_audio|google_c2|google_telephony|google_video|vendor_audio).*\n', ''), + 'vendor/etc/seccomp_policy/atfwd@2.0.policy': blob_fixup() + .add_line_if_missing('gettid: 1'), + 'vendor/etc/seccomp_policy/qwesd@2.0.policy': blob_fixup() + .add_line_if_missing('gettid: 1') + .add_line_if_missing('pipe2: 1'), + 'vendor/lib64/libqcodec2_core.so': blob_fixup() + .add_needed('libcodec2_shim.so'), + 'vendor/lib64/unihal_android.so': blob_fixup() + .add_needed('libui_shim.so'), +} # fmt: skip + +module = ExtractUtilsModule( + 'sm8550-common', + 'samsung', + blob_fixups=blob_fixups, + lib_fixups=lib_fixups, + namespace_imports=namespace_imports, +) + +if __name__ == '__main__': + utils = ExtractUtils.device(module) + utils.run() diff --git a/extract-files.sh b/extract-files.sh deleted file mode 100755 index 141bad0..0000000 --- a/extract-files.sh +++ /dev/null @@ -1,151 +0,0 @@ -#!/bin/bash -# -# SPDX-FileCopyrightText: 2016 The CyanogenMod Project -# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project -# SPDX-License-Identifier: Apache-2.0 -# - -set -e - -# Load extract_utils and do some sanity checks -MY_DIR="${BASH_SOURCE%/*}" -if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi - -ANDROID_ROOT="${MY_DIR}/../../.." - -export TARGET_ENABLE_CHECKELF=true - -# If XML files don't have comments before the XML header, use this flag -# Can still be used with broken XML files by using blob_fixup -export TARGET_DISABLE_XML_FIXING=true - -HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" -if [ ! -f "${HELPER}" ]; then - echo "Unable to find helper script at ${HELPER}" - exit 1 -fi -source "${HELPER}" - -# Default to sanitizing the vendor folder before extraction -CLEAN_VENDOR=true - -ONLY_COMMON= -ONLY_FIRMWARE= -ONLY_TARGET= -KANG= -SECTION= - -while [ "${#}" -gt 0 ]; do - case "${1}" in - --only-common) - ONLY_COMMON=true - ;; - --only-firmware) - ONLY_FIRMWARE=true - ;; - --only-target) - ONLY_TARGET=true - ;; - -n | --no-cleanup) - CLEAN_VENDOR=false - ;; - -k | --kang) - KANG="--kang" - ;; - -s | --section) - SECTION="${2}" - shift - CLEAN_VENDOR=false - ;; - *) - SRC="${1}" - ;; - esac - shift -done - -if [ -z "${SRC}" ]; then - SRC="adb" -fi - -function blob_fixup() { - case "${1}" in - vendor/bin/hw/android.hardware.security.keymint-service|vendor/lib64/libskeymint10device.so|vendor/lib64/libskeymint_cli.so) - [ "$2" = "" ] && return 0 - grep -q "android.hardware.security.rkp-V3-ndk.so" "${2}" || ${PATCHELF} --add-needed "android.hardware.security.rkp-V3-ndk.so" "${2}" - ${PATCHELF} --replace-needed libcrypto.so libcrypto-v33.so "${2}" - ${PATCHELF} --replace-needed libcppbor_external.so libcppbor.so "${2}" - ;; - vendor/lib64/hw/gatekeeper.mdfpp.so) - [ "$2" = "" ] && return 0 - ${PATCHELF} --replace-needed libcrypto.so libcrypto-v33.so "${2}" - ;; - vendor/lib64/libsec-ril.so) - [ "$2" = "" ] && return 0 - xxd -p -c0 "${2}" | sed "s/600e40f9e10315aa820c8052e30314aa/600e40f9e10315aa820c8052030080d2/g" | xxd -r -p > "${2}".patched - mv "${2}".patched "${2}" - sed -i 's/ril.dds.call.ongoing/vendor.calls.slot_id/g' "${2}" - ;; - vendor/etc/vintf/manifest/sec_c2_manifest_default0_1_0.xml) - [ "$2" = "" ] && return 0 - sed -i 's/default0/software/g' "${2}" - ;; - vendor/etc/media_codecs_kalama.xml|vendor/etc/media_codecs_kalama_vendor.xml) - [ "$2" = "" ] && return 0 - sed -Ei "/media_codecs_(google_audio|google_c2|google_telephony|google_video|vendor_audio)/d" "${2}" - ;; - vendor/etc/seccomp_policy/atfwd@2.0.policy) - [ "$2" = "" ] && return 0 - grep -q "gettid: 1" "${2}" || echo -e "\ngettid: 1" >> "${2}" - ;; - vendor/etc/seccomp_policy/qwesd@2.0.policy) - [ "$2" = "" ] && return 0 - grep -q "gettid: 1" "${2}" || echo -e "\ngettid: 1" >> "${2}" - grep -q "pipe2: 1" "${2}" || echo -e "\npipe2: 1" >> "${2}" - ;; - vendor/lib64/libqcodec2_core.so) - [ "$2" = "" ] && return 0 - grep -q "libcodec2_shim.so" "${2}" || "${PATCHELF}" --add-needed "libcodec2_shim.so" "${2}" - ;; - vendor/etc/init/vendor.qti.media.c2audio@1.0-service.rc) - [ "$2" = "" ] && return 0 - sed -i '/disabled/d' "${2}" - ;; - vendor/lib64/unihal_android.so) - [ "$2" = "" ] && return 0 - grep -q libui_shim.so "$2" || "$PATCHELF" --add-needed libui_shim.so "$2" - ;; - *) - return 1 - ;; - esac - - return 0 -} - -function blob_fixup_dry() { - blob_fixup "$1" "" -} - -if [ -z "${ONLY_FIRMWARE}" ] && [ -z "${ONLY_TARGET}" ]; then - # Initialize the helper for common device - setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}" - - extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" -fi - -if [ -z "${ONLY_COMMON}" ] && [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - source "${MY_DIR}/../../${VENDOR}/${DEVICE}/extract-files.sh" - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" - - if [ -z "${ONLY_FIRMWARE}" ]; then - extract "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" - fi - - if [ -z "${SECTION}" ] && [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then - extract_firmware "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" "${SRC}" - fi -fi - -"${MY_DIR}/setup-makefiles.sh" diff --git a/setup-makefiles.py b/setup-makefiles.py new file mode 100755 index 0000000..32947cf --- /dev/null +++ b/setup-makefiles.py @@ -0,0 +1 @@ +#!./extract-files.py --regenerate_makefiles diff --git a/setup-makefiles.sh b/setup-makefiles.sh deleted file mode 100755 index 342c417..0000000 --- a/setup-makefiles.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# -# SPDX-FileCopyrightText: 2016 The CyanogenMod Project -# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project -# SPDX-License-Identifier: Apache-2.0 -# - -set -e - -# Load extract_utils and do some sanity checks -MY_DIR="${BASH_SOURCE%/*}" -if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi - -ANDROID_ROOT="${MY_DIR}/../../.." - -export TARGET_ENABLE_CHECKELF=true - -HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" -if [ ! -f "${HELPER}" ]; then - echo "Unable to find helper script at ${HELPER}" - exit 1 -fi -source "${HELPER}" - -function vendor_imports() { - cat <>"$1" - "device/samsung/sm8550-common", - "hardware/qcom-caf/sm8550", - "hardware/qcom-caf/wlan", - "hardware/samsung", - "vendor/qcom/opensource/commonsys/display", - "vendor/qcom/opensource/commonsys-intf/display", - "vendor/qcom/opensource/dataservices", - "vendor/samsung/sm8550-common", -EOF -} - -function lib_to_package_fixup_vendor_variants() { - if [ "$2" != "vendor" ]; then - return 1 - fi - - case "$1" in - vendor.qti.diaghal@1.0 | \ - libsecril-client | \ - vendor.qti.hardware.fm@1.0 | \ - libhyper) - echo "$1_vendor" - ;; - libagmclient | \ - libpalclient | \ - libwpa_client) ;; - *) - return 1 - ;; - esac -} - -function lib_to_package_fixup() { - lib_to_package_fixup_clang_rt_ubsan_standalone "$1" || - lib_to_package_fixup_proto_3_9_1 "$1" || - lib_to_package_fixup_vendor_variants "$@" -} - -# Initialize the helper for common -setup_vendor "${DEVICE_COMMON}" "${VENDOR_COMMON:-$VENDOR}" "${ANDROID_ROOT}" true - -# Warning headers and guards -write_headers "dm1q dm2q dm3q" - -# The standard common blobs -write_makefiles "${MY_DIR}/proprietary-files.txt" - -# Finish -write_footers - -if [ -s "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - source "${MY_DIR}/../../${VENDOR}/${DEVICE}/setup-makefiles.sh" - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false - - # Warning headers and guards - write_headers - - # The standard device blobs - write_makefiles "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-files.txt" - - if [ -f "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" ]; then - append_firmware_calls_to_makefiles "${MY_DIR}/../../${VENDOR}/${DEVICE}/proprietary-firmware.txt" - fi - - # Finish - write_footers -fi