diff --git a/fdtextract.c b/fdtextract.c index 460f0fbb9ea84447f0a31ca5b40020d54071a05b..91040aa73a1da48622dd8d7fb8a6fac84a847192 100644 --- a/fdtextract.c +++ b/fdtextract.c @@ -96,11 +96,6 @@ static int extract_image(char *buf, char *name, char *out) unsigned int data_size, data_offset; const fdt32_t *val; - if (!out) { - printf("Error: please specify output file name.\n"); - return -1; - } - snprintf(path, MAX_PATH_LEN, "/images/%s", name); noffset = fdt_path_offset(buf, path); if (noffset < 0) { @@ -108,8 +103,6 @@ static int extract_image(char *buf, char *name, char *out) return -1; } - 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) { @@ -135,11 +128,18 @@ static int extract_image(char *buf, char *name, char *out) data_size = fdt32_to_cpu(*val); - fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { - printf("Error opening output file %s.\n", out); - return errno; + /* If output file is provided, write to that file. If not, write + to stdout. */ + if (out) { + 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); if (count < data_size) { printf("Error writing output file %s.\n", out);