diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 996682e..c760429 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -211,6 +211,27 @@ static int flash_io (int mode);
 static char *envmatch (char * s1, char * s2);
 static int parse_config (void);

+
+/*
+ * Returns 1 if it is MTD and 0 if it is not MTD
+ */
+static int fd_is_mtd(int fd)
+{
+	struct mtd_info_user mtdinfo;
+	int rc;
+
+	rc = ioctl(fd, MEMGETINFO, &mtdinfo);
+	if (rc < 0) {
+		/* Failed MEMGETINFO, not MTD */
+		return 0;
+	} else {
+		/* Succeeded, MTD */
+		return 1;
+	}
+}
+
+
+
 #if defined(CONFIG_FILE)
 static int get_config (char *);
 #endif
@@ -836,31 +857,35 @@ static int flash_write_buf (int dev, int fd,
void *buf, size_t count,

 	/* This only runs once on NOR flash and SPI-dataflash */
 	while (processed < write_total) {
-		rc = flash_bad_block (fd, mtd_type, &blockstart);
-		if (rc < 0)		/* block test failed */
-			return rc;
+		if (mtd_type != MTD_ABSENT)  {
+			rc = flash_bad_block(fd, mtd_type, &blockstart);
+			if (rc < 0)		/* block test failed */
+				return rc;

-		if (blockstart + erasesize > top_of_range) {
-			fprintf (stderr, "End of range reached, aborting\n");
-			return -1;
-		}
+			if (blockstart + erasesize > top_of_range) {
+				fprintf(stderr,
+					"End of range reached, aborting\n");
+				return -1;
+			}

-		if (rc) {		/* block is bad */
-			blockstart += blocklen;
-			continue;
-		}
+			if (rc) {		/* block is bad */
+				blockstart += blocklen;
+				continue;
+			}

-		erase.start = blockstart;
-		ioctl (fd, MEMUNLOCK, &erase);
+			erase.start = blockstart;
+			ioctl(fd, MEMUNLOCK, &erase);

-		/* Dataflash does not need an explicit erase cycle */
-		if (mtd_type != MTD_DATAFLASH)
-			if (ioctl (fd, MEMERASE, &erase) != 0) {
-				fprintf (stderr, "MTD erase error on %s: %s\n",
-					 DEVNAME (dev),
-					 strerror (errno));
-				return -1;
-			}
+			/* Dataflash does not need an explicit erase cycle */
+			if (mtd_type != MTD_DATAFLASH)
+				if (ioctl(fd, MEMERASE, &erase) != 0) {
+					fprintf(stderr,
+						"MTD erase error on %s: %s\n",
+						DEVNAME(dev),
+						strerror(errno));
+					return -1;
+				}
+		}

 		if (lseek (fd, blockstart, SEEK_SET) == -1) {
