Add support for A-only 2SI

This commit is contained in:
topjohnwu 2019-09-22 05:15:31 -04:00
parent 0e5a113a0c
commit ee0cef06a6
3 changed files with 29 additions and 8 deletions

View File

@ -207,7 +207,7 @@ int main(int argc, char *argv[]) {
if (run_test) { if (run_test) {
init = make_unique<TestInit>(argv, &cmd); init = make_unique<TestInit>(argv, &cmd);
} else if (cmd.force_normal_boot) { } else if (cmd.force_normal_boot) {
init = make_unique<FirstStageInit>(argv, &cmd); init = make_unique<ABFirstStageInit>(argv, &cmd);
} else if (cmd.system_as_root) { } else if (cmd.system_as_root) {
if (access("/overlay", F_OK) == 0) /* Compatible mode */ if (access("/overlay", F_OK) == 0) /* Compatible mode */
init = make_unique<SARCompatInit>(argv, &cmd); init = make_unique<SARCompatInit>(argv, &cmd);
@ -217,6 +217,8 @@ int main(int argc, char *argv[]) {
decompress_ramdisk(); decompress_ramdisk();
if (access("/sbin/recovery", F_OK) == 0) if (access("/sbin/recovery", F_OK) == 0)
init = make_unique<RecoveryInit>(argv, &cmd); init = make_unique<RecoveryInit>(argv, &cmd);
else if (access("/apex", F_OK) == 0)
init = make_unique<AFirstStageInit>(argv, &cmd);
else else
init = make_unique<LegacyInit>(argv, &cmd); init = make_unique<LegacyInit>(argv, &cmd);
} }

View File

@ -97,21 +97,32 @@ public:
} }
}; };
/* ******************* /* *************
* Logical Partitions * 2 Stage Init
* *******************/ * *************/
class FirstStageInit : public BaseInit { class ABFirstStageInit : public BaseInit {
protected: protected:
void prepare(); void prepare();
public: public:
FirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {}; ABFirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {};
void start() override { void start() override {
prepare(); prepare();
exec_init("/system/bin/init"); exec_init("/system/bin/init");
} }
}; };
class AFirstStageInit : public BaseInit {
protected:
void prepare();
public:
AFirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {};
void start() override {
prepare();
exec_init();
}
};
class SecondStageInit : public SARCommon { class SecondStageInit : public SARCommon {
protected: protected:
void early_mount() override; void early_mount() override;
@ -121,7 +132,7 @@ public:
}; };
/* *********** /* ***********
* Normal SAR * Legacy SAR
* ***********/ * ***********/
class SARInit : public SARCommon { class SARInit : public SARCommon {

View File

@ -386,7 +386,7 @@ void SARCommon::patch_rootdir() {
#define FSR "/first_stage_ramdisk" #define FSR "/first_stage_ramdisk"
void FirstStageInit::prepare() { void ABFirstStageInit::prepare() {
// Find fstab // Find fstab
DIR *dir = xopendir(FSR); DIR *dir = xopendir(FSR);
if (!dir) if (!dir)
@ -448,6 +448,14 @@ void FirstStageInit::prepare() {
rename("/overlay.d", FSR "/overlay.d"); rename("/overlay.d", FSR "/overlay.d");
} }
void AFirstStageInit::prepare() {
// Move stuffs for next stage
xmkdir("/system", 0755);
xmkdir("/system/bin", 0755);
rename("/init", "/system/bin/init");
rename("/.backup/init", "/init");
}
#ifdef MAGISK_DEBUG #ifdef MAGISK_DEBUG
static FILE *kmsg; static FILE *kmsg;
static int vprintk(const char *fmt, va_list ap) { static int vprintk(const char *fmt, va_list ap) {