fix: 更新 device.mk 文件,移除 bootanim.rc 相关文件的引用,优化 magisk.py 中的主机架构检测逻辑,并新增 magisk.rc 文件以支持完整的构建流程。
This commit is contained in:
@@ -3,8 +3,6 @@ PRODUCT_PACKAGES += \
|
|||||||
magisk.apk
|
magisk.apk
|
||||||
|
|
||||||
PRODUCT_COPY_FILES += \
|
PRODUCT_COPY_FILES += \
|
||||||
vendor/magisk/magisk/system/etc/init/bootanim.rc:$(TARGET_COPY_OUT_SYSTEM)/etc/init/bootanim.rc \
|
|
||||||
vendor/magisk/magisk/system/etc/init/bootanim.rc.gz:$(TARGET_COPY_OUT_SYSTEM)/etc/init/bootanim.rc.gz \
|
|
||||||
vendor/magisk/magisk/system/etc/init/magisk/busybox:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/busybox:0755 \
|
vendor/magisk/magisk/system/etc/init/magisk/busybox:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/busybox:0755 \
|
||||||
vendor/magisk/magisk/system/etc/init/magisk/magisk:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/magisk:0755 \
|
vendor/magisk/magisk/system/etc/init/magisk/magisk:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/magisk:0755 \
|
||||||
vendor/magisk/magisk/system/etc/init/magisk/magiskboot:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/magiskboot:0755 \
|
vendor/magisk/magisk/system/etc/init/magisk/magiskboot:$(TARGET_COPY_OUT_SYSTEM)/etc/init/magisk/magiskboot:0755 \
|
||||||
|
|||||||
97
magisk.py
97
magisk.py
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import gzip
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -26,18 +25,27 @@ def download_file(url, file_path):
|
|||||||
|
|
||||||
|
|
||||||
def get_host_arch():
|
def get_host_arch():
|
||||||
"""获取主机架构"""
|
"""获取主机架构信息"""
|
||||||
machine = platform.machine().lower()
|
machine = platform.machine()
|
||||||
if machine in ['amd64', 'x86_64']:
|
|
||||||
return 'arm64' # 默认构建 arm64
|
mapping = {
|
||||||
elif machine in ['i386', 'i686', 'x86']:
|
"i686": ("x86", 32),
|
||||||
return 'arm64' # 默认构建 arm64
|
"x86_64": ("x86_64", 64),
|
||||||
elif machine in ['aarch64', 'arm64']:
|
"aarch64": ("arm64", 64),
|
||||||
return 'arm64'
|
"armv7l": ("arm", 32),
|
||||||
elif machine.startswith('arm'):
|
"armv8l": ("arm", 32)
|
||||||
return 'arm'
|
}
|
||||||
else:
|
if machine in mapping:
|
||||||
return 'arm64' # 默认返回 arm64
|
# if mapping[machine] == "x86_64":
|
||||||
|
# with open("/proc/cpuinfo") as f:
|
||||||
|
# if "sse4_2" not in f.read():
|
||||||
|
# print("x86_64 CPU does not support SSE4.2, falling back to x86...")
|
||||||
|
# return ("x86", 32)
|
||||||
|
return mapping[machine]
|
||||||
|
|
||||||
|
# 如果不在映射中,默认返回 arm64(适用于 Android 构建)
|
||||||
|
print(f"Warning: platform.machine '{machine}' architecture not recognized, defaulting to arm64")
|
||||||
|
return ("arm64", 64)
|
||||||
|
|
||||||
|
|
||||||
def run_command(cmd):
|
def run_command(cmd):
|
||||||
@@ -58,44 +66,7 @@ class Magisk:
|
|||||||
self.extract_to = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
|
self.extract_to = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp")
|
||||||
self.copy_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "magisk")
|
self.copy_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "magisk")
|
||||||
self.magisk_dir = os.path.join(self.copy_dir, "system", "etc", "init", "magisk")
|
self.magisk_dir = os.path.join(self.copy_dir, "system", "etc", "init", "magisk")
|
||||||
self.machine_arch = get_host_arch()
|
self.machine = get_host_arch() # 返回 (arch, bits) 元组
|
||||||
|
|
||||||
self.original_bootanim = """service bootanim /system/bin/bootanimation
|
|
||||||
class core animation
|
|
||||||
user graphics
|
|
||||||
group graphics audio
|
|
||||||
disabled
|
|
||||||
oneshot
|
|
||||||
ioprio rt 0
|
|
||||||
task_profiles MaxPerformance
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.bootanim_component = """on post-fs-data
|
|
||||||
start logd
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKSYSTEMDIR}/magiskpolicy --live --magisk
|
|
||||||
exec u:r:magisk:s0 root root -- {MAGISKSYSTEMDIR}/magiskpolicy --live --magisk
|
|
||||||
exec u:r:update_engine:s0 root root -- {MAGISKSYSTEMDIR}/magiskpolicy --live --magisk
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKSYSTEMDIR}/{magisk_name} --auto-selinux --setup-sbin {MAGISKSYSTEMDIR} {MAGISKTMP}
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --post-fs-data
|
|
||||||
|
|
||||||
on nonencrypted
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --service
|
|
||||||
|
|
||||||
on property:vold.decrypt=trigger_restart_framework
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --service
|
|
||||||
|
|
||||||
on property:sys.boot_completed=1
|
|
||||||
mkdir /data/adb/magisk 755
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --boot-complete
|
|
||||||
exec -- /system/bin/sh -c "if [ ! -e /data/data/io.github.huskydg.magisk ] ; then pm install /system/etc/init/magisk/magisk.apk ; fi"
|
|
||||||
|
|
||||||
on property:init.svc.zygote=restarting
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --zygote-restart
|
|
||||||
|
|
||||||
on property:init.svc.zygote=stopped
|
|
||||||
exec u:r:su:s0 root root -- {MAGISKTMP}/magisk --auto-selinux --zygote-restart
|
|
||||||
""".format(MAGISKSYSTEMDIR="/system/etc/init/magisk", MAGISKTMP="/sbin", magisk_name="magisk")
|
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
"""下载 Magisk APK"""
|
"""下载 Magisk APK"""
|
||||||
@@ -153,7 +124,7 @@ on property:init.svc.zygote=stopped
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 复制主要架构的库文件
|
# 复制主要架构的库文件
|
||||||
lib_dir = os.path.join(self.extract_to, "lib", arch_map[self.machine_arch])
|
lib_dir = os.path.join(self.extract_to, "lib", arch_map[self.machine[0]])
|
||||||
if os.path.exists(lib_dir):
|
if os.path.exists(lib_dir):
|
||||||
for parent, dirnames, filenames in os.walk(lib_dir):
|
for parent, dirnames, filenames in os.walk(lib_dir):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
@@ -177,30 +148,8 @@ on property:init.svc.zygote=stopped
|
|||||||
if os.path.exists(self.dl_file_name):
|
if os.path.exists(self.dl_file_name):
|
||||||
shutil.copyfile(self.dl_file_name, apk_dst)
|
shutil.copyfile(self.dl_file_name, apk_dst)
|
||||||
|
|
||||||
# 生成 bootanim.rc 文件
|
|
||||||
self._create_bootanim_rc()
|
|
||||||
|
|
||||||
print("==> Magisk installation completed!")
|
print("==> Magisk installation completed!")
|
||||||
|
|
||||||
def _create_bootanim_rc(self):
|
|
||||||
"""创建 bootanim.rc 文件"""
|
|
||||||
# 创建备份的 gzip 文件
|
|
||||||
bootanim_path = os.path.join(self.copy_dir, "system", "etc", "init", "bootanim.rc")
|
|
||||||
gz_filename = bootanim_path + ".gz"
|
|
||||||
|
|
||||||
# 确保目录存在
|
|
||||||
os.makedirs(os.path.dirname(bootanim_path), exist_ok=True)
|
|
||||||
|
|
||||||
# 创建 gzip 备份
|
|
||||||
with gzip.open(gz_filename, 'wb') as f_gz:
|
|
||||||
f_gz.write(self.original_bootanim.encode('utf-8'))
|
|
||||||
|
|
||||||
# 创建完整的 bootanim.rc
|
|
||||||
with open(bootanim_path, "w") as initfile:
|
|
||||||
initfile.write(self.original_bootanim + self.bootanim_component)
|
|
||||||
|
|
||||||
os.chmod(bootanim_path, 0o644)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""执行完整的构建流程"""
|
"""执行完整的构建流程"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
33
magisk.rc
Normal file
33
magisk.rc
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
service bootanim /system/bin/bootanimation
|
||||||
|
class core animation
|
||||||
|
user graphics
|
||||||
|
group graphics audio
|
||||||
|
disabled
|
||||||
|
oneshot
|
||||||
|
ioprio rt 0
|
||||||
|
task_profiles MaxPerformance
|
||||||
|
|
||||||
|
on post-fs-data
|
||||||
|
start logd
|
||||||
|
exec u:r:su:s0 root root -- /system/etc/init/magisk/magiskpolicy --live --magisk
|
||||||
|
exec u:r:magisk:s0 root root -- /system/etc/init/magisk/magiskpolicy --live --magisk
|
||||||
|
exec u:r:update_engine:s0 root root -- /system/etc/init/magisk/magiskpolicy --live --magisk
|
||||||
|
exec u:r:su:s0 root root -- /system/etc/init/magisk/magisk --auto-selinux --setup-sbin /system/etc/init/magisk /sbin
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --post-fs-data
|
||||||
|
|
||||||
|
on nonencrypted
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --service
|
||||||
|
|
||||||
|
on property:vold.decrypt=trigger_restart_framework
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --service
|
||||||
|
|
||||||
|
on property:sys.boot_completed=1
|
||||||
|
mkdir /data/adb/magisk 755
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --boot-complete
|
||||||
|
exec -- /system/bin/sh -c "if [ ! -e /data/data/io.github.huskydg.magisk ] ; then pm install /system/etc/init/magisk/magisk.apk ; fi"
|
||||||
|
|
||||||
|
on property:init.svc.zygote=restarting
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --zygote-restart
|
||||||
|
|
||||||
|
on property:init.svc.zygote=stopped
|
||||||
|
exec u:r:su:s0 root root -- /sbin/magisk --auto-selinux --zygote-restart
|
||||||
Reference in New Issue
Block a user