2019-12-02 09:34:21 +00:00
|
|
|
#include <bitset>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2021-10-31 18:46:56 +00:00
|
|
|
#include <libfdt.h>
|
2019-02-25 04:09:34 +00:00
|
|
|
|
2022-05-12 09:03:42 +00:00
|
|
|
#include <base.hpp>
|
2017-09-14 18:52:27 +00:00
|
|
|
|
2020-03-09 08:50:30 +00:00
|
|
|
#include "magiskboot.hpp"
|
|
|
|
#include "dtb.hpp"
|
2021-03-03 04:37:37 +00:00
|
|
|
#include "format.hpp"
|
2017-09-14 18:52:27 +00:00
|
|
|
|
2019-09-20 07:05:14 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2019-10-09 03:49:21 +00:00
|
|
|
constexpr int MAX_DEPTH = 32;
|
|
|
|
static bitset<MAX_DEPTH> depth_set;
|
|
|
|
|
2019-09-20 07:05:14 +00:00
|
|
|
static void pretty_node(int depth) {
|
2020-12-31 06:11:24 +00:00
|
|
|
if (depth == 0)
|
|
|
|
return;
|
2019-09-20 07:05:14 +00:00
|
|
|
|
2020-12-31 06:11:24 +00:00
|
|
|
for (int i = 0; i < depth - 1; ++i)
|
|
|
|
printf(depth_set[i] ? "│ " : " ");
|
2019-09-21 09:30:04 +00:00
|
|
|
|
2020-12-31 06:11:24 +00:00
|
|
|
printf(depth_set[depth - 1] ? "├── " : "└── ");
|
2019-09-20 07:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pretty_prop(int depth) {
|
2020-12-31 06:11:24 +00:00
|
|
|
for (int i = 0; i < depth; ++i)
|
|
|
|
printf(depth_set[i] ? "│ " : " ");
|
2019-09-21 09:30:04 +00:00
|
|
|
|
2020-12-31 06:11:24 +00:00
|
|
|
printf(depth_set[depth] ? "│ " : " ");
|
2019-09-20 07:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_node(const void *fdt, int node = 0, int depth = 0) {
|
2020-12-31 06:11:24 +00:00
|
|
|
// Print node itself
|
|
|
|
pretty_node(depth);
|
|
|
|
printf("#%d: %s\n", node, fdt_get_name(fdt, node, nullptr));
|
|
|
|
|
|
|
|
// Print properties
|
|
|
|
depth_set[depth] = fdt_first_subnode(fdt, node) >= 0;
|
|
|
|
int prop;
|
|
|
|
fdt_for_each_property_offset(prop, fdt, node) {
|
|
|
|
pretty_prop(depth);
|
|
|
|
int size;
|
|
|
|
const char *name;
|
|
|
|
auto value = static_cast<const char *>(fdt_getprop_by_offset(fdt, prop, &name, &size));
|
|
|
|
|
|
|
|
bool is_str = !(size > 1 && value[0] == 0);
|
|
|
|
if (is_str) {
|
|
|
|
// Scan through value to see if printable
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
char c = value[i];
|
|
|
|
if (i == size - 1) {
|
|
|
|
// Make sure null terminate
|
|
|
|
is_str = c == '\0';
|
|
|
|
} else if ((c > 0 && c < 32) || c >= 127) {
|
|
|
|
is_str = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_str) {
|
|
|
|
printf("[%s]: [%s]\n", name, value);
|
|
|
|
} else {
|
|
|
|
printf("[%s]: <bytes>(%d)\n", name, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursive
|
|
|
|
if (depth_set[depth]) {
|
|
|
|
int child;
|
|
|
|
int prev = -1;
|
|
|
|
fdt_for_each_subnode(child, fdt, node) {
|
|
|
|
if (prev >= 0)
|
|
|
|
print_node(fdt, prev, depth + 1);
|
|
|
|
prev = child;
|
|
|
|
}
|
|
|
|
depth_set[depth] = false;
|
|
|
|
print_node(fdt, prev, depth + 1);
|
|
|
|
}
|
2017-10-07 14:08:10 +00:00
|
|
|
}
|
2017-09-14 18:52:27 +00:00
|
|
|
|
2019-09-21 09:30:04 +00:00
|
|
|
static int find_fstab(const void *fdt, int node = 0) {
|
2021-11-04 03:53:50 +00:00
|
|
|
if (auto name = fdt_get_name(fdt, node, nullptr); name && name == "fstab"sv)
|
2020-12-31 06:11:24 +00:00
|
|
|
return node;
|
|
|
|
int child;
|
|
|
|
fdt_for_each_subnode(child, fdt, node) {
|
|
|
|
int fstab = find_fstab(fdt, child);
|
|
|
|
if (fstab >= 0)
|
|
|
|
return fstab;
|
|
|
|
}
|
|
|
|
return -1;
|
2017-09-14 18:52:27 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 07:53:58 +00:00
|
|
|
static void dtb_print(const char *file, bool fstab) {
|
2020-12-31 06:11:24 +00:00
|
|
|
fprintf(stderr, "Loading dtbs from [%s]\n", file);
|
2021-11-30 09:50:55 +00:00
|
|
|
auto m = mmap_data(file);
|
2020-12-31 06:11:24 +00:00
|
|
|
// Loop through all the dtbs
|
|
|
|
int dtb_num = 0;
|
2021-11-30 09:50:55 +00:00
|
|
|
uint8_t * const end = m.buf + m.sz;
|
|
|
|
for (uint8_t *fdt = m.buf; fdt < end;) {
|
2021-03-03 04:37:37 +00:00
|
|
|
fdt = static_cast<uint8_t*>(memmem(fdt, end - fdt, DTB_MAGIC, sizeof(fdt32_t)));
|
2021-02-28 22:36:48 +00:00
|
|
|
if (fdt == nullptr)
|
|
|
|
break;
|
|
|
|
if (fstab) {
|
|
|
|
int node = find_fstab(fdt);
|
|
|
|
if (node >= 0) {
|
2021-11-30 09:50:55 +00:00
|
|
|
fprintf(stderr, "Found fstab in buf.%04d\n", dtb_num);
|
2021-02-28 22:36:48 +00:00
|
|
|
print_node(fdt, node);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-02-28 22:36:48 +00:00
|
|
|
} else {
|
2021-11-30 09:50:55 +00:00
|
|
|
fprintf(stderr, "Printing buf.%04d\n", dtb_num);
|
2021-02-28 22:36:48 +00:00
|
|
|
print_node(fdt);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-02-28 22:36:48 +00:00
|
|
|
++dtb_num;
|
|
|
|
fdt += fdt_totalsize(fdt);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
2017-10-07 14:08:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 03:48:00 +00:00
|
|
|
[[maybe_unused]]
|
2021-01-14 13:45:05 +00:00
|
|
|
static bool dtb_patch_rebuild(uint8_t *dtb, size_t dtb_sz, const char *file);
|
|
|
|
|
2020-05-05 08:03:09 +00:00
|
|
|
static bool dtb_patch(const char *file) {
|
2021-01-14 13:45:05 +00:00
|
|
|
bool keep_verity = check_env("KEEPVERITY");
|
|
|
|
|
2020-12-31 06:11:24 +00:00
|
|
|
fprintf(stderr, "Loading dtbs from [%s]\n", file);
|
2021-11-30 09:50:55 +00:00
|
|
|
auto m = mmap_data(file, true);
|
2021-01-14 13:45:05 +00:00
|
|
|
|
2021-01-15 03:48:00 +00:00
|
|
|
bool patched = false;
|
2021-11-30 09:50:55 +00:00
|
|
|
uint8_t * const end = m.buf + m.sz;
|
|
|
|
for (uint8_t *fdt = m.buf; fdt < end;) {
|
2021-03-03 04:37:37 +00:00
|
|
|
fdt = static_cast<uint8_t*>(memmem(fdt, end - fdt, DTB_MAGIC, sizeof(fdt32_t)));
|
2021-02-28 22:36:48 +00:00
|
|
|
if (fdt == nullptr)
|
|
|
|
break;
|
2021-10-31 04:20:10 +00:00
|
|
|
int node;
|
|
|
|
// Patch the chosen node for bootargs
|
|
|
|
fdt_for_each_subnode(node, fdt, 0) {
|
2021-11-04 03:53:50 +00:00
|
|
|
if (auto name = fdt_get_name(fdt, node, nullptr); !name || name != "chosen"sv)
|
2021-10-31 04:20:10 +00:00
|
|
|
continue;
|
|
|
|
int len;
|
2021-10-31 18:46:56 +00:00
|
|
|
if (auto value = fdt_getprop(fdt, node, "bootargs", &len)) {
|
|
|
|
if (void *skip = memmem(value, len, "skip_initramfs", 14)) {
|
2021-10-31 04:20:10 +00:00
|
|
|
fprintf(stderr, "Patch [skip_initramfs] -> [want_initramfs]\n");
|
|
|
|
memcpy(skip, "want", 4);
|
|
|
|
patched = true;
|
|
|
|
}
|
|
|
|
}
|
2021-10-31 18:46:56 +00:00
|
|
|
break;
|
2021-10-31 04:20:10 +00:00
|
|
|
}
|
2021-02-28 22:36:48 +00:00
|
|
|
if (int fstab = find_fstab(fdt); fstab >= 0) {
|
|
|
|
fdt_for_each_subnode(node, fdt, fstab) {
|
|
|
|
if (!keep_verity) {
|
|
|
|
int len;
|
|
|
|
char *value = (char *) fdt_getprop(fdt, node, "fsmgr_flags", &len);
|
|
|
|
patched |= patch_verity(value, len) != len;
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 22:36:48 +00:00
|
|
|
fdt += fdt_totalsize(fdt);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-15 03:48:00 +00:00
|
|
|
return patched;
|
2019-10-07 04:38:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 08:03:09 +00:00
|
|
|
int dtb_commands(int argc, char *argv[]) {
|
2020-12-31 06:11:24 +00:00
|
|
|
char *dtb = argv[0];
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
|
|
|
|
if (argv[0] == "print"sv) {
|
|
|
|
dtb_print(dtb, argc > 1 && argv[1] == "-f"sv);
|
|
|
|
return 0;
|
|
|
|
} else if (argv[0] == "patch"sv) {
|
|
|
|
if (!dtb_patch(dtb))
|
|
|
|
exit(1);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-05-05 08:03:09 +00:00
|
|
|
}
|
2019-12-02 09:34:21 +00:00
|
|
|
|
2020-05-05 08:03:09 +00:00
|
|
|
namespace {
|
2019-09-22 08:17:15 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
struct fdt_blob {
|
|
|
|
void *fdt;
|
|
|
|
uint32_t offset;
|
|
|
|
uint32_t len;
|
|
|
|
};
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
static bool fdt_patch(void *fdt) {
|
|
|
|
int fstab = find_fstab(fdt);
|
|
|
|
if (fstab < 0)
|
|
|
|
return false;
|
|
|
|
bool modified = false;
|
|
|
|
int node;
|
|
|
|
fdt_for_each_subnode(node, fdt, fstab) {
|
|
|
|
const char *name = fdt_get_name(fdt, node, nullptr);
|
2021-01-14 14:20:12 +00:00
|
|
|
// Force remove AVB for 2SI since it may bootloop some devices
|
2021-01-14 13:45:05 +00:00
|
|
|
int len;
|
|
|
|
auto value = (const char *) fdt_getprop(fdt, node, "fsmgr_flags", &len);
|
|
|
|
string copy(value, len);
|
|
|
|
uint32_t new_len = patch_verity(copy.data(), len);
|
|
|
|
if (new_len != len) {
|
|
|
|
modified = true;
|
|
|
|
fdt_setprop(fdt, node, "fsmgr_flags", copy.data(), new_len);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-14 13:45:05 +00:00
|
|
|
if (name == "system"sv) {
|
|
|
|
fprintf(stderr, "Setting [mnt_point] to [/system_root]\n");
|
|
|
|
fdt_setprop_string(fdt, node, "mnt_point", "/system_root");
|
|
|
|
modified = true;
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-14 13:45:05 +00:00
|
|
|
}
|
|
|
|
return modified;
|
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
#define MAX_FDT_GROWTH 256
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
template <class Table, class Header>
|
|
|
|
static bool dt_table_patch(const Header *hdr, const char *out) {
|
|
|
|
map<uint32_t, fdt_blob> dtb_map;
|
|
|
|
auto buf = reinterpret_cast<const uint8_t *>(hdr);
|
|
|
|
auto tables = reinterpret_cast<const Table *>(buf + sizeof(Header));
|
|
|
|
|
|
|
|
constexpr bool is_aosp = std::is_same_v<Header, dt_table_header>;
|
|
|
|
|
|
|
|
// AOSP DTB store ints in big endian
|
|
|
|
using endian_conv = uint32_t (*)(uint32_t);
|
|
|
|
endian_conv be_to_le;
|
|
|
|
endian_conv le_to_be;
|
|
|
|
if constexpr (is_aosp) {
|
|
|
|
be_to_le = fdt32_to_cpu;
|
|
|
|
le_to_be = cpu_to_fdt32;
|
|
|
|
} else {
|
|
|
|
be_to_le = le_to_be = [](uint32_t x) { return x; };
|
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
// Collect all dtbs
|
|
|
|
auto num_dtb = be_to_le(hdr->num_dtbs);
|
|
|
|
for (int i = 0; i < num_dtb; ++i) {
|
|
|
|
auto offset = be_to_le(tables[i].offset);
|
|
|
|
if (dtb_map.count(offset) == 0) {
|
|
|
|
auto blob = buf + offset;
|
|
|
|
uint32_t size = fdt_totalsize(blob);
|
|
|
|
auto fdt = xmalloc(size + MAX_FDT_GROWTH);
|
|
|
|
memcpy(fdt, blob, size);
|
|
|
|
fdt_open_into(fdt, fdt, size + MAX_FDT_GROWTH);
|
|
|
|
dtb_map[offset] = { fdt, offset };
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-14 13:45:05 +00:00
|
|
|
}
|
|
|
|
if (dtb_map.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Patch fdt
|
|
|
|
bool modified = false;
|
|
|
|
for (auto &[_, blob] : dtb_map)
|
|
|
|
modified |= fdt_patch(blob.fdt);
|
|
|
|
if (!modified)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unlink(out);
|
|
|
|
int fd = xopen(out, O_RDWR | O_CREAT | O_CLOEXEC, 0644);
|
|
|
|
|
|
|
|
// This value is only used if AOSP DTB
|
|
|
|
uint32_t total_size = 0;
|
|
|
|
|
|
|
|
// Copy headers and tables
|
|
|
|
total_size += xwrite(fd, buf, dtb_map.begin()->first);
|
|
|
|
|
|
|
|
// mmap rw to patch table values retroactively
|
|
|
|
auto mmap_sz = lseek(fd, 0, SEEK_CUR);
|
|
|
|
auto addr = (uint8_t *) xmmap(nullptr, mmap_sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
|
|
|
|
// Guess alignment using gcd
|
|
|
|
uint32_t align = 1;
|
|
|
|
if constexpr (!is_aosp) {
|
|
|
|
auto it = dtb_map.begin();
|
|
|
|
align = (it++)->first;
|
|
|
|
for (; it != dtb_map.end(); ++it)
|
|
|
|
align = binary_gcd(align, it->first);
|
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
// Write dtbs
|
|
|
|
for (auto &val : dtb_map) {
|
|
|
|
val.second.offset = lseek(fd, 0, SEEK_CUR);
|
|
|
|
auto fdt = val.second.fdt;
|
|
|
|
fdt_pack(fdt);
|
|
|
|
auto size = fdt_totalsize(fdt);
|
|
|
|
total_size += xwrite(fd, fdt, size);
|
|
|
|
if constexpr (!is_aosp) {
|
2021-11-30 03:56:37 +00:00
|
|
|
val.second.len = align_to(size, align);
|
|
|
|
write_zero(fd, align_padding(lseek(fd, 0, SEEK_CUR), align));
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-14 13:45:05 +00:00
|
|
|
free(fdt);
|
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
// Patch headers
|
|
|
|
if constexpr (is_aosp) {
|
|
|
|
auto hdr_rw = reinterpret_cast<Header *>(addr);
|
|
|
|
hdr_rw->total_size = le_to_be(total_size);
|
|
|
|
}
|
|
|
|
auto tables_rw = reinterpret_cast<Table *>(addr + sizeof(Header));
|
|
|
|
for (int i = 0; i < num_dtb; ++i) {
|
|
|
|
auto &blob = dtb_map[be_to_le(tables_rw[i].offset)];
|
|
|
|
tables_rw[i].offset = le_to_be(blob.offset);
|
|
|
|
tables_rw[i].len = le_to_be(blob.len);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
munmap(addr, mmap_sz);
|
|
|
|
close(fd);
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
static bool blob_patch(uint8_t *dtb, size_t dtb_sz, const char *out) {
|
|
|
|
vector<uint8_t *> fdt_list;
|
|
|
|
vector<uint32_t> padding_list;
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-02-28 22:36:48 +00:00
|
|
|
uint8_t * const end = dtb + dtb_sz;
|
|
|
|
for (uint8_t *curr = dtb; curr < end;) {
|
2021-03-03 04:37:37 +00:00
|
|
|
curr = static_cast<uint8_t*>(memmem(curr, end - curr, DTB_MAGIC, sizeof(fdt32_t)));
|
2021-02-28 22:36:48 +00:00
|
|
|
if (curr == nullptr)
|
|
|
|
break;
|
|
|
|
auto len = fdt_totalsize(curr);
|
|
|
|
auto fdt = static_cast<uint8_t *>(xmalloc(len + MAX_FDT_GROWTH));
|
|
|
|
memcpy(fdt, curr, len);
|
|
|
|
fdt_pack(fdt);
|
|
|
|
uint32_t padding = len - fdt_totalsize(fdt);
|
|
|
|
padding_list.push_back(padding);
|
|
|
|
fdt_open_into(fdt, fdt, len + MAX_FDT_GROWTH);
|
|
|
|
fdt_list.push_back(fdt);
|
|
|
|
curr += len;
|
2021-01-14 13:45:05 +00:00
|
|
|
}
|
2020-12-31 06:11:24 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
bool modified = false;
|
|
|
|
for (auto fdt : fdt_list)
|
|
|
|
modified |= fdt_patch(fdt);
|
|
|
|
if (!modified)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unlink(out);
|
|
|
|
int fd = xopen(out, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
|
|
|
|
|
|
|
|
for (int i = 0; i < fdt_list.size(); ++i) {
|
|
|
|
auto fdt = fdt_list[i];
|
|
|
|
fdt_pack(fdt);
|
|
|
|
// Only add padding back if it is anything meaningful
|
|
|
|
if (padding_list[i] > 4) {
|
|
|
|
auto len = fdt_totalsize(fdt);
|
|
|
|
fdt_set_totalsize(fdt, len + padding_list[i]);
|
|
|
|
}
|
|
|
|
xwrite(fd, fdt, fdt_totalsize(fdt));
|
|
|
|
free(fdt);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-01-14 13:45:05 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-10 17:30:33 +00:00
|
|
|
|
2021-03-03 04:37:37 +00:00
|
|
|
#define DTB_MATCH(s) BUFFER_MATCH(dtb, s)
|
2019-09-20 07:53:58 +00:00
|
|
|
|
2021-01-14 13:45:05 +00:00
|
|
|
static bool dtb_patch_rebuild(uint8_t *dtb, size_t dtb_sz, const char *file) {
|
2021-03-03 04:37:37 +00:00
|
|
|
if (DTB_MATCH(QCDT_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<qcdt_hdr*>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, "QCDT v1\n");
|
|
|
|
return dt_table_patch<qctable_v1>(hdr, file);
|
|
|
|
case 2:
|
|
|
|
fprintf(stderr, "QCDT v2\n");
|
|
|
|
return dt_table_patch<qctable_v2>(hdr, file);
|
|
|
|
case 3:
|
|
|
|
fprintf(stderr, "QCDT v3\n");
|
|
|
|
return dt_table_patch<qctable_v3>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-03 04:37:37 +00:00
|
|
|
} else if (DTB_MATCH(DTBH_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<dtbh_hdr *>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 2:
|
|
|
|
fprintf(stderr, "DTBH v2\n");
|
|
|
|
return dt_table_patch<bhtable_v2>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-03 04:37:37 +00:00
|
|
|
} else if (DTB_MATCH(PXADT_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<pxadt_hdr *>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, "PXA-DT v1\n");
|
|
|
|
return dt_table_patch<pxatable_v1>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2021-03-03 04:37:37 +00:00
|
|
|
} else if (DTB_MATCH(PXA19xx_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<pxa19xx_hdr *>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, "PXA-19xx v1\n");
|
|
|
|
return dt_table_patch<pxatable_v1>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-03 04:37:37 +00:00
|
|
|
} else if (DTB_MATCH(SPRD_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<sprd_hdr *>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, "SPRD v1\n");
|
|
|
|
return dt_table_patch<sprdtable_v1>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-03 04:37:37 +00:00
|
|
|
} else if (DTB_MATCH(DT_TABLE_MAGIC)) {
|
2021-01-14 13:45:05 +00:00
|
|
|
auto hdr = reinterpret_cast<dt_table_header *>(dtb);
|
|
|
|
switch (hdr->version) {
|
|
|
|
case 0:
|
|
|
|
fprintf(stderr, "DT_TABLE v0\n");
|
|
|
|
return dt_table_patch<dt_table_entry>(hdr, file);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return blob_patch(dtb, dtb_sz, file);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
2017-09-14 18:52:27 +00:00
|
|
|
}
|