mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-02 18:12:07 +00:00
Support custom legacy Sony devices with init.real setup
Custom ROM bring-ups of legacy Sony devices contain the following: /init (symlink to /bin/init_sony) /init.real (the "real" Android init) /bin/init_sony (this was /sbin/init_sony on Android <11) Kernel loads the ramdisk and starts /init -> /bin/init_sony /bin/init_sony does low-level device setup (see: https://github.com/LineageOS/android_device_sony_common/blob/lineage-18.1/init/init_main.cpp) /bin/init_sony unlinks /init and renames /init.real to /init /bin/init_sony starts /init Since init_sony needs to run first magiskinit needs to replace init.real instead, so add workarounds based on detection of init.real to boot patcher and uninstaller Thanks @115ek and @bleckdeth Fixes #3636 Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
@@ -252,6 +252,12 @@ bool check_two_stage() {
|
||||
if (access("/system/bin/init", F_OK) == 0)
|
||||
return true;
|
||||
// If we still have no indication, parse the original init and see what's up
|
||||
auto init = mmap_data::ro("/.backup/init");
|
||||
auto init = mmap_data::ro(backup_init());
|
||||
return init.contains("selinux_setup");
|
||||
}
|
||||
|
||||
const char *backup_init() {
|
||||
if (access("/.backup/init.real", F_OK) == 0)
|
||||
return "/.backup/init.real";
|
||||
return "/.backup/init";
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
RecoveryInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {}
|
||||
void start() override {
|
||||
LOGD("Ramdisk is recovery, abort\n");
|
||||
rename("/.backup/init", "/init");
|
||||
rename(backup_init(), "/init");
|
||||
rm_rf("/.backup");
|
||||
exec_init();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ bool unxz(int fd, const uint8_t *buf, size_t size);
|
||||
void load_kernel_info(BootConfig *config);
|
||||
bool check_two_stage();
|
||||
void setup_klog();
|
||||
const char *backup_init();
|
||||
|
||||
/***************
|
||||
* Base classes
|
||||
|
||||
@@ -289,7 +289,7 @@ void RootFSInit::early_mount() {
|
||||
self = mmap_data::ro("/init");
|
||||
|
||||
LOGD("Restoring /init\n");
|
||||
rename("/.backup/init", "/init");
|
||||
rename(backup_init(), "/init");
|
||||
|
||||
mount_with_dt();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void FirstStageInit::prepare() {
|
||||
xmkdirs(FSR "/system/bin", 0755);
|
||||
rename("/init" /* magiskinit */, FSR "/system/bin/init");
|
||||
symlink("/system/bin/init", FSR "/init");
|
||||
rename("/.backup/init", "/init");
|
||||
rename(backup_init(), "/init");
|
||||
|
||||
rename("/.backup", FSR "/.backup");
|
||||
rename("/overlay.d", FSR "/overlay.d");
|
||||
@@ -71,7 +71,7 @@ void FirstStageInit::prepare() {
|
||||
xmkdir("/system", 0755);
|
||||
xmkdir("/system/bin", 0755);
|
||||
rename("/init" /* magiskinit */ , "/system/bin/init");
|
||||
rename("/.backup/init", "/init");
|
||||
rename(backup_init(), "/init");
|
||||
}
|
||||
|
||||
char fstab_file[128];
|
||||
|
||||
Reference in New Issue
Block a user