diff --git a/extract-files.py b/extract-files.py new file mode 100644 index 0000000..ec89539 --- /dev/null +++ b/extract-files.py @@ -0,0 +1,84 @@ +#!/usr/bin/env -S PYTHONPATH=../../../tools/extract-utils python3 +# +# SPDX-FileCopyrightText: 2024 The LineageOS Project +# SPDX-License-Identifier: Apache-2.0 +# + +from extract_utils.file import File +from extract_utils.fixups_blob import ( + BlobFixupCtx, + blob_fixup, + blob_fixups_user_type, +) + +from extract_utils.main import ( + ExtractUtils, + ExtractUtilsModule, +) + + +namespace_imports = [ + 'device/xiaomi/sm6225-common', + 'vendor/xiaomi/sm6225-common', + 'hardware/qcom-caf/sm6225', + 'hardware/qcom-caf/wlan', + 'hardware/xiaomi', + 'vendor/qcom/opensource/commonsys-intf/display', + 'vendor/qcom/opensource/dataservices', + ] + + + +def blob_fixup_test_flag( + ctx: BlobFixupCtx, + file: File, + file_path: str, + *args, + **kargs, +): + with open(file_path, 'rb+') as f: + f.seek(1337) + f.write(b'\x01') + + +blob_fixups: blob_fixups_user_type = { + ('vendor/bin/hw/android.hardware.security.keymint-service-qti', 'vendor/lib64/libqtikeymint.so'): blob_fixup() + .add_needed('android.hardware.security.rkp-V3-ndk.so'), + ('vendor/lib64/hw/displayfeature.default.so'): blob_fixup() + .replace_needed('libstagefright_foundation.so', 'libstagefright_foundation-v33.so'), + 'libcodec2_hidl@1.0.so': blob_fixup() + .add_needed('libshim.so'), + 'vendor/lib64/vendor.libdpmframework.so': blob_fixup() + .add_needed('libhidlbase_shim.so'), + 'vendor/etc/seccomp_policy/c2audio.vendor.ext-arm64.policy': blob_fixup() + .add_line_if_missing('setsockopt: 1'), + ('vendor/lib64/hw/com.qti.chi.override.so', + 'vendor/lib64/libcamxcommonutils.so', + 'vendor/lib64/libmialgoengine.so', + 'vendor/lib64/hw/camera.qcom.so',): blob_fixup() + .add_needed('libprocessgroup_shim.so'), + 'vendor/etc/init/android.hardware.gnss-aidl-service-qti.rc': blob_fixup() + .regex_replace('group system gps radio vendor_qti_diag vendor_ssgtzd', 'group system gps radio vendor_qti_diag'), + 'vendor/etc/vintf/manifest/c2_manifest_vendor.xml': blob_fixup() + .regex_replace('.+DOLBY.+\n', ''), + 'vendor/bin/STFlashTool': blob_fixup() + .add_needed('libbase_shim.so'), + 'vendor/lib64/libwvhidl.so': blob_fixup() + .add_needed('libcrypto_shim.so') +} + +module = ExtractUtilsModule( + 'sm6225-common', + 'xiaomi', + blob_fixups=blob_fixups, + namespace_imports=namespace_imports, + check_elf=False, +) + +module.add_proprietary_file('proprietary-files-phone.txt').add_copy_files_guard( + 'TARGET_IS_TABLET', 'true', invert=True + ) + +if __name__ == '__main__': + utils = ExtractUtils.device(module) + utils.run() diff --git a/extract-files.sh b/extract-files.sh deleted file mode 100755 index b261a1f..0000000 --- a/extract-files.sh +++ /dev/null @@ -1,137 +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}/../../.." - -# Define the default patchelf version used to patch blobs -# This will also be used for utility functions like FIX_SONAME -# Older versions break some camera blobs for us -export PATCHELF_VERSION=0_17_2 - -export TARGET_ENABLE_CHECKELF=false - -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_TARGET= -KANG= -SECTION= - -while [ "${#}" -gt 0 ]; do - case "${1}" in - --only-common ) - ONLY_COMMON=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-qti|vendor/lib64/libqtikeymint.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}" - ;; - vendor/lib64/hw/displayfeature.default.so) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --replace-needed "libstagefright_foundation.so" "libstagefright_foundation-v33.so" "${2}" - ;; - vendor/bin/STFlashTool) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --add-needed "libbase_shim.so" "${2}" - ;; - vendor/bin/hw/vendor.qti.media.c2@1.0-service|vendor/bin/hw/vendor.qti.media.c2audio@1.0-service) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --replace-needed "libcodec2_hidl@1.0.so" "${2}" - "${PATCHELF}" --add-needed "libshim.so" "${2}" - ;; - vendor/bin/vendor.dpmd) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --replace-needed "vendor.libdpmframework.so" "${2}" - "${PATCHELF}" --add-needed "libshim.so" "${2}" - ;; - vendor/etc/seccomp_policy/atfwd@2.0.policy) - [ "$2" = "" ] && return 0 - grep -q "gettid: 1" "${2}" || echo "gettid: 1" >> "${2}" - ;; - vendor/lib64/vendor.libdpmframework.so) - [ "$2" = "" ] && return 0 - "${PATCHELF}" --add-needed "libhidlbase_shim.so" "${2}" - ;; - vendor/etc/media_codecs_khaje_iot.xml) - sed -i -E '/media_codecs_(google_audio|google_telephony|vendor_audio)/d' "${2}" - ;; - vendor/etc/init/hw/init.qcom.usb.rc) - sed -i 's/on charger/on property:init.svc.vendor.charger=running/g' "${2}" - ;; - vendor/etc/seccomp_policy/c2audio.vendor.ext-arm64.policy) - [ "$2" = "" ] && return 0 - grep -q "setsockopt: 1" "${2}" || echo "setsockopt: 1" >> "${2}" - ;; - *) - return 1 - ;; - esac - - return 0 -} - -function blob_fixup_dry() { - blob_fixup "$1" "" -} - -if [ -z "${ONLY_TARGET}" ]; then - # Initialize the helper for common device - setup_vendor "${DEVICE_COMMON}" "${VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}" - - extract "${MY_DIR}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" - extract "${MY_DIR}/proprietary-files-phone.txt" "${SRC}" "${KANG}" --section "${SECTION}" -fi - -if [ -z "${ONLY_COMMON}" ] && [ -s "${MY_DIR}/../${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - source "${MY_DIR}/../${DEVICE}/extract-files.sh" - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false "${CLEAN_VENDOR}" - - extract "${MY_DIR}/../${DEVICE}/proprietary-files.txt" "${SRC}" "${KANG}" --section "${SECTION}" -fi - -"${MY_DIR}/setup-makefiles.sh" diff --git a/setup-makefiles.py b/setup-makefiles.py new file mode 100644 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 c8b1ce8..0000000 --- a/setup-makefiles.sh +++ /dev/null @@ -1,54 +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}/../../.." - -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}" - -# Initialize the helper for common -setup_vendor "${DEVICE_COMMON}" "${VENDOR}" "${ANDROID_ROOT}" true - -# Warning headers and guards -write_headers "sapphire topaz xun" - -# The standard common blobs -write_makefiles "${MY_DIR}/proprietary-files.txt" true - -# Exclude blobs from tablet builds -printf '\n%s\n' 'ifneq ($(TARGET_IS_TABLET),true)' >> "$PRODUCTMK" - -write_makefiles "${MY_DIR}/proprietary-files-phone.txt" true - -printf '%s\n' 'endif' >> "$PRODUCTMK" - -# Finish -write_footers - -if [ -s "${MY_DIR}/../${DEVICE}/proprietary-files.txt" ]; then - # Reinitialize the helper for device - setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" false - - # Warning headers and guards - write_headers - - # The standard device blobs - write_makefiles "${MY_DIR}/../${DEVICE}/proprietary-files.txt" true - - # Finish - write_footers -fi