diff options
Diffstat (limited to 'iceprog')
-rw-r--r-- | iceprog/Makefile | 7 | ||||
-rw-r--r-- | iceprog/iceprog.c | 74 |
2 files changed, 63 insertions, 18 deletions
diff --git a/iceprog/Makefile b/iceprog/Makefile index 3cb07b8..f41263e 100644 --- a/iceprog/Makefile +++ b/iceprog/Makefile @@ -1,12 +1,5 @@ include ../config.mk -ifneq ($(shell uname -s),Darwin) - LDLIBS = -L/usr/local/lib -lm -else - LIBFTDI_NAME = $(shell $(PKG_CONFIG) --exists libftdi1 && echo ftdi1 || echo ftdi) - LDLIBS = -L/usr/local/lib -l$(LIBFTDI_NAME) -lm -endif - ifeq ($(STATIC),1) LDFLAGS += -static LDLIBS += $(shell for pkg in libftdi1 libftdi; do $(PKG_CONFIG) --silence-errors --static --libs $$pkg && exit; done; echo -lftdi; ) diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index b04fe65..8ee6443 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -96,16 +96,16 @@ enum flash_cmd { static void set_cs_creset(int cs_b, int creset_b) { uint8_t gpio = 0; - uint8_t direction = 0x93; + uint8_t direction = 0x03; - if (cs_b) { + if (!cs_b) { // ADBUS4 (GPIOL0) - gpio |= 0x10; + direction |= 0x10; } - if (creset_b) { + if (!creset_b) { // ADBUS7 (GPIOL3) - gpio |= 0x80; + direction |= 0x80; } mpsse_set_gpio(gpio, direction); @@ -180,7 +180,7 @@ static void flash_read_id() if (data[4] == 0xFF) fprintf(stderr, "Extended Device String Length is 0xFF, " - "this is likely a read error. Ignorig...\n"); + "this is likely a read error. Ignoring...\n"); else { // Read extended JEDEC ID bytes if (data[4] != 0) { @@ -202,9 +202,15 @@ static void flash_reset() { uint8_t data[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + // This disables CRM is if it was enabled flash_chip_select(); mpsse_xfer_spi(data, 8); flash_chip_deselect(); + + // This disables QPI if it was enable + flash_chip_select(); + mpsse_xfer_spi_bits(0xFF, 2); + flash_chip_deselect(); } static void flash_power_up() @@ -446,6 +452,34 @@ static void flash_disable_protection() } +static void flash_enable_quad() +{ + fprintf(stderr, "Enabling Quad operation...\n"); + + // Allow write + flash_write_enable(); + + // Write Status Register 2 <- 0x02 + uint8_t data[2] = { FC_WSR2, 0x02 }; + flash_chip_select(); + mpsse_xfer_spi(data, 2); + flash_chip_deselect(); + + flash_wait(); + + // Read Status Register 1 + data[0] = FC_RSR2; + + flash_chip_select(); + mpsse_xfer_spi(data, 2); + flash_chip_deselect(); + + if ((data[1] & 0x02) != 0x02) + fprintf(stderr, "failed to set QE=1, SR2 now equal to 0x%02x (expected 0x%02x)\n", data[1], data[1] | 0x02); + + fprintf(stderr, "SR2: %08x\n", data[1]); +} + // --------------------------------------------------------- // iceprog implementation // --------------------------------------------------------- @@ -484,6 +518,7 @@ static void help(const char *progname) fprintf(stderr, " -c do not write flash, only verify (`check')\n"); fprintf(stderr, " -S perform SRAM programming\n"); fprintf(stderr, " -t just read the flash ID sequence\n"); + fprintf(stderr, " -Q just set the flash QE=1 bit\n"); fprintf(stderr, "\n"); fprintf(stderr, "Erase mode (only meaningful in default mode):\n"); fprintf(stderr, " [default] erase aligned chunks of 64kB in write mode\n"); @@ -543,7 +578,7 @@ int main(int argc, char **argv) bool bulk_erase = false; bool dont_erase = false; bool prog_sram = false; - bool test_mode = false; + int test_mode = 0; bool slow_clock = false; bool disable_protect = false; bool disable_verify = false; @@ -565,7 +600,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:cbnStvspXk", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "d:i:I:rR:e:o:cbnStQvspXk", long_options, NULL)) != -1) { switch (opt) { case 'd': /* device string */ devstr = optarg; @@ -653,7 +688,10 @@ int main(int argc, char **argv) prog_sram = true; break; case 't': /* just read flash id */ - test_mode = true; + test_mode = 1; + break; + case 'Q': /* just read flash id */ + test_mode = 2; break; case 'v': /* provide verbose output */ verbose = true; @@ -682,7 +720,7 @@ int main(int argc, char **argv) /* Make sure that the combination of provided parameters makes sense */ - if (read_mode + erase_mode + check_mode + prog_sram + test_mode > 1) { + if (read_mode + erase_mode + check_mode + prog_sram + !!test_mode > 1) { fprintf(stderr, "%s: options `-r'/`-R', `-e`, `-c', `-S', and `-t' are mutually exclusive\n", my_name); return EXIT_FAILURE; } @@ -840,7 +878,10 @@ int main(int argc, char **argv) flash_reset(); flash_power_up(); - flash_read_id(); + if (test_mode == 1) + flash_read_id(); + else + flash_enable_quad(); flash_power_down(); @@ -966,10 +1007,14 @@ int main(int argc, char **argv) rc = fread(buffer, 1, page_size, f); if (rc <= 0) break; + fprintf(stderr, " \r"); + fprintf(stderr, "addr 0x%06X %3ld%%\r", rw_offset + addr, 100 * addr / file_size); flash_write_enable(); flash_prog(rw_offset + addr, buffer, rc); flash_wait(); } + fprintf(stderr, " \r"); + fprintf(stderr, "done.\n"); /* seek to the beginning for second pass */ fseek(f, 0, SEEK_SET); @@ -984,9 +1029,13 @@ int main(int argc, char **argv) fprintf(stderr, "reading..\n"); for (int addr = 0; addr < read_size; addr += 256) { uint8_t buffer[256]; + fprintf(stderr, " \r"); + fprintf(stderr, "addr 0x%06X %3d%%\r", rw_offset + addr, 100 * addr / read_size); flash_read(rw_offset + addr, buffer, 256); fwrite(buffer, read_size - addr > 256 ? 256 : read_size - addr, 1, f); } + fprintf(stderr, " \r"); + fprintf(stderr, "done.\n"); } else if (!erase_mode && !disable_verify) { fprintf(stderr, "reading..\n"); for (int addr = 0; true; addr += 256) { @@ -994,6 +1043,8 @@ int main(int argc, char **argv) int rc = fread(buffer_file, 1, 256, f); if (rc <= 0) break; + fprintf(stderr, " \r"); + fprintf(stderr, "addr 0x%06X %3ld%%\r", rw_offset + addr, 100 * addr / file_size); flash_read(rw_offset + addr, buffer_flash, rc); if (memcmp(buffer_file, buffer_flash, rc)) { fprintf(stderr, "Found difference between flash and file!\n"); @@ -1001,6 +1052,7 @@ int main(int argc, char **argv) } } + fprintf(stderr, " \r"); fprintf(stderr, "VERIFY OK\n"); } |