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) {
init = make_unique<TestInit>(argv, &cmd);
} else if (cmd.force_normal_boot) {
init = make_unique<FirstStageInit>(argv, &cmd);
init = make_unique<ABFirstStageInit>(argv, &cmd);
} else if (cmd.system_as_root) {
if (access("/overlay", F_OK) == 0) /* Compatible mode */
init = make_unique<SARCompatInit>(argv, &cmd);
@ -217,6 +217,8 @@ int main(int argc, char *argv[]) {
decompress_ramdisk();
if (access("/sbin/recovery", F_OK) == 0)
init = make_unique<RecoveryInit>(argv, &cmd);
else if (access("/apex", F_OK) == 0)
init = make_unique<AFirstStageInit>(argv, &cmd);
else
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:
void prepare();
public:
FirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {};
ABFirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {};
void start() override {
prepare();
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 {
protected:
void early_mount() override;
@ -121,7 +132,7 @@ public:
};
/* ***********
* Normal SAR
* Legacy SAR
* ***********/
class SARInit : public SARCommon {

View File

@ -386,7 +386,7 @@ void SARCommon::patch_rootdir() {
#define FSR "/first_stage_ramdisk"
void FirstStageInit::prepare() {
void ABFirstStageInit::prepare() {
// Find fstab
DIR *dir = xopendir(FSR);
if (!dir)
@ -448,6 +448,14 @@ void FirstStageInit::prepare() {
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
static FILE *kmsg;
static int vprintk(const char *fmt, va_list ap) {