Skip to content
Snippets Groups Projects
Commit cc2831ad authored by Andreas Gnau's avatar Andreas Gnau :speech_balloon:
Browse files

Support FIT-images with embedded data

Support the older way of storing image data directly inside the FIT
rather than after the FIT specified by offset or absolute position.
parent 573bf954
Branches
No related tags found
1 merge request!3Support FIT-images with embedded data
......@@ -92,10 +92,11 @@ static int list_images(char *buf)
static int extract_image(const char *file, char *name, char *out)
{
char path[MAX_PATH_LEN];
int noffset, fd, count;
unsigned int data_size, data_offset;
int noffset, fd, count, data_size;
unsigned int data_offset;
const fdt32_t *val;
char *buf;
char *data;
size_t len;
buf = utilfdt_read(file, &len);
......@@ -110,31 +111,37 @@ static int extract_image(const char *file, char *name, char *out)
return -1;
}
bool is_external = false;
/* Get offset of image. Try both relative and absolute offset. */
val = fdt_getprop(buf, noffset, "data-offset", NULL);
if(val) {
if ((val = fdt_getprop(buf, noffset, "data-offset", NULL))) {
/* Relative offset */
data_offset = fdt32_to_cpu(*val);
data_offset += ((fdt_totalsize(buf) + 3) & ~3);
} else {
is_external = true;
} else if ((val = fdt_getprop(buf, noffset, "data-position", NULL))) {
/* Absolute offset */
val = fdt_getprop(buf, noffset, "data-position", NULL);
if (!val) {
fprintf(stderr, "Error: could get offset of image: %s.\n", name);
return -1;
}
data_offset = fdt32_to_cpu(*val);
is_external = true;
}
/* Size */
val = fdt_getprop(buf, noffset, "data-size", NULL);
if (!val) {
fprintf(stderr, "Error: could get size of image: %s.\n", name);
return -1;
if (is_external) {
/* Size */
val = fdt_getprop(buf, noffset, "data-size", NULL);
if (!val) {
fprintf(stderr, "Error: Could not get image size: %s.\n", name);
return -1;
}
data = buf + data_offset;
data_size = fdt32_to_cpu(*val);
} else {
data = fdt_getprop(buf, noffset, "data", &data_size);
if (data_size < 0) {
fprintf(stderr, "Error: Could not get image data: %s.\n", name);
return -1;
}
}
data_size = fdt32_to_cpu(*val);
/* If output file is provided, write to that file. If not, write
to stdout. */
if (out) {
......@@ -147,7 +154,7 @@ static int extract_image(const char *file, char *name, char *out)
fd = STDOUT_FILENO;
}
count = write(fd, buf + data_offset, data_size);
count = write(fd, data, data_size);
if (count < data_size) {
fprintf(stderr, "Error writing output file %s.\n", out);
return errno;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment