mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Add new build command avd_patch
This commit is contained in:
@ -180,6 +180,8 @@ void BootConfig::set(const kv_pairs &kv) {
|
||||
strlcpy(hardware_plat, value.data(), sizeof(hardware_plat));
|
||||
} else if (key == "androidboot.fstab_suffix") {
|
||||
strlcpy(fstab_suffix, value.data(), sizeof(fstab_suffix));
|
||||
} else if (key == "qemu") {
|
||||
emulator = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -193,6 +195,7 @@ void BootConfig::print() {
|
||||
LOGD("fstab_suffix=[%s]\n", fstab_suffix);
|
||||
LOGD("hardware=[%s]\n", hardware);
|
||||
LOGD("hardware.platform=[%s]\n", hardware_plat);
|
||||
LOGD("emulator=[%d]\n", emulator);
|
||||
}
|
||||
|
||||
#define read_dt(name, key) \
|
||||
@ -230,7 +233,7 @@ void load_kernel_info(BootConfig *config) {
|
||||
parse_prop_file("/.backup/.magisk", [=](auto key, auto value) -> bool {
|
||||
if (key == "RECOVERYMODE" && value == "true") {
|
||||
LOGD("Running in recovery mode, waiting for key...\n");
|
||||
config->skip_initramfs = !check_key_combo();
|
||||
config->skip_initramfs = config->emulator || !check_key_combo();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -6,6 +6,7 @@ struct BootConfig {
|
||||
bool skip_initramfs;
|
||||
bool force_normal_boot;
|
||||
bool rootwait;
|
||||
bool emulator;
|
||||
char slot[3];
|
||||
char dt_dir[64];
|
||||
char fstab_suffix[32];
|
||||
@ -66,6 +67,10 @@ protected:
|
||||
mmap_data magisk_config;
|
||||
std::string custom_rules_dir;
|
||||
|
||||
// When this boolean is set, this means we are currently
|
||||
// running magiskinit on legacy SAR AVD emulator
|
||||
bool avd_hack = false;
|
||||
|
||||
void mount_with_dt();
|
||||
bool patch_sepolicy(const char *file);
|
||||
void setup_tmp(const char *path);
|
||||
|
@ -158,12 +158,19 @@ void MagiskInit::mount_with_dt() {
|
||||
for (const auto &entry : fstab) {
|
||||
if (is_lnk(entry.mnt_point.data()))
|
||||
continue;
|
||||
// When we force AVD to disable SystemAsRoot, it will always add system
|
||||
// to dt fstab, which we actually have already mounted as root
|
||||
if (avd_hack && entry.mnt_point == "/system")
|
||||
continue;
|
||||
// Derive partname from dev
|
||||
sprintf(blk_info.partname, "%s%s", basename(entry.dev.data()), config->slot);
|
||||
setup_block(true);
|
||||
xmkdir(entry.mnt_point.data(), 0755);
|
||||
xmount(blk_info.block_dev, entry.mnt_point.data(), entry.type.data(), MS_RDONLY, nullptr);
|
||||
mount_list.push_back(entry.mnt_point);
|
||||
// When avd_hack is true, do not add any early mount partitions to mount_list
|
||||
// as we will actually forcefully disable original init's early mount
|
||||
if (!avd_hack)
|
||||
mount_list.push_back(entry.mnt_point);
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,6 +379,7 @@ void SARInit::early_mount() {
|
||||
xmkdir("/dev", 0755);
|
||||
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
|
||||
mount_list.emplace_back("/dev");
|
||||
avd_hack = config->emulator;
|
||||
mount_with_dt();
|
||||
}
|
||||
}
|
||||
@ -399,7 +407,7 @@ bool SecondStageInit::prepare() {
|
||||
void BaseInit::exec_init() {
|
||||
// Unmount in reverse order
|
||||
for (auto &p : reversed(mount_list)) {
|
||||
if (xumount(p.data()) == 0)
|
||||
if (xumount2(p.data(), MNT_DETACH) == 0)
|
||||
LOGD("Unmount [%s]\n", p.data());
|
||||
}
|
||||
execv("/init", argv);
|
||||
|
@ -234,6 +234,10 @@ void SARBase::patch_rootdir() {
|
||||
make_pair(SPLIT_PLAT_CIL, "xxx"), /* Force loading monolithic sepolicy */
|
||||
make_pair(MONOPOLICY, sepol) /* Redirect /sepolicy to custom path */
|
||||
});
|
||||
if (avd_hack) {
|
||||
// Force disable early mount on original init
|
||||
init.patch({ make_pair("android,fstab", "xxx") });
|
||||
}
|
||||
xmkdir(ROOTOVL, 0);
|
||||
int dest = xopen(ROOTOVL "/init", O_CREAT | O_WRONLY | O_CLOEXEC, 0);
|
||||
xwrite(dest, init.buf, init.sz);
|
||||
|
Reference in New Issue
Block a user