diff --git a/fdtextract.c b/fdtextract.c index 4bf02989c7cbf83b392f39cf4c46fd2b2a84b87e..d0d5a8c1ee34460cf613dc392500af2b5a05adfa 100644 --- a/fdtextract.c +++ b/fdtextract.c @@ -82,6 +82,8 @@ static int extract_image(char *buf, char *name, char *out) { char path[MAX_PATH_LEN]; int noffset; + unsigned int data_size, data_offset; + const fdt32_t *val; if (!out) { printf("Error: please specify output file name.\n"); @@ -97,6 +99,34 @@ static int extract_image(char *buf, char *name, char *out) printf("Extracting: %s to %s.\n", name, out); + /* Get offset of image. Try both relative and absolute offset. */ + val = fdt_getprop(buf, noffset, "data-offset", NULL); + if(val) { + /* Relative offset */ + data_offset = fdt32_to_cpu(*val); + data_offset += ((fdt_totalsize(buf) + 3) & ~3); + } else { + /* Absolute offset */ + val = fdt_getprop(buf, noffset, "data-position", NULL); + } + + if (!val) { + printf("Error: could get offset of image: %s.\n", name); + return -1; + } + + data_offset = fdt32_to_cpu(*val); + + /* Size */ + val = fdt_getprop(buf, noffset, "data-size", NULL); + if (!val) { + printf("Error: could get size of image: %s.\n", name); + return -1; + } + + data_size = fdt32_to_cpu(*val); + printf("Offset:0x%08x Size:0x%08x\n", data_offset, data_size); + return 0; }