Merge pull request #230 from smunaut/fix_flash_reset

iceprog: Better reset of flash
diff --git a/icebox/icebox_vlog.py b/icebox/icebox_vlog.py
index 184cb03..a2c7950 100755
--- a/icebox/icebox_vlog.py
+++ b/icebox/icebox_vlog.py
@@ -750,8 +750,9 @@
         text_func.append("SB_RAM40_4K%s%s #(" % ("NR" if negclk_rd else "", "NW" if negclk_wr else ""));
         text_func.append("  .READ_MODE(%d)," % ((1 if get_ram_config('CBIT_2') else 0) + (2 if get_ram_config('CBIT_3') else 0)));
         text_func.append("  .WRITE_MODE(%d)," % ((1 if get_ram_config('CBIT_0') else 0) + (2 if get_ram_config('CBIT_1') else 0)));
-        for i in range(16):
-            text_func.append("  .INIT_%X(256'h%s)%s" % (i, ic.ram_data[tile][i], "," if i < 15 else ""));
+        if tile in ic.ram_data:
+            for i in range(16):
+                text_func.append("  .INIT_%X(256'h%s)%s" % (i, ic.ram_data[tile][i], "," if i < 15 else ""));
         text_func.append(") ram40_%d_%d (" % tile);
         text_func.append("  .WADDR(%s),"  % get_ram_wire('WADDR', 10, 0))
         text_func.append("  .RADDR(%s),"  % get_ram_wire('RADDR', 10, 0))
diff --git a/icepack/icepack.cc b/icepack/icepack.cc
index 5b1745a..d441042 100644
--- a/icepack/icepack.cc
+++ b/icepack/icepack.cc
@@ -912,7 +912,7 @@
 			ofs << '\n';
 		}
 
-		if (cic.tile_type == "ramb")
+		if (cic.tile_type == "ramb" && !this->bram.empty())
 		{
 			BramIndexConverter bic(this, x, y);
 			ofs << stringf(".ram_data %d %d\n", x, y);
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index 695e3ed..f38b133 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -35,6 +35,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#ifdef _WIN32
+#include <io.h> /* _setmode() */
+#include <fcntl.h> /* _O_BINARY */
+#endif
+
 #include "mpsse.h"
 
 static bool verbose = false;
@@ -521,6 +526,11 @@
 	const char *devstr = NULL;
 	int ifnum = 0;
 
+#ifdef _WIN32
+	_setmode(_fileno(stdin), _O_BINARY);
+	_setmode(_fileno(stdout), _O_BINARY);
+#endif
+
 	static struct option long_options[] = {
 		{"help", no_argument, NULL, -2},
 		{NULL, 0, NULL, 0}