Minor improvements in QCDT logic

This commit is contained in:
topjohnwu 2019-10-07 22:57:01 -04:00
parent dfc65b95f7
commit d6c2c821a4

View File

@ -223,11 +223,12 @@ static int dtb_patch(const qcdt_hdr *hdr, const char *in, const char *out) {
// Collect all dtbs // Collect all dtbs
for (int i = 0; i < hdr->num_dtbs; ++i) { for (int i = 0; i < hdr->num_dtbs; ++i) {
auto it = dtb_map.find(tables[i].offset); if (dtb_map.find(tables[i].offset) == dtb_map.end()) {
if (it == dtb_map.end()) { auto blob = buf + tables[i].offset;
auto fdt = xmalloc(tables[i].len + 256); int size = fdt_totalsize(blob);
memcpy(fdt, buf + tables[i].offset, tables[i].len); auto fdt = xmalloc(size + 256);
fdt_open_into(fdt, fdt, tables[i].len + 256); memcpy(fdt, blob, size);
fdt_open_into(fdt, fdt, size + 256);
dtb_map[tables[i].offset] = { fdt, tables[i].offset }; dtb_map[tables[i].offset] = { fdt, tables[i].offset };
} }
} }
@ -257,16 +258,15 @@ static int dtb_patch(const qcdt_hdr *hdr, const char *in, const char *out) {
// Write dtbs // Write dtbs
for (auto &val : dtb_map) { for (auto &val : dtb_map) {
write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR), page_size));
val.second.offset = lseek(fd, 0, SEEK_CUR); val.second.offset = lseek(fd, 0, SEEK_CUR);
auto fdt = val.second.fdt; auto fdt = val.second.fdt;
fdt_pack(fdt); fdt_pack(fdt);
int size = fdt_totalsize(fdt); int size = fdt_totalsize(fdt);
xwrite(fd, fdt, size); xwrite(fd, fdt, size);
val.second.len = do_align(size, page_size); val.second.len = do_align(size, page_size);
write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR), page_size));
free(fdt); free(fdt);
} }
write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR), page_size));
// Patch tables // Patch tables
auto tables_rw = reinterpret_cast<Table *>(addr + sizeof(qcdt_hdr)); auto tables_rw = reinterpret_cast<Table *>(addr + sizeof(qcdt_hdr));