From 0674841b948eb9a880425d2b1e680fd6521348d4 Mon Sep 17 00:00:00 2001 From: HDTianRu <103573273+HDTianRu@users.noreply.github.com> Date: Sat, 25 May 2024 11:09:06 +0800 Subject: [PATCH] ksud: Skip patch init_boot.img on kmi android12-xxx devices (#1744) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有一些设备(如ace2v),带了initboot,但ramdisk却在boot里,导致无法使用ota安装与直接安装,所以添加了个开关 因为本人开发环境有点简陋(mt管理器),而且对项目代码不太熟,合并前最好review一下( --- userspace/ksud/src/boot_patch.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index d62d446ed83a..c2661c68fc76 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -159,7 +159,11 @@ pub fn restore( let workdir = tmpdir.path(); let magiskboot = find_magiskboot(magiskboot_path, workdir)?; - let (bootimage, bootdevice) = find_boot_image(&image, false, false, workdir)?; + let kmi = get_current_kmi().unwrap_or_else(|_| String::from("")); + + let skip_init = kmi.starts_with("android12-"); + + let (bootimage, bootdevice) = find_boot_image(&image, skip_init, false, false, workdir)?; println!("- Unpacking boot image"); let status = Command::new(&magiskboot) @@ -309,7 +313,16 @@ fn do_patch( let tmpdir = tempdir::TempDir::new("KernelSU").context("create temp dir failed")?; let workdir = tmpdir.path(); - let (bootimage, bootdevice) = find_boot_image(&image, ota, is_replace_kernel, workdir)?; + let kmi = if let Some(kmi) = kmi { + kmi + } else { + get_current_kmi().context("Unknown KMI, please choose LKM manually")? + }; + + let skip_init = kmi.starts_with("android12-"); + + let (bootimage, bootdevice) = + find_boot_image(&image, skip_init, ota, is_replace_kernel, workdir)?; let bootimage = bootimage.display().to_string(); @@ -330,11 +343,6 @@ fn do_patch( std::fs::copy(kmod, kmod_file).context("copy kernel module failed")?; } else { // If kmod is not specified, extract from assets - let kmi = if let Some(kmi) = kmi { - kmi - } else { - get_current_kmi().context("Unknown KMI, please choose LKM manually")? - }; println!("- KMI: {kmi}"); let name = format!("{kmi}_kernelsu.ko"); assets::copy_assets_to_file(&name, kmod_file) @@ -537,6 +545,7 @@ fn find_magiskboot(magiskboot_path: Option, workdir: &Path) -> Result

, + skip_init: bool, ota: bool, is_replace_kernel: bool, workdir: &Path, @@ -564,7 +573,7 @@ fn find_boot_image( let init_boot_exist = Path::new(&format!("/dev/block/by-name/init_boot{slot_suffix}")).exists(); - let boot_partition = if !is_replace_kernel && init_boot_exist { + let boot_partition = if !is_replace_kernel && init_boot_exist && !skip_init { format!("/dev/block/by-name/init_boot{slot_suffix}") } else { format!("/dev/block/by-name/boot{slot_suffix}")