diff --git a/native/jni/magiskboot/dtb.cpp b/native/jni/magiskboot/dtb.cpp index b1a009538..e9fef715b 100644 --- a/native/jni/magiskboot/dtb.cpp +++ b/native/jni/magiskboot/dtb.cpp @@ -41,6 +41,19 @@ struct qctable_v3 { uint32_t len; /* DTB size */ } __attribute__((packed)); +struct dtbh_hdr { + char magic[4]; /* "DTBH" */ + uint32_t version; /* DTBH version */ + uint32_t num_dtbs; /* Number of DTBs */ +} __attribute__((packed)); + +struct bhtable_v2 { + uint32_t cpu_info[5]; /* Some CPU info */ + uint32_t offset; /* DTB offset in DTBH */ + uint32_t len; /* DTB size */ + uint32_t space; /* 0x00000020 */ +}; + struct dtb_blob { void *fdt; uint32_t offset; @@ -215,8 +228,8 @@ static bool fdt_patch(Iter first, Iter last) { return modified; } -template -static int dtb_patch(const qcdt_hdr *hdr, const char *in, const char *out) { +template +static int dtb_patch(const Header *hdr, const char *in, const char *out) { map dtb_map; auto buf = reinterpret_cast(hdr); auto tables = reinterpret_cast(hdr + 1); @@ -295,14 +308,26 @@ static int dtb_patch(const char *in, const char *out) { auto hdr = reinterpret_cast(dtb); switch (hdr->version) { case 1: + fprintf(stderr, "QCDT v1\n"); return dtb_patch(hdr, in, out); case 2: + fprintf(stderr, "QCDT v2\n"); return dtb_patch(hdr, in, out); case 3: + fprintf(stderr, "QCDT v3\n"); return dtb_patch(hdr, in, out); default: return 1; } + } else if (memcmp(dtb, DTBH_MAGIC, 4) == 0) { + auto hdr = reinterpret_cast(dtb); + switch (hdr->version) { + case 2: + fprintf(stderr, "DTBH v2\n"); + return dtb_patch(hdr, in, out); + default: + return 1; + } } else { vector fdt_list; for (int i = 0; i < dtb_sz; ++i) { diff --git a/native/jni/magiskboot/format.h b/native/jni/magiskboot/format.h index 1552e5d7c..782cde54b 100644 --- a/native/jni/magiskboot/format.h +++ b/native/jni/magiskboot/format.h @@ -42,6 +42,7 @@ typedef enum { #define LG_BUMP_MAGIC "\x41\xa9\xe4\x67\x74\x4d\x1d\x1b\xa4\x29\xf2\xec\xea\x65\x52\x79" #define DHTB_MAGIC "\x44\x48\x54\x42\x01\x00\x00\x00" #define QCDT_MAGIC "QCDT" +#define DTBH_MAGIC "DTBH" #define SEANDROID_MAGIC "SEANDROIDENFORCE" #define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-" #define NOOKHD_RL_MAGIC "Red Loader"