From b4b0ba1f2c6349178da895caad5151f9c24c0e0b Mon Sep 17 00:00:00 2001 From: Wilhansen Li Date: Mon, 26 Dec 2016 21:05:16 +0800 Subject: [PATCH] Flip dtb ID entries. --- dtbTool.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dtbTool.c b/dtbTool.c index b5a1a8f..665ef78 100644 --- a/dtbTool.c +++ b/dtbTool.c @@ -84,6 +84,13 @@ int entry_cmp(uint8_t *a, uint8_t *b) return memcmp(a, b, INFO_ENTRY_SIZE); } +uint32_t swap_bytes_u32(uint32_t b) { + return ((b & 0xFF000000) >> 24) | + ((b & 0x00FF0000) >> 8) | + ((b & 0x0000FF00) << 8) | + (b << 24); +} + void print_help() { log_info("dtbTool [options] -o \n"); @@ -441,9 +448,20 @@ int main(int argc, char **argv) dtb size */ for (chip = chip_list; chip; chip = chip->next) { - wrote += write(out_fd, &chip->chipset, INFO_ENTRY_SIZE); - wrote += write(out_fd, &chip->platform, INFO_ENTRY_SIZE); - wrote += write(out_fd, &chip->revNum, INFO_ENTRY_SIZE); + /* for some reason, the id entries are flipped. */ + { + uint32_t *u32chipset = (uint32_t*)chip->chipset, + *u32platform = (uint32_t*)chip->platform, + *u32revNum = (uint32_t*)chip->revNum; + for ( int i = 0; i < INFO_ENTRY_SIZE/sizeof(uint32_t); ++i ) { + *(u32chipset + i) = swap_bytes_u32(*(u32chipset + i)); + *(u32platform + i) = swap_bytes_u32(*(u32platform + i)); + *(u32revNum + i) = swap_bytes_u32(*(u32revNum + i)); + } + } + wrote += write(out_fd, chip->chipset, INFO_ENTRY_SIZE); + wrote += write(out_fd, chip->platform, INFO_ENTRY_SIZE); + wrote += write(out_fd, chip->revNum, INFO_ENTRY_SIZE); wrote += write(out_fd, &expected, sizeof(uint32_t)); wrote += write(out_fd, &chip->dtb_size, sizeof(uint32_t)); expected += chip->dtb_size; -- 2.20.1