Skip to content

Commit 7e04c91

Browse files
committed
Fix android 10+ support
1 parent 350f3ed commit 7e04c91

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

lib/inject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int inject_rd(const char *path)
326326
int inject_cmdline(struct bootimg *image)
327327
{
328328
int res = 0;
329-
char* custom_cmdline = "printk.devkmsg=on androidboot.android_dt_dir=/fakefstab/";
329+
char* custom_cmdline = "printk.devkmsg=on androidboot.android_dt_dir=/fakefsbat/";
330330

331331
char* cmdline = libbootimg_get_cmdline(&image->hdr);
332332
char* newcmdline = NULL;

multirom.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ void disable_dtb_fstab(char* partition) {
100100
if (access("status", F_OK)) {
101101
DIR* dir = opendir("/proc/device-tree/firmware/android");
102102
char** exclude_dirs = NULL;
103-
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefstab", exclude_dirs);
103+
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefsbat", exclude_dirs);
104104
FILE* fp = fopen("status", "w");
105105
fprintf(fp, "disabled");
106106
fclose(fp);
107107
}
108108
char path[256];
109-
sprintf(path, "/fakefstab/fstab/%s/status", partition);
109+
sprintf(path, "/fakefsbat/fstab/%s/status", partition);
110110
copy_file("/status", path);
111111
}
112112

113113
void remove_dtb_fstab() {
114114
mkdir("/dummy_fw", S_IFDIR);
115115
DIR* dir = opendir("/proc/device-tree/firmware/android");
116116
char** exclude_dirs = NULL;
117-
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefstab", exclude_dirs);
118-
if (!mount("/dummy_fw", "/fakefstab", "ext4", MS_BIND, "discard,nomblk_io_submit")) {
117+
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefsbat", exclude_dirs);
118+
if (!mount("/dummy_fw", "/fakefsbat", "ext4", MS_BIND, "discard,nomblk_io_submit")) {
119119
INFO("dummy dtb node bind mounted in procfs\n");
120120
} else {
121121
ERROR("dummy dtb node bind mount failed! %s\n", strerror(errno));
@@ -124,22 +124,32 @@ void remove_dtb_fstab() {
124124

125125
int multirom_is_android10() {
126126
if (!multirom_path_exists("/", "apex")) {
127+
INFO("APEX folder found\n");
128+
return 1;
129+
}
130+
if (!multirom_path_exists("/system", "system/bin/init")) {
131+
INFO("system/bin/init found\n");
127132
return 1;
128133
}
129134
char* initPath = "/main_init";
130135
if (!multirom_path_exists("/", "/.backup/init")) {
131136
initPath = "/.backup/init";
132137
}
133138

134-
char *addr;
139+
void *addr;
135140
int initfd = open(initPath, O_RDWR);
141+
INFO("open file %s result %d\n", initPath, initfd);
136142
struct stat st;
137143
lstat(initPath, &st);
138144
size_t size = st.st_size;
139-
addr = mmap(NULL, size, PROT_WRITE, MAP_SHARED, initfd, 0);
140-
int contains = strstr(addr, "selinux_setup") != NULL;
145+
addr = mmap(NULL, size, PROT_READ, MAP_SHARED, initfd, 0);
146+
if (addr == -1) {
147+
INFO("mmap error! %s\n", strerror(errno));
148+
}
149+
int contains = memmem(addr, size, "selinux_setup", 13) != NULL;
141150
munmap(addr, size);
142151
close(initfd);
152+
INFO("init contains selinux_setup %d\n", contains);
143153
return contains;
144154
}
145155

@@ -1972,6 +1982,7 @@ int multirom_prep_android_mounts(struct multirom_status *s, struct multirom_rom
19721982
asprintf(&system_path, "%s/system.sparse.img", rom->base_path);
19731983

19741984
if (!multirom_path_exists("/system", "init.rc") && !multirom_is_android10()) {
1985+
INFO("ROM is not android 10\n");
19751986
umount("/system");
19761987
mkdir_with_perms("/system_root", 0755, NULL, NULL);
19771988
multirom_mount_image(system_path, "/system_root", "ext4", MS_RDONLY, NULL);
@@ -1988,6 +1999,7 @@ int multirom_prep_android_mounts(struct multirom_status *s, struct multirom_rom
19881999
char* exclude_dirs[] = {"system", "vendor", "product", NULL};
19892000
copy_init_contents(dir, "/system_root", "/", true, exclude_dirs);
19902001
} else if (multirom_is_android10()) {
2002+
INFO("ROM is android 10+\n");
19912003
umount("/system");
19922004
mkdir_with_perms("/system_root", 0755, NULL, NULL);
19932005
multirom_mount_image(system_path, "/system_root", "ext4", MS_RDONLY, NULL);

no_kexec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ int nokexec_set_cmdline(char *secondary_path)
293293
{
294294
int res = 0;
295295
struct bootimg image;
296-
char* custom_cmdline = "androidboot.selinux=permissive printk.devkmsg=on androidboot.android_dt_dir=/fakefstab/";
296+
char* custom_cmdline = "androidboot.selinux=permissive printk.devkmsg=on androidboot.android_dt_dir=/fakefsbat/";
297297

298298
INFO(NO_KEXEC_LOG_TEXT ": Going to check the bootimg in primary slot for slevel\n");
299299

trampoline/trampoline.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,9 @@ int main(int argc, char *argv[])
736736
umount("/sys/kernel/debug");
737737
#endif
738738

739-
if (access("/fakefstab/", F_OK)) {
739+
if (access("/fakefsbat/", F_OK)) {
740740
DIR* dir = opendir("/proc/device-tree/firmware/android");
741-
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefstab", NULL);
741+
copy_dir_contents(dir, "/proc/device-tree/firmware/android", "/fakefsbat", NULL);
742742
//remove("/fakefstab/fstab/system/mnt_point");
743743
closedir(dir);
744744
//remove("/fakefstab/fstab/vendor/mnt_point");

0 commit comments

Comments
 (0)