Skip to content

Commit

Permalink
ksud: Skip patch init_boot.img on kmi android12-xxx devices (#1744)
Browse files Browse the repository at this point in the history
有一些设备(如ace2v),带了initboot,但ramdisk却在boot里,导致无法使用ota安装与直接安装,所以添加了个开关
因为本人开发环境有点简陋(mt管理器),而且对项目代码不太熟,合并前最好review一下(
  • Loading branch information
HDTianRu authored May 25, 2024
1 parent 57a5f39 commit 0674841
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions userspace/ksud/src/boot_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -537,6 +545,7 @@ fn find_magiskboot(magiskboot_path: Option<PathBuf>, workdir: &Path) -> Result<P

fn find_boot_image(
image: &Option<PathBuf>,
skip_init: bool,
ota: bool,
is_replace_kernel: bool,
workdir: &Path,
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 0674841

Please sign in to comment.