aboutsummaryrefslogtreecommitdiff
path: root/iceprog/iceprog.c
diff options
context:
space:
mode:
authorIan McIntyre <me@mciantyre.dev>2025-05-10 09:52:01 -0400
committerIan McIntyre <me@mciantyre.dev>2025-09-13 19:28:24 -0400
commit920544aad4c06521eeb20fe81e3cfc7c756ae7ce (patch)
tree004954d8613f8dc483cde7efcb1b4f285f95ca5c /iceprog/iceprog.c
parentf31c39cc2eadd0ab7f29f34becba1348ae9f8721 (diff)
iceprog: add option for global block unlockHEADmain
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.
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();