diff --git a/fdtextract.c b/fdtextract.c
index d0d5a8c1ee34460cf613dc392500af2b5a05adfa..b00a51487c2d187b115a579748fe798d18c09617 100644
--- a/fdtextract.c
+++ b/fdtextract.c
@@ -26,7 +26,11 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/types.h>
 #include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
 
 #include <libfdt.h>
 #include <fdt.h>
@@ -81,7 +85,7 @@ static int list_images(char *buf)
 static int extract_image(char *buf, char *name, char *out)
 {
 	char path[MAX_PATH_LEN];
-	int noffset;
+	int noffset, fd, count;
 	unsigned int data_size, data_offset;
 	const fdt32_t *val;
 
@@ -127,6 +131,17 @@ static int extract_image(char *buf, char *name, char *out)
 	data_size = fdt32_to_cpu(*val);
 	printf("Offset:0x%08x Size:0x%08x\n", data_offset, data_size);
 
+	fd = open(out, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+	if (fd < 0) {
+		printf("Error opening output file %s.\n", out);
+		return errno;
+	}
+	count = write(fd, buf + data_offset, data_size);
+	if (count < data_size) {
+		printf("Error writing output file %s.\n", out);
+		return errno;
+	}
+
 	return 0;
 }