aboutsummaryrefslogtreecommitdiff
path: root/iceprog/iceprog.c
diff options
context:
space:
mode:
Diffstat (limited to 'iceprog/iceprog.c')
-rw-r--r--iceprog/iceprog.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index d86e874..20c7c23 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -428,6 +428,16 @@ static void flash_wait()
}
+static void flash_unlock()
+{
+ fprintf(stderr, "unlocking flash...\n");
+
+ uint8_t data[1] = { FC_GBU };
+ flash_chip_select();
+ mpsse_xfer_spi(data, 1);
+ flash_chip_deselect();
+}
+
static void flash_disable_protection()
{
fprintf(stderr, "disable flash protection...\n");
@@ -530,6 +540,7 @@ static void help(const char *progname)
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, " -u unlock blocks globally after reset.\n");
fprintf(stderr, "\n");
fprintf(stderr, "Miscellaneous options:\n");
fprintf(stderr, " --help display this help and exit\n");
@@ -583,6 +594,7 @@ int main(int argc, char **argv)
bool disable_protect = false;
bool disable_verify = false;
bool disable_powerdown = false;
+ bool unlock = false;
const char *filename = NULL;
const char *devstr = NULL;
int ifnum = 0;
@@ -600,7 +612,7 @@ int main(int argc, char **argv)
/* Decode command line parameters */
int opt;
char *endptr;
- while ((opt = getopt_long(argc, argv, "d:i:I:rR:e:o:cbnStQvspXk", long_options, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "d:i:I:rR:e:o:cbnStQvspXku", long_options, NULL)) != -1) {
switch (opt) {
case 'd': /* device string */
devstr = optarg;
@@ -702,6 +714,9 @@ int main(int argc, char **argv)
case 'p': /* disable flash protect before erase/write */
disable_protect = true;
break;
+ case 'u': /* send global unlock command before erase / write */
+ unlock = true;
+ break;
case 'X': /* disable verification */
disable_verify = true;
break;
@@ -943,6 +958,12 @@ int main(int argc, char **argv)
flash_reset();
flash_power_up();
+ if (unlock)
+ {
+ flash_write_enable();
+ flash_unlock();
+ }
+
flash_read_id();