aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--icebox/icebox.py15
-rwxr-xr-xicebox/icebox_vlog.py11
-rw-r--r--iceprog/iceprog.c49
3 files changed, 64 insertions, 11 deletions
diff --git a/icebox/icebox.py b/icebox/icebox.py
index 36572c0..27bd243 100644
--- a/icebox/icebox.py
+++ b/icebox/icebox.py
@@ -174,12 +174,15 @@ class iceconfig:
if (x, y) in self.ipcon_tiles: return self.ipcon_tiles[(x, y)]
return None
- def pinloc_db(self):
- if self.device == "384": return pinloc_db["384-qn32"]
- if self.device == "1k": return pinloc_db["1k-tq144"]
- if self.device == "lm4k": return pinloc_db["lm4k-cm49"]
- if self.device == "5k": return pinloc_db["5k-sg48"]
- if self.device == "8k": return pinloc_db["8k-ct256"]
+ def pinloc_db(self, package = None):
+ if package is None:
+ if self.device == "384": return pinloc_db["384-qn32"]
+ if self.device == "1k": return pinloc_db["1k-tq144"]
+ if self.device == "lm4k": return pinloc_db["lm4k-cm49"]
+ if self.device == "5k": return pinloc_db["5k-sg48"]
+ if self.device == "8k": return pinloc_db["8k-ct256"]
+ else:
+ return pinloc_db[self.device + "-" + package]
assert False
def gbufin_db(self):
diff --git a/icebox/icebox_vlog.py b/icebox/icebox_vlog.py
index 873e4b2..5736011 100755
--- a/icebox/icebox_vlog.py
+++ b/icebox/icebox_vlog.py
@@ -25,6 +25,7 @@ check_ieren = False
check_driver = False
lookup_symbols = False
do_collect = False
+package = None
pcf_data = dict()
portnames = set()
unmatched_ports = set()
@@ -56,6 +57,10 @@ Usage: icebox_vlog [options] [bitmap.asc]
like -p, enable some hacks for pcf files created
by the iCEcube2 placer.
+ -d <package>
+ use the given package to obtain chip pin numbers,
+ rather than the default for a device
+
-c
collect multi-bit ports
@@ -68,7 +73,7 @@ Usage: icebox_vlog [options] [bitmap.asc]
sys.exit(0)
try:
- opts, args = getopt.getopt(sys.argv[1:], "sSlLap:P:n:cRD")
+ opts, args = getopt.getopt(sys.argv[1:], "sSlLap:P:n:d:cRD")
except:
usage()
@@ -111,6 +116,8 @@ for o, a in opts:
else:
pinloc = (line[2],)
pcf_data[pinloc] = p
+ elif o == "-d":
+ package = a
elif o == "-c":
do_collect = True
elif o == "-R":
@@ -285,7 +292,7 @@ for segs in sorted(ic.group_segments(extra_connections=extra_connections, extra_
idx = (s[0], s[1], int(match.group(1)))
p = "io_%d_%d_%d" % idx
if lookup_pins or pcf_data:
- for entry in ic.pinloc_db():
+ for entry in ic.pinloc_db(package):
if idx[0] == entry[1] and idx[1] == entry[2] and idx[2] == entry[3]:
if (entry[0],) in pcf_data:
p = pcf_data[(entry[0],)]
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index c7e0061..29d4c22 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -395,6 +395,31 @@ static void flash_wait()
fprintf(stderr, "\n");
}
+static void flash_disable_protection()
+{
+ fprintf(stderr, "disable flash protection...\n");
+
+ //WRSR 0x00
+ uint8_t data[2] = { 0x01, 0x00 };
+ set_gpio(0, 0);
+ xfer_spi(data, 2);
+ set_gpio(1, 0);
+
+ flash_wait();
+
+ //RDSR
+ data[0] = 0x5;
+
+ set_gpio(0, 0);\
+ xfer_spi(data, 2);
+ set_gpio(1, 0);
+
+ if(data[1] != 0x00)
+ fprintf(stderr, "failed to disable protection, SR now equal to 0x%02x (expected 0x00)\n", data[1]);
+
+}
+
+
static void help(const char *progname)
{
fprintf(stderr, "Simple programming tool for FTDI-based Lattice iCE programmers.\n");
@@ -433,6 +458,9 @@ static void help(const char *progname)
fprintf(stderr, " -b bulk erase entire flash before writing\n");
fprintf(stderr, " -e <size in bytes> erase flash as if we were writing that number of bytes\n");
fprintf(stderr, " -n do not erase flash before writing\n");
+ fprintf(stderr, " -p disable write protection before erasing or writing\n");
+ fprintf(stderr, " This can be useful if flash memory appears to be\n");
+ fprintf(stderr, " bricked and won't respond to erasing or programming.\n");
fprintf(stderr, "\n");
fprintf(stderr, "Miscellaneous options:\n");
fprintf(stderr, " --help display this help and exit\n");
@@ -481,6 +509,7 @@ int main(int argc, char **argv)
bool dont_erase = false;
bool prog_sram = false;
bool test_mode = false;
+ bool disable_protect = false;
const char *filename = NULL;
const char *devstr = NULL;
enum ftdi_interface ifnum = INTERFACE_A;
@@ -492,7 +521,7 @@ int main(int argc, char **argv)
int opt;
char *endptr;
- while ((opt = getopt_long(argc, argv, "d:I:rR:e:o:cbnStv", long_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "d:I:rR:e:o:cbnStvp", long_options, NULL)) != -1) {
switch (opt) {
case 'd':
devstr = optarg;
@@ -573,6 +602,9 @@ int main(int argc, char **argv)
case 'v':
verbose = true;
break;
+ case 'p':
+ disable_protect = true;
+ break;
case -2:
help(argv[0]);
return EXIT_SUCCESS;
@@ -593,6 +625,11 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
+ if (disable_protect && (read_mode || check_mode || prog_sram || test_mode)) {
+ fprintf(stderr, "%s: option `-p' only valid in programming mode\n", my_name);
+ return EXIT_FAILURE;
+ }
+
if (bulk_erase && (read_mode || check_mode || prog_sram || test_mode)) {
fprintf(stderr, "%s: option `-b' only valid in programming mode\n", my_name);
return EXIT_FAILURE;
@@ -624,9 +661,9 @@ int main(int argc, char **argv)
fprintf(stderr, "%s: too many arguments\n", my_name);
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
return EXIT_FAILURE;
- } else if (bulk_erase) {
+ } else if (bulk_erase || disable_protect) {
filename = "/dev/null";
- } else if (!test_mode && !erase_mode) {
+ } else if (!test_mode && !erase_mode && !disable_protect) {
fprintf(stderr, "%s: missing argument\n", my_name);
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
return EXIT_FAILURE;
@@ -864,6 +901,12 @@ int main(int argc, char **argv)
if (!read_mode && !check_mode)
{
+ if (disable_protect)
+ {
+ flash_write_enable();
+ flash_disable_protection();
+ }
+
if (!dont_erase)
{
if (bulk_erase)