Support A only System-as-root Devices

Most Chinese devices (and supposedly Galaxy S10) running Android Pie
is using system-as-root without A/B partition.

https://source.android.com/devices/bootloader/system-as-root#about-system-as-root

According to the docs above, these devices will have a ramdisk block
with size 0 in their boot images. Since magiskinit can run independently
on system-as-root devices, we simply just create an empty ramdisk with
magiskinit added as init.

Huge thanks to @vvb2060 for the heads up and original PR.
Close #980, close #1102
This commit is contained in:
topjohnwu
2019-02-28 05:46:36 -05:00
parent 99d6bd8efc
commit e72c6685ed
4 changed files with 43 additions and 20 deletions

View File

@@ -22,6 +22,7 @@ static const char *MAGISK_LIST[] =
class magisk_cpio : public cpio_rw {
public:
magisk_cpio() = default;
explicit magisk_cpio(const char *filename) : cpio_rw(filename) {}
void patch(bool keepverity, bool keepforceencrypt);
int test();
@@ -140,6 +141,8 @@ void magisk_cpio::restore() {
}
void magisk_cpio::backup(const char *orig) {
if (access(orig, R_OK))
return;
entry_map bkup_entries;
string remv;
@@ -257,7 +260,9 @@ int cpio_commands(int argc, char *argv[]) {
++argv;
--argc;
magisk_cpio cpio(incpio);
magisk_cpio cpio;
if (access(incpio, R_OK) == 0)
cpio.load_cpio(incpio);
int cmdc;
char *cmdv[6];
@@ -305,7 +310,7 @@ int cpio_commands(int argc, char *argv[]) {
return 0;
}
} else if (cmdc == 3 && strcmp(cmdv[0], "mkdir") == 0) {
cpio.makedir(strtoul(cmdv[1], nullptr, 8), cmdv[2]);
cpio.mkdir(strtoul(cmdv[1], nullptr, 8), cmdv[2]);
} else if (cmdc == 3 && strcmp(cmdv[0], "ln") == 0) {
cpio.ln(cmdv[1], cmdv[2]);
} else if (cmdc == 4 && strcmp(cmdv[0], "add") == 0) {