src: bring back LKM patching

This commit is contained in:
rifsxd
2025-05-26 02:38:51 +06:00
parent 39617497ca
commit 5fa1050e1b
18 changed files with 325 additions and 330 deletions

View File

@@ -62,65 +62,67 @@ enum Commands {
#[command(subcommand)]
command: Profile,
},
//
// /// Patch boot or init_boot images to apply KernelSU Next
// BootPatch {
// /// boot image path, if not specified, will try to find the boot image automatically
// #[arg(short, long)]
// boot: Option<PathBuf>,
//
// /// kernel image path to replace
// #[arg(short, long)]
// kernel: Option<PathBuf>,
//
// /// LKM module path to replace, if not specified, will use the builtin one
// #[arg(short, long)]
// module: Option<PathBuf>,
//
// /// init to be replaced
// #[arg(short, long, requires("module"))]
// init: Option<PathBuf>,
//
// /// will use another slot when boot image is not specified
// #[arg(short = 'u', long, default_value = "false")]
// ota: bool,
//
// /// Flash it to boot partition after patch
// #[arg(short, long, default_value = "false")]
// flash: bool,
//
// /// output path, if not specified, will use current directory
// #[arg(short, long, default_value = None)]
// out: Option<PathBuf>,
//
// /// magiskboot path, if not specified, will search from $PATH
// #[arg(long, default_value = None)]
// magiskboot: Option<PathBuf>,
//
// /// KMI version, if specified, will use the specified KMI
// #[arg(long, default_value = None)]
// kmi: Option<String>,
// },
//
// /// Restore boot or init_boot images patched by KernelSU Next
// BootRestore {
// /// boot image path, if not specified, will try to find the boot image automatically
// #[arg(short, long)]
// boot: Option<PathBuf>,
//
// /// Flash it to boot partition after patch
// #[arg(short, long, default_value = "false")]
// flash: bool,
//
// /// magiskboot path, if not specified, will search from $PATH
// #[arg(long, default_value = None)]
// magiskboot: Option<PathBuf>,
// },
/// Patch boot or init_boot images to apply KernelSU Next
BootPatch {
/// boot image path, if not specified, will try to find the boot image automatically
#[arg(short, long)]
boot: Option<PathBuf>,
/// kernel image path to replace
#[arg(short, long)]
kernel: Option<PathBuf>,
/// LKM module path to replace, if not specified, will use the builtin one
#[arg(short, long)]
module: Option<PathBuf>,
/// init to be replaced
#[arg(short, long, requires("module"))]
init: Option<PathBuf>,
/// will use another slot when boot image is not specified
#[arg(short = 'u', long, default_value = "false")]
ota: bool,
/// Flash it to boot partition after patch
#[arg(short, long, default_value = "false")]
flash: bool,
/// output path, if not specified, will use current directory
#[arg(short, long, default_value = None)]
out: Option<PathBuf>,
/// magiskboot path, if not specified, will search from $PATH
#[arg(long, default_value = None)]
magiskboot: Option<PathBuf>,
/// KMI version, if specified, will use the specified KMI
#[arg(long, default_value = None)]
kmi: Option<String>,
},
/// Restore boot or init_boot images patched by KernelSU Next
BootRestore {
/// boot image path, if not specified, will try to find the boot image automatically
#[arg(short, long)]
boot: Option<PathBuf>,
/// Flash it to boot partition after patch
#[arg(short, long, default_value = "false")]
flash: bool,
/// magiskboot path, if not specified, will search from $PATH
#[arg(long, default_value = None)]
magiskboot: Option<PathBuf>,
},
/// Show boot information
BootInfo {
#[command(subcommand)]
command: BootInfo,
},
/// For developers
Debug {
#[command(subcommand)]
@@ -354,17 +356,17 @@ pub fn run() -> Result<()> {
Debug::Test => assets::ensure_binaries(false),
},
// Commands::BootPatch {
// boot,
// init,
// kernel,
// module,
// ota,
// flash,
// out,
// magiskboot,
// kmi,
// } => crate::boot_patch::patch(boot, kernel, module, init, ota, flash, out, magiskboot, kmi), // DISBAND LKM MODE
Commands::BootPatch {
boot,
init,
kernel,
module,
ota,
flash,
out,
magiskboot,
kmi,
} => crate::boot_patch::patch(boot, kernel, module, init, ota, flash, out, magiskboot, kmi),
Commands::BootInfo { command } => match command {
BootInfo::CurrentKmi => {
let kmi = crate::boot_patch::get_current_kmi()?;
@@ -378,11 +380,11 @@ pub fn run() -> Result<()> {
return Ok(());
}
},
// Commands::BootRestore {
// boot,
// magiskboot,
// flash,
// } => crate::boot_patch::restore(boot, magiskboot, flash),
Commands::BootRestore {
boot,
magiskboot,
flash,
} => crate::boot_patch::restore(boot, magiskboot, flash),
};
if let Err(e) = &result {