Commit c42a51dc authored by topjohnwu's avatar topjohnwu

Add support to patch DTBH DTBs

Apparently, Qualcomm is not the only on creating weird DTB formats,
Samsung also have their own DTBH format for Exynos platforms.

Close #1902
parent da3fd92b
...@@ -41,6 +41,19 @@ struct qctable_v3 { ...@@ -41,6 +41,19 @@ struct qctable_v3 {
uint32_t len; /* DTB size */ uint32_t len; /* DTB size */
} __attribute__((packed)); } __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 { struct dtb_blob {
void *fdt; void *fdt;
uint32_t offset; uint32_t offset;
...@@ -215,8 +228,8 @@ static bool fdt_patch(Iter first, Iter last) { ...@@ -215,8 +228,8 @@ static bool fdt_patch(Iter first, Iter last) {
return modified; return modified;
} }
template <class Table> template <class Table, class Header>
static int dtb_patch(const qcdt_hdr *hdr, const char *in, const char *out) { static int dtb_patch(const Header *hdr, const char *in, const char *out) {
map<uint32_t, dtb_blob> dtb_map; map<uint32_t, dtb_blob> dtb_map;
auto buf = reinterpret_cast<const uint8_t *>(hdr); auto buf = reinterpret_cast<const uint8_t *>(hdr);
auto tables = reinterpret_cast<const Table *>(hdr + 1); auto tables = reinterpret_cast<const Table *>(hdr + 1);
...@@ -295,14 +308,26 @@ static int dtb_patch(const char *in, const char *out) { ...@@ -295,14 +308,26 @@ static int dtb_patch(const char *in, const char *out) {
auto hdr = reinterpret_cast<qcdt_hdr*>(dtb); auto hdr = reinterpret_cast<qcdt_hdr*>(dtb);
switch (hdr->version) { switch (hdr->version) {
case 1: case 1:
fprintf(stderr, "QCDT v1\n");
return dtb_patch<qctable_v1>(hdr, in, out); return dtb_patch<qctable_v1>(hdr, in, out);
case 2: case 2:
fprintf(stderr, "QCDT v2\n");
return dtb_patch<qctable_v2>(hdr, in, out); return dtb_patch<qctable_v2>(hdr, in, out);
case 3: case 3:
fprintf(stderr, "QCDT v3\n");
return dtb_patch<qctable_v3>(hdr, in, out); return dtb_patch<qctable_v3>(hdr, in, out);
default: default:
return 1; return 1;
} }
} else if (memcmp(dtb, DTBH_MAGIC, 4) == 0) {
auto hdr = reinterpret_cast<dtbh_hdr *>(dtb);
switch (hdr->version) {
case 2:
fprintf(stderr, "DTBH v2\n");
return dtb_patch<bhtable_v2>(hdr, in, out);
default:
return 1;
}
} else { } else {
vector<uint8_t *> fdt_list; vector<uint8_t *> fdt_list;
for (int i = 0; i < dtb_sz; ++i) { for (int i = 0; i < dtb_sz; ++i) {
......
...@@ -42,6 +42,7 @@ typedef enum { ...@@ -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 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 DHTB_MAGIC "\x44\x48\x54\x42\x01\x00\x00\x00"
#define QCDT_MAGIC "QCDT" #define QCDT_MAGIC "QCDT"
#define DTBH_MAGIC "DTBH"
#define SEANDROID_MAGIC "SEANDROIDENFORCE" #define SEANDROID_MAGIC "SEANDROIDENFORCE"
#define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-" #define TEGRABLOB_MAGIC "-SIGNED-BY-SIGNBLOB-"
#define NOOKHD_RL_MAGIC "Red Loader" #define NOOKHD_RL_MAGIC "Red Loader"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment