diff --git a/Linux/SNANDer b/Linux/SNANDer index 9d0bd59..416b581 100755 Binary files a/Linux/SNANDer and b/Linux/SNANDer differ diff --git a/MacOSX/SNANDer b/MacOSX/SNANDer index e4822ac..0c5d1a8 100755 Binary files a/MacOSX/SNANDer and b/MacOSX/SNANDer differ diff --git a/Windows/SNANDer.exe b/Windows/SNANDer.exe index eb431d0..bf517b3 100755 Binary files a/Windows/SNANDer.exe and b/Windows/SNANDer.exe differ diff --git a/flash_support_list.txt b/flash_support_list.txt index 382b632..53950c5 100644 --- a/flash_support_list.txt +++ b/flash_support_list.txt @@ -1,5 +1,5 @@ -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC SPI NAND Flash Support List: 001. GIGADEVICE GD5F1GQ4UA diff --git a/readme.txt b/readme.txt index 80ef303..6d223fb 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC Usage: -h display this message @@ -23,7 +23,19 @@ Examples: igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -i -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC + +Found programmer device: WinChipHead (WCH) - CH341A +Device revision is 3.0.4 +spi_nand_probe: mfr_id = 0xc2, dev_id = 0x22 +Get Status Register 1: 0x38 +Get Status Register 2: 0x10 +Using Flash ECC. +Detected SPI NAND Flash: MXIC MX35LF2G, Flash Size: 256 MB + +or + +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC Found programmer device: Winchiphead (WCH) - CH341A Device revision is 3.0.4 @@ -32,98 +44,90 @@ Get Status Register 1: 0x81 Get Status Register 2: 0x18 Using Flash ECC. Detected SPI NAND Flash: WINBOND W25N01G, Flash Size: 128 MB -igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ 2. Full erase flash with disable internal ECC check. Without OOB, page size 2112 bytes. igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -d -e -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC -Found programmer device: Winchiphead (WCH) - CH341A +Found programmer device: WinChipHead (WCH) - CH341A Device revision is 3.0.4 -spi_nand_probe: mfr_id = 0xef, dev_id = 0xaa -Get Status Register 1: 0x81 -Get Status Register 2: 0x18 +spi_nand_probe: mfr_id = 0xc2, dev_id = 0x22 +Get Status Register 1: 0x00 +Get Status Register 2: 0x11 Disable Flash ECC. -Detected SPI NAND Flash: WINBOND W25N01G, Flash Size: 128 MB +Detected SPI NAND Flash: MXIC MX35LF2G, Flash Size: 256 MB ERASE: Set full erase chip! -Erase addr = 0x0000000000000000, len = 0x0000000008400000 +Erase addr = 0x0000000000000000, len = 0x0000000010800000 +Erase 100% [276824064] of [276824064] bytes +Elapsed time: 3 seconds Status: OK igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ 3. Write and verify flash with disable internal ECC check. Without OOB, page size 2112 bytes. -igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -d -v -w ecc_1Gb_2K_64_flashimage_rfb1_ac2600.bin +igor@mcmcc-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -d -v -w ecc_2Gb_2K_64_flashimage_rfb1_ac2600.bin -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC -Found programmer device: Winchiphead (WCH) - CH341A +Found programmer device: WinChipHead (WCH) - CH341A Device revision is 3.0.4 -spi_nand_probe: mfr_id = 0xef, dev_id = 0xaa -Get Status Register 1: 0x81 -Get Status Register 2: 0x08 +spi_nand_probe: mfr_id = 0xc2, dev_id = 0x22 +Get Status Register 1: 0x00 +Get Status Register 2: 0x11 Disable Flash ECC. -Detected SPI NAND Flash: WINBOND W25N01G, Flash Size: 128 MB +Detected SPI NAND Flash: MXIC MX35LF2G, Flash Size: 256 MB WRITE: -Write addr = 0x0000000000000000, len = 0x0000000001080000 -snand_erase_write: offs:0, count:1080000 -.......................................................................................................... -.......................................................................................................... -.......................................................................................................... -.......................................................................................................... -........................................................................................................Done! +Write addr = 0x0000000000000000, len = 0x000000000E5A9D6F +Written 100% [240819567] of [240819567] bytes +Elapsed time: 4184 seconds Status: OK VERIFY: -Read addr = 0x0000000000000000, len = 0x0000000001080000 +Read addr = 0x0000000000000000, len = 0x000000000E5A9D6F +Read 100% [240819567] of [240819567] bytes +Elapsed time: 2047 seconds Status: OK 4. Read Microwire EEPROM Atmel 93C46 and save file. igor@igor-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -E 93c46 -r test.bin -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC Found programmer device: WinChipHead (WCH) - CH341A Device revision is 3.0.4 -spi_nand_probe: mfr_id = 0xff, dev_id = 0xff -SPI NAND Flash Not Detected! -spi device id: ff ff ff ff ff (ffffffff) -SPI NOR Flash Not Detected! -I2C EEPROM Not Detected! Microwire EEPROM chip: 93c46, Size: 64 bytes, Org: 16 bits, fix addr len: Auto READ: Read addr = 0x0000000000000000, len = 0x0000000000000080 Read_EEPROM_3wire: Set address len 6 bits -............................................................ +Read 100% [64] of [64] bytes Read [128] bytes from [93c46] EEPROM address 0x00000000 +Elapsed time: 0 seconds Status: OK 5. Write and verify Microwire EEPROM Atmel 93C46 from file. igor@igor-GL553VE:~/Soft/SNANDer-bin/Linux$ ./SNANDer -E 93c46 -w test.bin -v -SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.6.2 by McMCC +SNANDer - Serial Nor/nAND/Eeprom programmeR v.1.7 by McMCC Found programmer device: WinChipHead (WCH) - CH341A Device revision is 3.0.4 -spi_nand_probe: mfr_id = 0xff, dev_id = 0xff -SPI NAND Flash Not Detected! -spi device id: ff ff ff ff ff (ffffffff) -SPI NOR Flash Not Detected! -I2C EEPROM Not Detected! Microwire EEPROM chip: 93c46, Size: 64 bytes, Org: 16 bits, fix addr len: Auto WRITE: Write addr = 0x0000000000000000, len = 0x0000000000000080 Erase_EEPROM_3wire: Set address len 6 bits Write_EEPROM_3wire: Set address len 6 bits -............................................................ +Written 100% [64] of [64] bytes Wrote [128] bytes to [93c46] EEPROM address 0x00000000 +Elapsed time: 1 seconds Status: OK VERIFY: Read addr = 0x0000000000000000, len = 0x0000000000000080 Read_EEPROM_3wire: Set address len 6 bits -............................................................ +Read 100% [64] of [64] bytes Read [128] bytes from [93c46] EEPROM address 0x00000000 +Elapsed time: 1 seconds Status: OK diff --git a/src/Makefile b/src/Makefile index 7cb7555..3c38fd8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ EEPROM_SUPPORT = y BIGFILES=-D_FILE_OFFSET_BITS=64 CFLAGS=-O2 -std=gnu99 -static -Wall -I./lusb_build/include $(BIGFILES) -OBJS= flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o main.o +OBJS= flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o timer.o main.o ifeq ($(EEPROM_SUPPORT),y) CFLAGS += -DEEPROM_SUPPORT diff --git a/src/Makefile.osx b/src/Makefile.osx index 21a110b..0bb235d 100644 --- a/src/Makefile.osx +++ b/src/Makefile.osx @@ -19,7 +19,7 @@ CFLAGS=-O2 -std=gnu99 -Wall -Wno-gnu-designator -I./lusb_build_osx/include $(BIG U=lusb_build_osx/libusb O=lusb_build_osx/libusb/os -OBJS = flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o main.o +OBJS = flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o timer.o main.o USB_OBJS += $(U)/libusb_1_0_la-core.o $(U)/libusb_1_0_la-descriptor.o $(U)/libusb_1_0_la-hotplug.o \ $(U)/libusb_1_0_la-io.o $(U)/libusb_1_0_la-strerror.o $(U)/libusb_1_0_la-sync.o \ $(O)/libusb_1_0_la-darwin_usb.o $(O)/libusb_1_0_la-poll_posix.o $(O)/libusb_1_0_la-threads_posix.o diff --git a/src/Makefile.win b/src/Makefile.win index 92bda47..e7c0841 100644 --- a/src/Makefile.win +++ b/src/Makefile.win @@ -8,7 +8,7 @@ EEPROM_SUPPORT = y BIGFILES=-D_FILE_OFFSET_BITS=64 CFLAGS=-O2 -std=gnu99 -posix -static -Wall -I./lusb_build_win/include $(BIGFILES) -OBJS= flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o main.o +OBJS= flashcmd_api.o spi_controller.o spi_nand_flash.o spi_nor_flash.o ch341a_spi.o timer.o main.o ifeq ($(EEPROM_SUPPORT),y) CFLAGS += -DEEPROM_SUPPORT @@ -26,8 +26,11 @@ all: SNANDer.exe make install touch $@ -SNANDer.exe: .lusb_install_win $(OBJS) - $(CC) $(CFLAGS) -s -o $@ $(OBJS) $(LDFLAGS) +res.o: + x86_64-w64-mingw32-windres -i snander.rc -o res.o + +SNANDer.exe: .lusb_install_win $(OBJS) res.o + $(CC) $(CFLAGS) -s -o $@ $(OBJS) res.o $(LDFLAGS) .c.o: $(CC) $(CFLAGS) -c $< diff --git a/src/bitbang_microwire.c b/src/bitbang_microwire.c index a794308..403bbd4 100644 --- a/src/bitbang_microwire.c +++ b/src/bitbang_microwire.c @@ -250,7 +250,6 @@ void Erase_EEPROM_3wire(int size_eeprom) int i, num_bit; num_bit = addr_nbits(__func__, size_eeprom); - size_eeprom = convert_size(size_eeprom); enable_write_3wire(num_bit); csel_0(); @@ -339,13 +338,12 @@ int Read_EEPROM_3wire(unsigned char *buffer, int size_eeprom) delay_ms(1); clock_1(); delay_ms(1); + printf("\bRead %d%% [%d] of [%d] bytes ", 100 * l / size_eeprom, l, size_eeprom); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); address++; - if (l % (org ? 16 : 8)) { - printf("."); - fflush(stdout); - } } - printf("\n"); + printf("Read 100%% [%d] of [%d] bytes \n", l, size_eeprom); return 0; } @@ -408,13 +406,12 @@ int Write_EEPROM_3wire(unsigned char *buffer, int size_eeprom) delay_ms(1); clock_1(); delay_ms(1); + printf("\bWritten %d%% [%d] of [%d] bytes ", 100 * l / size_eeprom, l, size_eeprom); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); address++; - if (l % (org ? 16 : 8)) { - printf("."); - fflush(stdout); - } } - printf("\n"); + printf("Written 100%% [%d] of [%d] bytes \n", l, size_eeprom); disable_write_3wire(num_bit); return 0; diff --git a/src/ch341a_i2c.c b/src/ch341a_i2c.c index 11cc1a0..83bfde6 100644 --- a/src/ch341a_i2c.c +++ b/src/ch341a_i2c.c @@ -144,7 +144,9 @@ int32_t ch341readEEPROM(uint8_t *buffer, uint32_t bytestoread, struct EEPROM *ee readbuf = buffer; while (1) { - printf("Read %d%% [%d] of [%d] bytes \r", 100 * byteoffset / bytestoread, byteoffset, bytestoread); + printf("Read %d%% [%d] of [%d] bytes ", 100 * byteoffset / bytestoread, byteoffset, bytestoread); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); ret = libusb_handle_events_timeout(NULL, &tv); if (ret < 0 || getnextpkt == -1) { // indicates an error @@ -182,6 +184,7 @@ int32_t ch341readEEPROM(uint8_t *buffer, uint32_t bytestoread, struct EEPROM *ee } } } + printf("Read 100%% [%d] of [%d] bytes \n", byteoffset, bytestoread); libusb_free_transfer(xferBulkIn); libusb_free_transfer(xferBulkOut); @@ -321,8 +324,11 @@ int32_t ch341writeEEPROM(uint8_t *buffer, uint32_t bytesum, struct EEPROM *eepro return -1; } */ - printf("Written %d%% [%d] of [%d] bytes \r", 100 * (bytesum - bytes) / bytesum, bytesum - bytes, bytesum); + printf("\bWritten %d%% [%d] of [%d] bytes ", 100 * (bytesum - bytes) / bytesum, bytesum - bytes, bytesum); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); } + printf("Written 100%% [%d] of [%d] bytes \n", bytesum - bytes, bytesum); return 0; } diff --git a/src/ch341a_spi.c b/src/ch341a_spi.c index 9c89816..c488063 100644 --- a/src/ch341a_spi.c +++ b/src/ch341a_spi.c @@ -424,9 +424,9 @@ int ch341a_spi_init(void) } printf("Found programmer device: %s - %s\n", devs_ch341a_spi[0].vendor_name, devs_ch341a_spi[0].device_name); -/* libusb_detach_kernel_driver() and friends basically only work on Linux. We simply try to detach on Linux - * without a lot of passion here. If that works fine else we will fail on claiming the interface anyway. */ -#if 1 /* IS_LINUX */ +#ifdef __gnu_linux__ + /* libusb_detach_kernel_driver() and friends basically only work on Linux. We simply try to detach on Linux + * without a lot of passion here. If that works fine else we will fail on claiming the interface anyway. */ ret = libusb_detach_kernel_driver(handle, 0); if (ret == LIBUSB_ERROR_NOT_SUPPORTED) { printf("Detaching kernel drivers is not supported. Further accesses may fail.\n"); diff --git a/src/flashcmd_api.c b/src/flashcmd_api.c index d8e8744..746f1fc 100644 --- a/src/flashcmd_api.c +++ b/src/flashcmd_api.c @@ -18,6 +18,8 @@ #ifdef EEPROM_SUPPORT #define __EEPROM___ "or EEPROM" +extern int eepromsize; +extern int mw_eepromsize; #else #define __EEPROM___ "" #endif @@ -26,26 +28,33 @@ long flash_cmd_init(struct flash_cmd *cmd) { long flen = -1; - if((flen = snand_init()) > 0) { - cmd->flash_erase = snand_erase; - cmd->flash_write = snand_write; - cmd->flash_read = snand_read; - } else if ((flen = snor_init()) > 0) { - cmd->flash_erase = snor_erase; - cmd->flash_write = snor_write; - cmd->flash_read = snor_read; #ifdef EEPROM_SUPPORT - } else if ((flen = i2c_init()) > 0) { - cmd->flash_erase = i2c_eeprom_erase; - cmd->flash_write = i2c_eeprom_write; - cmd->flash_read = i2c_eeprom_read; - } else if ((flen = mw_init()) > 0) { - cmd->flash_erase = mw_eeprom_erase; - cmd->flash_write = mw_eeprom_write; - cmd->flash_read = mw_eeprom_read; + if ((eepromsize <= 0) && (mw_eepromsize <= 0)) { #endif - } else - printf("\nNot Flash" __EEPROM___ " detected!!!!\n\n"); + if ((flen = snand_init()) > 0) { + cmd->flash_erase = snand_erase; + cmd->flash_write = snand_write; + cmd->flash_read = snand_read; + } else if ((flen = snor_init()) > 0) { + cmd->flash_erase = snor_erase; + cmd->flash_write = snor_write; + cmd->flash_read = snor_read; + } +#ifdef EEPROM_SUPPORT + } else if ((eepromsize > 0) || (mw_eepromsize > 0)) { + if ((eepromsize > 0) && (flen = i2c_init()) > 0) { + cmd->flash_erase = i2c_eeprom_erase; + cmd->flash_write = i2c_eeprom_write; + cmd->flash_read = i2c_eeprom_read; + } else if ((mw_eepromsize > 0) && (flen = mw_init()) > 0) { + cmd->flash_erase = mw_eeprom_erase; + cmd->flash_write = mw_eeprom_write; + cmd->flash_read = mw_eeprom_read; + } + } +#endif + else + printf("\nFlash" __EEPROM___ " not found!!!!\n\n"); return flen; } @@ -62,3 +71,4 @@ void support_flash_list(void) support_mw_eeprom_list(); #endif } +/* End of [flashcmd.c] package */ diff --git a/src/i2c_eeprom.c b/src/i2c_eeprom.c index 7c9aee8..bdc1a00 100644 --- a/src/i2c_eeprom.c +++ b/src/i2c_eeprom.c @@ -15,6 +15,7 @@ #include "ch341a_spi.h" #include "ch341a_i2c.h" +#include "timer.h" extern unsigned int bsize; struct EEPROM eeprom_info; @@ -28,6 +29,7 @@ int i2c_eeprom_read(unsigned char *buf, unsigned long from, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0, sizeof(ebuf)); pbuf = ebuf; @@ -39,6 +41,7 @@ int i2c_eeprom_read(unsigned char *buf, unsigned long from, unsigned long len) memcpy(buf, pbuf + from, len); printf("Read [%d] bytes from [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, from); + timer_end(); return (int)len; } @@ -50,6 +53,7 @@ int i2c_eeprom_erase(unsigned long offs, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0xff, sizeof(ebuf)); pbuf = ebuf; @@ -67,6 +71,7 @@ int i2c_eeprom_erase(unsigned long offs, unsigned long len) } printf("Erased [%d] bytes of [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, offs); + timer_end(); return 0; } @@ -78,6 +83,7 @@ int i2c_eeprom_write(unsigned char *buf, unsigned long to, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0xff, sizeof(ebuf)); pbuf = ebuf; @@ -95,6 +101,7 @@ int i2c_eeprom_write(unsigned char *buf, unsigned long to, unsigned long len) } printf("Wrote [%d] bytes to [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, to); + timer_end(); return (int)len; } diff --git a/src/main.c b/src/main.c index ee67a89..8a444de 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,7 @@ extern int org; #define EHELP "" #endif -#define _VER "1.6.2" +#define _VER "1.7" void title(void) { diff --git a/src/mw_eeprom.c b/src/mw_eeprom.c index 9a79a70..8046656 100644 --- a/src/mw_eeprom.c +++ b/src/mw_eeprom.c @@ -24,6 +24,7 @@ #include "bitbang_microwire.h" #include "ch341a_gpio.h" +#include "timer.h" extern struct gpio_cmd bb_func; extern char eepromname[12]; @@ -36,13 +37,15 @@ int mw_eeprom_read(unsigned char *buf, unsigned long from, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0, sizeof(ebuf)); pbuf = ebuf; Read_EEPROM_3wire(pbuf, mw_eepromsize); memcpy(buf, pbuf + from, len); - printf("Read [%d] bytes from [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, from); + printf("Read [%lu] bytes from [%s] EEPROM address 0x%08lu\n", len, eepromname, from); + timer_end(); return (int)len; } @@ -54,6 +57,7 @@ int mw_eeprom_erase(unsigned long offs, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0xff, sizeof(ebuf)); pbuf = ebuf; @@ -66,12 +70,13 @@ int mw_eeprom_erase(unsigned long offs, unsigned long len) if (offs || len < mw_eepromsize) { if (Write_EEPROM_3wire(pbuf, mw_eepromsize) < 0) { - printf("Failed to erase [%d] bytes of [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, offs); + printf("Failed to erase [%lu] bytes of [%s] EEPROM address 0x%08lu\n", len, eepromname, offs); return -1; } } - printf("Erased [%d] bytes of [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, offs); + printf("Erased [%lu] bytes of [%s] EEPROM address 0x%08lu\n", len, eepromname, offs); + timer_end(); return 0; } @@ -83,6 +88,7 @@ int mw_eeprom_write(unsigned char *buf, unsigned long to, unsigned long len) if (len == 0) return -1; + timer_start(); memset(ebuf, 0xff, sizeof(ebuf)); pbuf = ebuf; @@ -94,11 +100,12 @@ int mw_eeprom_write(unsigned char *buf, unsigned long to, unsigned long len) Erase_EEPROM_3wire(mw_eepromsize); if (Write_EEPROM_3wire(pbuf, mw_eepromsize) < 0) { - printf("Failed to write [%d] bytes of [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, to); + printf("Failed to write [%lu] bytes of [%s] EEPROM address 0x%08lu\n", len, eepromname, to); return -1; } - printf("Wrote [%d] bytes to [%s] EEPROM address 0x%08lu\n", (int)len, eepromname, to); + printf("Wrote [%lu] bytes to [%s] EEPROM address 0x%08lu\n", len, eepromname, to); + timer_end(); return (int)len; } diff --git a/src/res.h b/src/res.h new file mode 100644 index 0000000..71bc0f2 --- /dev/null +++ b/src/res.h @@ -0,0 +1 @@ +#define snander 128 diff --git a/src/snander.ico b/src/snander.ico new file mode 100644 index 0000000..065d0e5 Binary files /dev/null and b/src/snander.ico differ diff --git a/src/snander.rc b/src/snander.rc new file mode 100644 index 0000000..785946c --- /dev/null +++ b/src/snander.rc @@ -0,0 +1,31 @@ +#include +#include "res.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1, 7, 0, 0 + PRODUCTVERSION 1, 7, 0, 0 + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileDescription", "SNANDer - Serial Nor/nAND/Eeprom programmeR\0" + VALUE "OriginalFilename", "SNANDer.exe\0" + VALUE "CompanyName", "-= (c) 2018-2021 Igor Mokrushin aka McMCC =-\0" + VALUE "FileVersion", "1.7.0.0\0" + VALUE "InternalName", "SNANDer\0" + VALUE "LegalCopyright", "Copyright (c) 2018-2021 by McMCC \0" + VALUE "ProductName","SNANDer\0" + VALUE "ProductVersion","1.7.0.0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END + +snander ICON DISCARDABLE "snander.ico" diff --git a/src/spi_nand_flash.c b/src/spi_nand_flash.c index fef3e49..0d47d39 100644 --- a/src/spi_nand_flash.c +++ b/src/spi_nand_flash.c @@ -37,6 +37,7 @@ #include "spi_nand_flash.h" #include "spi_controller.h" #include "nandcmd_api.h" +#include "timer.h" /* NAMING CONSTANT DECLARATIONS ------------------------------------------------------ */ @@ -254,7 +255,9 @@ static unsigned long bmt_oob_size = 64; static u32 erase_oob_size = 0; static u32 ecc_size = 0; u32 bsize = 0; +#if 0 static unsigned int print_dot = 0; +#endif static u32 _current_page_num = 0xFFFFFFFF; static u8 _current_cache_page[_SPI_NAND_CACHE_SIZE]; @@ -2782,12 +2785,14 @@ SPI_NAND_FLASH_RTN_T spi_nand_erase_block ( u32 block_index) /* 2.5 Disable write_flash */ spi_nand_protocol_write_disable(); - print_dot ++; +#if 0 + print_dot++; if( (print_dot % 15) == 0 ) { _SPI_NAND_PRINTF("."); fflush(stdout); } +#endif /* 2.6 Check Erase Fail Bit */ if( status & _SPI_NAND_VAL_ERASE_FAIL ) @@ -2823,7 +2828,9 @@ static SPI_NAND_FLASH_RTN_T spi_nand_erase_internal( u32 addr, u32 len ) u32 block_index = 0; u32 erase_len = 0; SPI_NAND_FLASH_RTN_T rtn_status = SPI_NAND_FLASH_RTN_NO_ERROR; +#if 0 print_dot = 0; +#endif _SPI_NAND_DEBUG_PRINTF(SPI_NAND_FLASH_DEBUG_LEVEL_1, "\nspi_nand_erase_internal (in): addr = 0x%x, len = 0x%x\n", addr, len ); _SPI_NAND_SEMAPHORE_LOCK(); @@ -2857,7 +2864,11 @@ static SPI_NAND_FLASH_RTN_T spi_nand_erase_internal( u32 addr, u32 len ) /* 2.7 Erase next block if needed */ addr += _current_flash_info_t.erase_size; erase_len += _current_flash_info_t.erase_size; + printf("\bErase %d%% [%u] of [%u] bytes ", 100 * (erase_len / 1024) / (len / 1024), erase_len, len); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); } + printf("Erase 100%% [%u] of [%u] bytes \n", erase_len, len); } else { @@ -2955,12 +2966,14 @@ static SPI_NAND_FLASH_RTN_T spi_nand_read_page (u32 page_number, SPI_NAND_FLASH_ } noecc: _current_page_num = page_number; - print_dot ++; +#if 0 + print_dot++; if( (print_dot % 20) == 0 ) { _SPI_NAND_PRINTF("."); fflush(stdout); } +#endif } return rtn_status; @@ -3075,14 +3088,14 @@ static SPI_NAND_FLASH_RTN_T spi_nand_write_page( u32 page_number, u32 data_offse spi_nand_protocol_get_status_reg_1( &status_2); _SPI_NAND_DEBUG_PRINTF(SPI_NAND_FLASH_DEBUG_LEVEL_1, "[spi_nand_write_page]: status 1 = 0x%x, status 3 = 0x%x\n", status_2, status); - - print_dot ++; +#if 0 + print_dot++; if( (print_dot % 20) == 0 ) { _SPI_NAND_PRINTF("."); fflush(stdout); } - +#endif /* Check Program Fail Bit */ if( status & _SPI_NAND_VAL_PROGRAM_FAIL ) { @@ -3125,8 +3138,9 @@ static SPI_NAND_FLASH_RTN_T spi_nand_write_internal( u32 dst_addr, u32 len, u32 u32 addr_offset; struct SPI_NAND_FLASH_INFO_T *ptr_dev_info_t; SPI_NAND_FLASH_RTN_T rtn_status = SPI_NAND_FLASH_RTN_NO_ERROR; - +#if 0 print_dot = 0; +#endif *ptr_rtn_len = 0; ptr_dev_info_t = _SPI_NAND_GET_DEVICE_INFO_PTR; @@ -3163,8 +3177,11 @@ static SPI_NAND_FLASH_RTN_T spi_nand_write_internal( u32 dst_addr, u32 len, u32 write_addr += data_len; remain_len -= data_len; ptr_rtn_len += data_len; + printf("\bWritten %d%% [%u] of [%u] bytes ", 100 * ((len - remain_len) / 1024) / (len / 1024), len - remain_len, len); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); } - + printf("Written 100%% [%u] of [%u] bytes \n", len - remain_len, len); _SPI_NAND_SEMAPHORE_UNLOCK(); return (rtn_status); @@ -3199,7 +3216,9 @@ static SPI_NAND_FLASH_RTN_T spi_nand_read_internal ( u32 addr, u32 len, u8 *ptr_ SPI_NAND_FLASH_RTN_T rtn_status = SPI_NAND_FLASH_RTN_NO_ERROR; ptr_dev_info_t = _SPI_NAND_GET_DEVICE_INFO_PTR; +#if 0 print_dot = 0; +#endif read_addr = addr; remain_len = len; @@ -3237,7 +3256,11 @@ static SPI_NAND_FLASH_RTN_T spi_nand_read_internal ( u32 addr, u32 len, u8 *ptr_ remain_len -= (ptr_dev_info_t->page_size - data_offset); read_addr += (ptr_dev_info_t->page_size - data_offset); } + printf("\bRead %d%% [%u] of [%u] bytes ", 100 * ((len - remain_len) / 1024) / (len / 1024), len - remain_len, len); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); } + printf("Read 100%% [%u] of [%u] bytes \n", len - remain_len, len); _SPI_NAND_SEMAPHORE_UNLOCK(); return (rtn_status); @@ -4118,8 +4141,10 @@ int nandflash_read(unsigned long from, unsigned long len, unsigned long *retlen, ptr_dev_info_t = _SPI_NAND_GET_DEVICE_INFO_PTR; + timer_start(); if( SPI_NAND_Flash_Read_NByte(from, len, (u32 *)retlen, buf, ptr_dev_info_t->read_mode, status) == SPI_NAND_FLASH_RTN_NO_ERROR ) { + timer_end(); return 0; } else @@ -4130,8 +4155,10 @@ int nandflash_read(unsigned long from, unsigned long len, unsigned long *retlen, int nandflash_erase(unsigned long offset, unsigned long len) { + timer_start(); if( SPI_NAND_Flash_Erase(offset, len) == SPI_NAND_FLASH_RTN_NO_ERROR ) { + timer_end(); return 0; } else @@ -4146,8 +4173,10 @@ int nandflash_write(unsigned long to, unsigned long len, unsigned long *retlen, ptr_dev_info_t = _SPI_NAND_GET_DEVICE_INFO_PTR; + timer_start(); if( SPI_NAND_Flash_Write_Nbyte(to, len, (u32 *)retlen, buf, ptr_dev_info_t->write_mode) == SPI_NAND_FLASH_RTN_NO_ERROR ) { + timer_end(); return 0; } else diff --git a/src/spi_nor_flash.c b/src/spi_nor_flash.c index 58f5590..310e780 100644 --- a/src/spi_nor_flash.c +++ b/src/spi_nor_flash.c @@ -23,6 +23,7 @@ #include "spi_controller.h" #include "snorcmd_api.h" #include "types.h" +#include "timer.h" #define min(a,b) (((a)<(b))?(a):(b)) @@ -274,6 +275,7 @@ static int snor_erase_sector(unsigned long offset) static int full_erase_chip(void) { + timer_start(); /* Wait until finished previous write command. */ if (snor_wait_ready(3)) return -1; @@ -288,6 +290,7 @@ static int full_erase_chip(void) snor_wait_ready(950); snor_write_disable(); + timer_end(); return 0; } @@ -534,6 +537,7 @@ long snor_init(void) int snor_erase(unsigned long offs, unsigned long len) { + unsigned long plen = len; snor_dbg("%s: offs:%x len:%x\n", __func__, offs, len); /* sanity checks */ @@ -546,6 +550,8 @@ int snor_erase(unsigned long offs, unsigned long len) return full_erase_chip(); } + timer_start(); + snor_unprotect(); /* now erase those sectors */ @@ -556,10 +562,13 @@ int snor_erase(unsigned long offs, unsigned long len) offs += spi_chip_info->sector_size; len -= spi_chip_info->sector_size; - printf("."); + + printf("\bErase %ld%% [%lu] of [%lu] bytes ", 100 * (plen - len) / plen, plen - len, plen); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } - printf("\n"); + printf("Erase 100%% [%lu] of [%lu] bytes \n", plen - len, plen); + timer_end(); return 0; } @@ -574,6 +583,7 @@ int snor_read(unsigned char *buf, unsigned long from, unsigned long len) if (len == 0) return 0; + timer_start(); /* Wait till previous write/erase is done. */ if (snor_wait_ready(1)) { /* REVISIT status return?? */ @@ -622,8 +632,11 @@ int snor_read(unsigned char *buf, unsigned long from, unsigned long len) } remain_len -= spi_chip_info->sector_size - data_offset; read_addr += spi_chip_info->sector_size - data_offset; - printf("."); - fflush(stdout); + if ((read_addr & 0xffff) == 0) { + printf("\bRead %ld%% [%lu] of [%lu] bytes ", 100 * (len - remain_len) / len, len - remain_len, len); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } } SPI_CONTROLLER_Chip_Select_High(); @@ -631,7 +644,8 @@ int snor_read(unsigned char *buf, unsigned long from, unsigned long len) if (spi_chip_info->addr4b) snor_4byte_mode(0); } - printf("\n"); + printf("Read 100%% [%lu] of [%lu] bytes \n", len - remain_len, len); + timer_end(); return len; } @@ -640,6 +654,7 @@ int snor_write(unsigned char *buf, unsigned long to, unsigned long len) { u32 page_offset, page_size; int rc = 0, retlen = 0; + unsigned long plen = len; snor_dbg("%s: to:%x len:%x \n", __func__, to, len); @@ -650,7 +665,7 @@ int snor_write(unsigned char *buf, unsigned long to, unsigned long len) if (to + len > spi_chip_info->sector_size * spi_chip_info->n_sectors) return -1; - + timer_start(); /* Wait until finished previous write command. */ if (snor_wait_ready(2)) { return -1; @@ -693,7 +708,8 @@ int snor_write(unsigned char *buf, unsigned long to, unsigned long len) snor_dbg("%s: to:%x page_size:%x ret:%x\n", __func__, to, page_size, rc); if ((retlen & 0xffff) == 0) { - printf("."); + printf("\bWritten %ld%% [%lu] of [%lu] bytes ", 100 * (plen - len) / plen, plen - len, plen); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } @@ -717,7 +733,8 @@ int snor_write(unsigned char *buf, unsigned long to, unsigned long len) snor_write_disable(); - printf("\n"); + printf("Written 100%% [%ld] of [%ld] bytes \n", plen - len, plen); + timer_end(); return retlen; } diff --git a/src/timer.c b/src/timer.c new file mode 100644 index 0000000..29c1f3f --- /dev/null +++ b/src/timer.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2021 McMCC + * timer.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include + +#include "timer.h" + +static time_t start_time = 0; + +void timer_start(void) +{ + start_time = time(0); +} + +void timer_end(void) +{ + time_t end_time = 0, elapsed_seconds = 0; + + time(&end_time); + elapsed_seconds = difftime(end_time, start_time); + printf("Elapsed time: %d seconds\n", (int)elapsed_seconds); +} +/* End of [timer.c] package */ diff --git a/src/timer.h b/src/timer.h new file mode 100644 index 0000000..b6b8328 --- /dev/null +++ b/src/timer.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 McMCC + * timer.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef __TIMER_H__ +#define __TIMER_H__ + +void timer_start(void); +void timer_end(void); + +#endif /* __TIMER_H__ */ +/* End of [timer.h] package */