Revert DTB fstab changes
This commit is contained in:
parent
76061296c9
commit
b100d0c503
@ -27,6 +27,6 @@ android.injected.testOnly=false
|
||||
kapt.incremental.apt=true
|
||||
|
||||
# Magisk
|
||||
magisk.versionCode=21201
|
||||
magisk.versionCode=21202
|
||||
magisk.ndkVersion=21d
|
||||
magisk.fullNdkVersion=21.3.6528147
|
||||
|
@ -57,36 +57,63 @@ void FirstStageInit::prepare() {
|
||||
}
|
||||
exit_loop:
|
||||
|
||||
if (fstab_file[0] == '\0') {
|
||||
LOGI("Cannot find fstab file in ramdisk!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse and load fstab file
|
||||
// Try to load dt fstab
|
||||
vector<fstab_entry> fstab;
|
||||
file_readline(fstab_file, [&](string_view l) -> bool {
|
||||
if (l[0] == '#' || l.length() == 1)
|
||||
read_dt_fstab(fstab);
|
||||
|
||||
if (!fstab.empty()) {
|
||||
// Dump dt fstab to fstab file in rootfs and force init to use it instead
|
||||
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
|
||||
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") });
|
||||
} else {
|
||||
// Parse and load the fstab file
|
||||
file_readline(fstab_file, [&](string_view l) -> bool {
|
||||
if (l[0] == '#' || l.length() == 1)
|
||||
return true;
|
||||
char *line = (char *) l.data();
|
||||
|
||||
int dev0, dev1, mnt_point0, mnt_point1, type0, type1,
|
||||
mnt_flags0, mnt_flags1, fsmgr_flags0, fsmgr_flags1;
|
||||
|
||||
sscanf(line, "%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n",
|
||||
&dev0, &dev1, &mnt_point0, &mnt_point1, &type0, &type1,
|
||||
&mnt_flags0, &mnt_flags1, &fsmgr_flags0, &fsmgr_flags1);
|
||||
|
||||
fstab_entry entry;
|
||||
|
||||
set_info(dev);
|
||||
set_info(mnt_point);
|
||||
set_info(type);
|
||||
set_info(mnt_flags);
|
||||
set_info(fsmgr_flags);
|
||||
|
||||
fstab.emplace_back(std::move(entry));
|
||||
return true;
|
||||
char *line = (char *) l.data();
|
||||
|
||||
int dev0, dev1, mnt_point0, mnt_point1, type0, type1,
|
||||
mnt_flags0, mnt_flags1, fsmgr_flags0, fsmgr_flags1;
|
||||
|
||||
sscanf(line, "%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n",
|
||||
&dev0, &dev1, &mnt_point0, &mnt_point1, &type0, &type1,
|
||||
&mnt_flags0, &mnt_flags1, &fsmgr_flags0, &fsmgr_flags1);
|
||||
|
||||
fstab_entry entry;
|
||||
|
||||
set_info(dev);
|
||||
set_info(mnt_point);
|
||||
set_info(type);
|
||||
set_info(mnt_flags);
|
||||
set_info(fsmgr_flags);
|
||||
|
||||
fstab.emplace_back(std::move(entry));
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
LOGD("Write fstab file: %s\n", fstab_file);
|
||||
|
@ -124,52 +124,37 @@ static void dtb_print(const char *file, bool fstab) {
|
||||
munmap(dtb, size);
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
static bool dtb_patch_rebuild(uint8_t *dtb, size_t dtb_sz, const char *file);
|
||||
|
||||
static bool dtb_patch(const char *file) {
|
||||
bool keep_verity = check_env("KEEPVERITY");
|
||||
bool have_system = false;
|
||||
vector<pair<char *, int>> flags_list;
|
||||
|
||||
size_t size;
|
||||
uint8_t *dtb;
|
||||
fprintf(stderr, "Loading dtbs from [%s]\n", file);
|
||||
mmap_rw(file, dtb, size);
|
||||
run_finally f([=]{ munmap(dtb, size); });
|
||||
|
||||
// First traverse through DTB to determine whether we need a rebuild
|
||||
int dtb_num = 0;
|
||||
bool patched = false;
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (memcmp(dtb + i, FDT_MAGIC_STR, 4) == 0) {
|
||||
auto fdt = dtb + i;
|
||||
if (int fstab = find_fstab(fdt); fstab >= 0) {
|
||||
int node;
|
||||
fdt_for_each_subnode(node, fdt, fstab) {
|
||||
const char *name = fdt_get_name(fdt, node, nullptr);
|
||||
if (!keep_verity) {
|
||||
int len;
|
||||
char *value = (char *) fdt_getprop(fdt, node, "fsmgr_flags", &len);
|
||||
flags_list.emplace_back(value, len);
|
||||
patched |= patch_verity(value, len) != len;
|
||||
}
|
||||
if (name == "system"sv)
|
||||
have_system = true;
|
||||
}
|
||||
}
|
||||
i += fdt_totalsize(fdt) - 1;
|
||||
++dtb_num;
|
||||
}
|
||||
}
|
||||
|
||||
if (!have_system) {
|
||||
// Patch in place with rw mmap
|
||||
bool patched = false;
|
||||
for (auto &[value, len] : flags_list)
|
||||
patched |= patch_verity(value, len) != len;
|
||||
return patched;
|
||||
} else {
|
||||
// Need to rebuild dtb due to additional props
|
||||
return dtb_patch_rebuild(dtb, size, file);
|
||||
}
|
||||
munmap(dtb, size);
|
||||
return patched;
|
||||
}
|
||||
|
||||
int dtb_commands(int argc, char *argv[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user