Skip to content
Snippets Groups Projects
Commit e92fb432 authored by Jonas Höglund's avatar Jonas Höglund
Browse files

Enable output of extrated file to stdout.

parent 152a2d96
Branches
No related tags found
No related merge requests found
...@@ -96,11 +96,6 @@ static int extract_image(char *buf, char *name, char *out) ...@@ -96,11 +96,6 @@ static int extract_image(char *buf, char *name, char *out)
unsigned int data_size, data_offset; unsigned int data_size, data_offset;
const fdt32_t *val; const fdt32_t *val;
if (!out) {
printf("Error: please specify output file name.\n");
return -1;
}
snprintf(path, MAX_PATH_LEN, "/images/%s", name); snprintf(path, MAX_PATH_LEN, "/images/%s", name);
noffset = fdt_path_offset(buf, path); noffset = fdt_path_offset(buf, path);
if (noffset < 0) { if (noffset < 0) {
...@@ -108,8 +103,6 @@ static int extract_image(char *buf, char *name, char *out) ...@@ -108,8 +103,6 @@ static int extract_image(char *buf, char *name, char *out)
return -1; return -1;
} }
printf("Extracting %s to %s.\n", name, out);
/* Get offset of image. Try both relative and absolute offset. */ /* Get offset of image. Try both relative and absolute offset. */
val = fdt_getprop(buf, noffset, "data-offset", NULL); val = fdt_getprop(buf, noffset, "data-offset", NULL);
if(val) { if(val) {
...@@ -135,11 +128,18 @@ static int extract_image(char *buf, char *name, char *out) ...@@ -135,11 +128,18 @@ static int extract_image(char *buf, char *name, char *out)
data_size = fdt32_to_cpu(*val); data_size = fdt32_to_cpu(*val);
fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666); /* If output file is provided, write to that file. If not, write
if (fd < 0) { to stdout. */
printf("Error opening output file %s.\n", out); if (out) {
return errno; fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
printf("Error opening output file %s.\n", out);
return errno;
}
} else {
fd = STDOUT_FILENO;
} }
count = write(fd, buf + data_offset, data_size); count = write(fd, buf + data_offset, data_size);
if (count < data_size) { if (count < data_size) {
printf("Error writing output file %s.\n", out); printf("Error writing output file %s.\n", out);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment