diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-05-30 13:01:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-30 13:01:21 +0200 |
commit | ea9553a215955c094fea786c4046ae25a40108f1 (patch) | |
tree | 53f95c75427f68c8554d36cf64b51ee2b579568e /iceprog | |
parent | 662117bceaefe71305e1ae3d97f400d917f359a6 (diff) | |
parent | e5e09ee722839123ea89d920de2a21460059d204 (diff) | |
download | icestorm-ea9553a215955c094fea786c4046ae25a40108f1.tar.gz icestorm-ea9553a215955c094fea786c4046ae25a40108f1.tar.bz2 icestorm-ea9553a215955c094fea786c4046ae25a40108f1.zip |
Merge pull request #144 from daveshah1/unbrick
Add write protection disable to iceprog
Diffstat (limited to 'iceprog')
-rw-r--r-- | iceprog/iceprog.c | 49 |
1 files changed, 46 insertions, 3 deletions
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) |