Support GKIs without ramdisk

Fix #5819
This commit is contained in:
topjohnwu
2022-05-12 03:04:55 -07:00
parent 622e09862a
commit 985249c3d0
3 changed files with 17 additions and 2 deletions

View File

@@ -17,7 +17,15 @@ void FirstStageInit::prepare() {
cp_afc("/init" /* magiskinit */, REDIR_PATH);
unlink("/init");
xrename(backup_init(), "/init");
const char *orig_init = backup_init();
if (access(orig_init, F_OK) == 0) {
xrename(orig_init, "/init");
} else {
// If the backup init is missing, this means that the boot ramdisk
// was created from scratch, and the real init is in a separate CPIO,
// which is guaranteed to be placed at /system/bin/init.
xsymlink(INIT_PATH, "/init");
}
{
auto init = mmap_data("/init", true);