Let MagiskBoot handle dtb fstab patching

This commit is contained in:
topjohnwu 2021-01-14 06:20:12 -08:00
parent bb303d2da1
commit 76061296c9
2 changed files with 38 additions and 68 deletions

View File

@ -38,35 +38,32 @@ void FirstStageInit::prepare() {
rename("/.backup/init", "/init"); rename("/.backup/init", "/init");
} }
// Try to load fstab from dt
vector<fstab_entry> fstab;
read_dt_fstab(fstab);
char fstab_file[128]; char fstab_file[128];
fstab_file[0] = '\0'; fstab_file[0] = '\0';
// Find existing fstab file // Find existing fstab file
for (const char *hw : { cmd->fstab_suffix, cmd->hardware, cmd->hardware_plat }) { for (const char *suffix : { cmd->fstab_suffix, cmd->hardware, cmd->hardware_plat }) {
if (hw[0] == '\0') if (suffix[0] == '\0')
continue; continue;
sprintf(fstab_file, "fstab.%s", hw); for (const char *prefix: { "odm/etc/fstab", "vendor/etc/fstab", "fstab" }) {
sprintf(fstab_file, "%s.%s", prefix, suffix);
if (access(fstab_file, F_OK) != 0) { if (access(fstab_file, F_OK) != 0) {
fstab_file[0] = '\0'; fstab_file[0] = '\0';
continue;
} else { } else {
LOGD("Found fstab file: %s\n", fstab_file); LOGD("Found fstab file: %s\n", fstab_file);
break; goto exit_loop;
} }
} }
}
exit_loop:
if (fstab.empty()) {
// fstab has to be somewhere in ramdisk
if (fstab_file[0] == '\0') { if (fstab_file[0] == '\0') {
LOGE("Cannot find fstab file in ramdisk!\n"); LOGI("Cannot find fstab file in ramdisk!\n");
return; return;
} }
// Parse and load fstab file // Parse and load fstab file
vector<fstab_entry> fstab;
file_readline(fstab_file, [&](string_view l) -> bool { file_readline(fstab_file, [&](string_view l) -> bool {
if (l[0] == '#' || l.length() == 1) if (l[0] == '#' || l.length() == 1)
return true; return true;
@ -90,33 +87,6 @@ void FirstStageInit::prepare() {
fstab.emplace_back(std::move(entry)); fstab.emplace_back(std::move(entry));
return true; return true;
}); });
} else {
// All dt fstab entries should be first_stage_mount
for (auto &entry : fstab) {
if (!str_contains(entry.fsmgr_flags, "first_stage_mount")) {
if (!entry.fsmgr_flags.empty())
entry.fsmgr_flags += ',';
entry.fsmgr_flags += "first_stage_mount";
}
}
// Dump dt fstab to fstab file in rootfs
if (fstab_file[0] == '\0') {
const char *suffix =
cmd->fstab_suffix[0] ? cmd->fstab_suffix :
(cmd->hardware[0] ? cmd->hardware :
(cmd->hardware_plat[0] ? cmd->hardware_plat : nullptr));
if (suffix == nullptr) {
LOGE("Cannot determine fstab suffix!\n");
return;
}
sprintf(fstab_file, "fstab.%s", suffix);
}
// Patch init to force IsDtFstabCompatible() return false
auto init = mmap_data::rw("/init");
init.patch({ make_pair("android,fstab", "xxx") });
}
{ {
LOGD("Write fstab file: %s\n", fstab_file); LOGD("Write fstab file: %s\n", fstab_file);

View File

@ -207,7 +207,7 @@ static bool fdt_patch(void *fdt) {
int node; int node;
fdt_for_each_subnode(node, fdt, fstab) { fdt_for_each_subnode(node, fdt, fstab) {
const char *name = fdt_get_name(fdt, node, nullptr); const char *name = fdt_get_name(fdt, node, nullptr);
// Always patch verity if 2SI // Force remove AVB for 2SI since it may bootloop some devices
int len; int len;
auto value = (const char *) fdt_getprop(fdt, node, "fsmgr_flags", &len); auto value = (const char *) fdt_getprop(fdt, node, "fsmgr_flags", &len);
string copy(value, len); string copy(value, len);