pipa: Clean up extract files script
This commit is contained in:
committed by
gensis01
parent
7a46159969
commit
7b3919960b
315
extract-files.py
315
extract-files.py
@@ -1,294 +1,59 @@
|
||||
#!/usr/bin/env -S PYTHONPATH=../../../tools/extract-utils python3
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2016 The CyanogenMod Project
|
||||
# SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
|
||||
# SPDX-FileCopyrightText: 2024 The LineageOS Project
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
from extract_utils.fixups_blob import (
|
||||
blob_fixup,
|
||||
blob_fixups_user_type,
|
||||
)
|
||||
from extract_utils.fixups_lib import (
|
||||
lib_fixups,
|
||||
)
|
||||
from extract_utils.main import (
|
||||
ExtractUtils,
|
||||
ExtractUtilsModule,
|
||||
)
|
||||
|
||||
# Helper function to check if a command exists
|
||||
def is_command_available(command):
|
||||
return shutil.which(command) is not None
|
||||
|
||||
# Create proper fixup classes that have a run method
|
||||
class BatterySecretRcFixup(blob_fixup):
|
||||
def run(self, ctx, file_path, obj_file_path):
|
||||
"""Remove seclabel line from batterysecret rc file"""
|
||||
if not obj_file_path:
|
||||
return True
|
||||
with open(obj_file_path, 'r') as f:
|
||||
content = f.read()
|
||||
content = re.sub(r"seclabel u:r:batterysecret:s0\n", "", content)
|
||||
with open(obj_file_path, 'w') as f:
|
||||
f.write(content)
|
||||
return True
|
||||
|
||||
class CameraPostprocFixup(blob_fixup):
|
||||
def run(self, ctx, file_path, obj_file_path):
|
||||
"""Run sigscan on camera postproc library"""
|
||||
if not obj_file_path:
|
||||
return True
|
||||
|
||||
# Try a direct binary patch if sigscan isn't available
|
||||
try:
|
||||
with open(obj_file_path, 'rb') as f:
|
||||
content = f.read()
|
||||
|
||||
# Try to find the byte sequence that needs to be replaced
|
||||
pattern = b'\x9A\x0A\x00\x94'
|
||||
replacement = b'\x1F\x20\x03\xD5'
|
||||
|
||||
if pattern in content:
|
||||
content = content.replace(pattern, replacement)
|
||||
with open(obj_file_path, 'wb') as f:
|
||||
f.write(content)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fall back to sigscan if available
|
||||
sigscan_cmd = os.environ.get("SIGSCAN", "sigscan")
|
||||
if not is_command_available(sigscan_cmd):
|
||||
return True
|
||||
|
||||
try:
|
||||
subprocess.run([
|
||||
sigscan_cmd,
|
||||
"-p", "9A 0A 00 94",
|
||||
"-P", "1F 20 03 D5",
|
||||
"-f", obj_file_path
|
||||
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
class CameraQcomFixup(blob_fixup):
|
||||
def run(self, ctx, file_path, obj_file_path):
|
||||
"""Replace hex string in camera qcom library"""
|
||||
if not obj_file_path:
|
||||
return True
|
||||
try:
|
||||
with open(obj_file_path, 'rb') as f:
|
||||
content = f.read()
|
||||
|
||||
# Original replacement
|
||||
orig_pattern = b"\x73\x74\x5F\x6C\x69\x63\x65\x6E\x73\x65\x2E\x6C\x69\x63"
|
||||
replacement = b"\x63\x61\x6D\x65\x72\x61\x5F\x63\x6E\x66\x2E\x74\x78\x74"
|
||||
|
||||
if orig_pattern in content:
|
||||
content = content.replace(orig_pattern, replacement)
|
||||
|
||||
with open(obj_file_path, 'wb') as f:
|
||||
f.write(content)
|
||||
return True
|
||||
|
||||
# Try alternative patterns if the original one isn't found
|
||||
alt_pattern = b"st_license.lic"
|
||||
if alt_pattern in content:
|
||||
content = content.replace(alt_pattern, b"camera_cnf.txt")
|
||||
with open(obj_file_path, 'wb') as f:
|
||||
f.write(content)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
class WatermarkFixup(blob_fixup):
|
||||
def run(self, ctx, file_path, obj_file_path):
|
||||
"""Check and add libpiex_shim.so dependency"""
|
||||
if not obj_file_path:
|
||||
return True
|
||||
|
||||
patchelf_cmd = os.environ.get("PATCHELF", "patchelf")
|
||||
if not is_command_available(patchelf_cmd):
|
||||
return True
|
||||
|
||||
try:
|
||||
# First try using strings to check for the dependency
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["strings", obj_file_path],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
if "libpiex_shim.so" in result.stdout:
|
||||
return True
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
# Fall back to grep if strings fails
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["grep", "-q", "libpiex_shim.so", obj_file_path],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
if result.returncode == 0: # String found
|
||||
return True
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
pass
|
||||
|
||||
# Add the dependency if not found
|
||||
subprocess.run([
|
||||
patchelf_cmd,
|
||||
"--add-needed", "libpiex_shim.so",
|
||||
obj_file_path
|
||||
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return True
|
||||
|
||||
# Define blob fixups using class instances
|
||||
blob_fixups: blob_fixups_user_type = {
|
||||
'vendor/etc/init/init.batterysecret.rc': BatterySecretRcFixup(),
|
||||
'vendor/lib/hw/audio.primary.pipa.so': AudioPrimaryFixup(),
|
||||
'vendor/lib64/vendor.qti.hardware.camera.postproc@1.0-service-impl.so': CameraPostprocFixup(),
|
||||
'vendor/lib64/hw/camera.qcom.so': CameraQcomFixup(),
|
||||
'vendor/lib64/camera/components/com.mi.node.watermark.so': WatermarkFixup(),
|
||||
"vendor/etc/init/init.batterysecret.rc": blob_fixup()
|
||||
.regex_replace(r".*seclabel u:r:batterysecret:s0\n", ""),
|
||||
|
||||
"vendor/lib64/vendor.qti.hardware.camera.postproc@1.0-service-impl.so": blob_fixup()
|
||||
.binary_regex_replace(b"\x9A\x0A\x00\x94", b"\x1F\x20\x03\xD5"),
|
||||
|
||||
"vendor/lib64/hw/camera.qcom.so": blob_fixup()
|
||||
.binary_regex_replace(
|
||||
b"\x73\x74\x5F\x6C\x69\x63\x65\x6E\x73\x65\x2E\x6C\x69\x63",
|
||||
b"\x63\x61\x6D\x65\x72\x61\x5F\x63\x6E\x66\x2E\x74\x78\x74",
|
||||
),
|
||||
|
||||
"vendor/lib64/camera/components/com.mi.node.watermark.so": blob_fixup()
|
||||
.add_needed("libpiex_shim.so"),
|
||||
|
||||
"vendor/lib/libaudioroute_ext.so": blob_fixup()
|
||||
.replace_needed("libaudioroute.so", "libaudioroute-v34.so"),
|
||||
|
||||
"vendor/lib/hw/audio.primary.kona.so": blob_fixup()
|
||||
.replace_needed("libaudioroute.so", "libaudioroute-v34.so"),
|
||||
} # fmt: skip
|
||||
|
||||
# Check if a file path contains Dolby-related patterns
|
||||
def is_dolby_file(file_path):
|
||||
dolby_patterns = [
|
||||
"dolby", "Dolby", "DOLBY",
|
||||
"dax", "DAX", "Dax"
|
||||
]
|
||||
|
||||
for pattern in dolby_patterns:
|
||||
if pattern in file_path:
|
||||
return True
|
||||
return False
|
||||
namespace_imports = [
|
||||
'hardware/qcom-caf/common/libqti-perfd-client',
|
||||
'hardware/qcom-caf/sm8250',
|
||||
'vendor/qcom/opensource/display',
|
||||
'vendor/xiaomi/sm8250-common',
|
||||
]
|
||||
|
||||
module = ExtractUtilsModule(
|
||||
'pipa',
|
||||
'xiaomi',
|
||||
blob_fixups=blob_fixups,
|
||||
lib_fixups=lib_fixups,
|
||||
namespace_imports=namespace_imports,
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Parse command line arguments first
|
||||
parser = argparse.ArgumentParser(description='Extract proprietary blobs for Xiaomi Pad 6')
|
||||
parser.add_argument('-s', '--section', help='Extract only specified section')
|
||||
parser.add_argument('-p', '--path', help='Path to system image or directory')
|
||||
parser.add_argument('-k', '--kang', action='store_true', help='Force extraction')
|
||||
parser.add_argument('-n', '--no-cleanup', action='store_true', help='Skip cleanup')
|
||||
parser.add_argument('--skip-common', action='store_true', help='Skip extracting common blobs')
|
||||
parser.add_argument('--device-only', action='store_true', help='Extract only device-specific blobs')
|
||||
parser.add_argument('--common-only', '--only-common', action='store_true', help='Extract only common blobs')
|
||||
parser.add_argument('-q', '--quiet', action='store_true', help='Minimize output')
|
||||
parser.add_argument('--ignore-missing-dolby', action='store_true', default=True,
|
||||
help='Ignore errors for missing Dolby files')
|
||||
args, remaining_args = parser.parse_known_args()
|
||||
|
||||
# Always disable firmware extraction
|
||||
add_firmware = False
|
||||
|
||||
# Common module for sm8250-common
|
||||
common_device = 'sm8250-common'
|
||||
vendor = 'xiaomi'
|
||||
|
||||
# Create module for device (unless common-only mode)
|
||||
if not args.common_only:
|
||||
device_module = ExtractUtilsModule(
|
||||
'pipa',
|
||||
'xiaomi',
|
||||
blob_fixups=blob_fixups,
|
||||
add_firmware_proprietary_file=add_firmware,
|
||||
)
|
||||
|
||||
# Create ExtractUtils instance for device
|
||||
utils = ExtractUtils(device_module)
|
||||
|
||||
# Set options based on arguments
|
||||
utils.clean_vendor = not args.no_cleanup
|
||||
utils.kang = args.kang
|
||||
if args.section:
|
||||
utils.section = args.section
|
||||
if args.path:
|
||||
utils.source_path = args.path
|
||||
|
||||
if not args.quiet:
|
||||
print("Extracting Xiaomi Pad 6 proprietary blobs...")
|
||||
|
||||
# Process common device if requested
|
||||
if not (args.skip_common or args.device_only or args.section):
|
||||
common_file_path = f'{os.path.dirname(os.path.abspath(__file__))}/../../{vendor}/{common_device}/proprietary-files.txt'
|
||||
if os.path.exists(common_file_path):
|
||||
if not args.quiet:
|
||||
print("Processing common files...")
|
||||
|
||||
# Custom extraction function to handle common files with error handling for Dolby
|
||||
try:
|
||||
# Read proprietary-files.txt for the common device
|
||||
with open(common_file_path, 'r') as f:
|
||||
common_files = f.read().splitlines()
|
||||
|
||||
# Create module for common device
|
||||
common_module = ExtractUtilsModule(
|
||||
common_device,
|
||||
vendor,
|
||||
add_firmware_proprietary_file=add_firmware,
|
||||
)
|
||||
|
||||
common_utils = ExtractUtils(common_module)
|
||||
common_utils.clean_vendor = not args.no_cleanup
|
||||
common_utils.kang = args.kang
|
||||
|
||||
if args.path:
|
||||
common_utils.source_path = args.path
|
||||
|
||||
# Extract the common files
|
||||
try:
|
||||
common_utils.run()
|
||||
except Exception as e:
|
||||
if not args.quiet:
|
||||
print(f"Note: Error processing common files (this is expected if using a different firmware): {e}")
|
||||
# Continue execution even if common files extraction fails
|
||||
pass
|
||||
except Exception as e:
|
||||
if not args.quiet:
|
||||
print(f"Warning: Error setting up common files: {e}")
|
||||
# Continue execution even if setup fails
|
||||
pass
|
||||
|
||||
# Extract device-specific files unless common-only mode
|
||||
if not args.common_only:
|
||||
try:
|
||||
# Run for device
|
||||
if not args.quiet:
|
||||
print("Processing device files...")
|
||||
utils.run()
|
||||
except FileNotFoundError as e:
|
||||
# Skip error reporting for missing Dolby files
|
||||
if args.ignore_missing_dolby and is_dolby_file(str(e)):
|
||||
pass
|
||||
elif not args.quiet:
|
||||
print(f"Error: {e}")
|
||||
|
||||
# Continue with makefile generation if it was a specific section
|
||||
if args.section:
|
||||
if not args.quiet:
|
||||
print("Attempting to continue with available files...")
|
||||
try:
|
||||
utils.write_makefiles()
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Don't exit on errors that might be related to missing Dolby files
|
||||
if not (args.ignore_missing_dolby and "dolby" in str(e).lower()):
|
||||
sys.exit(1)
|
||||
|
||||
if not args.quiet:
|
||||
print("Extraction completed")
|
||||
utils = ExtractUtils.device_with_common(module, 'sm8250-common', module.vendor)
|
||||
utils.run()
|
||||
|
||||
@@ -17,12 +17,6 @@ $(call inherit-product, device/xiaomi/pipa/device.mk)
|
||||
# Inherit keys
|
||||
$(call inherit-product, vendor/lineage-priv/keys/keys.mk)
|
||||
|
||||
<<<<<<< HEAD:lineage_pipa.mk
|
||||
PRODUCT_NAME := lineage_pipa
|
||||
=======
|
||||
<<<<<<< HEAD:voltage_pipa.mk
|
||||
PRODUCT_NAME := voltage_pipa
|
||||
=======
|
||||
# Mist OS Flags
|
||||
MIST_BUILD_TYPE := OFFICIAL
|
||||
MISTOS_MAINTAINER := Mufasa
|
||||
@@ -31,10 +25,7 @@ TARGET_USES_PICO_GAPPS := true
|
||||
PRODUCT_NO_CAMERA := false
|
||||
TARGET_DISABLE_EPPE := true
|
||||
|
||||
|
||||
PRODUCT_NAME := lineage_pipa
|
||||
>>>>>>> d3fa1db (MistOS Bringup):lineage_pipa.mk
|
||||
>>>>>>> d0f68ef (pip:MistOS Bringup):voltage_pipa.mk
|
||||
PRODUCT_DEVICE := pipa
|
||||
PRODUCT_MANUFACTURER := Xiaomi
|
||||
PRODUCT_BRAND := Xiaomi
|
||||
@@ -45,17 +36,5 @@ TARGET_SUPPORTS_QUICK_TAP := false
|
||||
|
||||
PRODUCT_GMS_CLIENTID_BASE := android-xiaomi
|
||||
|
||||
# Axion specific
|
||||
AXION_CAMERA_REAR_INFO := 13
|
||||
AXION_CAMERA_FRONT_INFO := 8
|
||||
AXION_CPU_SMALL_CORES := 0,1,2,3
|
||||
AXION_CPU_BIG_CORES := 4,5,6,7
|
||||
AXION_MAINTAINER := Abdulwahab_(ai94iq)
|
||||
AXION_PROCESSOR := Qualcomm_Snapdragon_870
|
||||
TARGET_PREBUILT_BCR := false
|
||||
PRODUCT_NO_CAMERA := false
|
||||
TARGET_INCLUDE_MATLOG := true
|
||||
BYPASS_CHARGE_SUPPORTED := true
|
||||
|
||||
PRODUCT_BUILD_PROP_OVERRIDES += \
|
||||
BuildFingerprint=Xiaomi/pipa_global/pipa:13/RKQ1.211001.001/V816.0.7.0.UMZMIXM:user/release-keys
|
||||
|
||||
Reference in New Issue
Block a user