From 920544aad4c06521eeb20fe81e3cfc7c756ae7ce Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Sat, 10 May 2025 09:52:01 -0400 Subject: iceprog: add option for global block unlock Required for some Microchip flash memories. Tested against a SST26VF032. No strong reason to put it as a separate command line option. I'm leaving the part unlocked once the program returns. I should probably re-lock it. This part's lock command seems to be 0x8D, not the expected 0x7E. --- iceprog/iceprog.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'iceprog') 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(); -- cgit v1.2.3