Open ZhiyuanYuanNJ opened 10 months ago
try spi-nand-prog
try spi-nand-prog Hi,this is nice project, do you have any plans to continue updating other chips in the future?
I have replaced the SPI part with CH347, but the speed of read and write seems a bit slow.
try spi-nand-prog
When can it be adapted
@ZhiyuanYuanNJ
Your commits are breaking things compared to the main repo when trying to build it with the command ./build-for-linux.sh
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages
/usr/bin/mkdir -p '/xxxx/SNANDer/build/libs/include/libusb-1.0'
/usr/bin/install -c -m 644 libusb.h '/xxxx/SNANDer/build/libs/include/libusb-1.0'
make[2]: Leaving directory '/xxxx/SNANDer/dl/libusb-1.0.27/libusb'
make[1]: Leaving directory '/xxxx/SNANDer/dl/libusb-1.0.27/libusb'
make[1]: Entering directory '/xxxx/SNANDer/dl/libusb-1.0.27'
make[2]: Entering directory '/xxxx/SNANDer/dl/libusb-1.0.27'
make[2]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/xxxx/SNANDer/build/libs/lib/pkgconfig'
/usr/bin/install -c -m 644 libusb-1.0.pc '/xxxx/SNANDer/build/libs/lib/pkgconfig'
make[2]: Leaving directory '/xxxx/SNANDer/dl/libusb-1.0.27'
make[1]: Leaving directory '/xxxx/SNANDer/dl/libusb-1.0.27'
make: Entering directory '/xxxx/SNANDer/src'
make: Circular snander <- snander dependency dropped.
cc -std=gnu99 -Wall -O2 -D_FILE_OFFSET_BITS=64 -I/xxxx/SNANDer/build/libs/include -DEEPROM_SUPPORT flashcmd_api.c spi_controller.c spi_nand_flash.c spi_nor_flash.c ch347_spi.c timer.c main.c i2c_eeprom.c spi_eeprom.c bitbang_microwire.c mw_eeprom.c ch341a_gpio.c ch347_i2c.c -pthread -L/xxxx/SNANDer/build/libs/lib -Wl,-rpath -Wl,/xxxx/SNANDer/build/libs/lib -static -lusb-1.0 -o snander
ch347_spi.c: In function ‘config_stream’:
ch347_spi.c:359:9: error: unknown type name ‘ULONG’
359 | ULONG transferred = sizeof(buff);
| ^~~~~
ch347_spi.c:359:15: warning: unused variable ‘transferred’ [-Wunused-variable]
359 | ULONG transferred = sizeof(buff);
| ^~~~~~~~~~~
ch347_spi.c: In function ‘ch347_cs_control’:
ch347_spi.c:406:9: error: unknown type name ‘ULONG’
406 | ULONG transferred = sizeof(cmd);
| ^~~~~
ch347_spi.c:406:15: warning: unused variable ‘transferred’ [-Wunused-variable]
406 | ULONG transferred = sizeof(cmd);
| ^~~~~~~~~~~
ch347_spi.c: In function ‘ch347_write’:
ch347_spi.c:436:9: error: unknown type name ‘ULONG’
436 | ULONG transferred;
| ^~~~~
ch347_spi.c: In function ‘ch347_read’:
ch347_spi.c:482:9: error: unknown type name ‘ULONG’
482 | ULONG transferred;
| ^~~~~
ch347_spi.c:485:17: warning: unused variable ‘command_buf’ [-Wunused-variable]
485 | uint8_t command_buf[7] = {
| ^~~~~~~~~~~
ch347_spi.c:481:13: warning: unused variable ‘ret’ [-Wunused-variable]
481 | int ret;
| ^~~
ch347_spi.c: In function ‘ch347_spi_shutdown’:
ch347_spi.c:580:45: error: ‘data’ undeclared (first use in this function)
580 | struct ch347_spi_data *ch347_data = data;
| ^~~~
ch347_spi.c:580:45: note: each undeclared identifier is reported only once for each function it appears in
ch347_spi.c:580:32: warning: unused variable ‘ch347_data’ [-Wunused-variable]
580 | struct ch347_spi_data *ch347_data = data;
| ^~~~~~~~~~
ch347_spi.c: In function ‘ch347_spi_init’:
ch347_spi.c:648:9: error: ‘ch347_data’ undeclared (first use in this function)
648 | ch347_data->handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
| ^~~~~~~~~~
ch347_spi.c:652:17: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
652 | free(ch347_data);
| ^~~~
ch347_spi.c:28:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
27 | #include <libusb-1.0/libusb.h>
+++ |+#include <stdlib.h>
28 | #include <stdbool.h>
ch347_spi.c:652:17: warning: incompatible implicit declaration of built-in function ‘free’ [-Wbuiltin-declaration-mismatch]
652 | free(ch347_data);
| ^~~~
ch347_spi.c:652:17: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
ch347_spi.c:662:17: warning: implicit declaration of function ‘msg_pwarn’ [-Wimplicit-function-declaration]
662 | msg_pwarn("Cannot detach the existing USB driver. Claiming the interface may fail. %s\n",
| ^~~~~~~~~
ch347_spi.c:684:9: warning: implicit declaration of function ‘msg_pdbg’ [-Wimplicit-function-declaration]
684 | msg_pdbg("Device revision is %d.%01d.%01d\n",
| ^~~~~~~~
ch347_spi.c:597:13: warning: unused variable ‘i’ [-Wunused-variable]
597 | int i = 0;
| ^
ch347_spi.c:596:13: warning: unused variable ‘spispeed’ [-Wunused-variable]
596 | int spispeed = 0x0; //defaulet 60M SPI
| ^~~~~~~~
ch347_spi.c:593:13: warning: unused variable ‘open_res’ [-Wunused-variable]
593 | int open_res = -1;
| ^~~~~~~~
ch347_spi.c: In function ‘enable_pins’:
ch347_spi.c:430:1: warning: control reaches end of non-void function [-Wreturn-type]
430 | }
| ^
ch347_spi.c: At top level:
ch347_spi.c:389:16: warning: ‘swap_byte’ defined but not used [-Wunused-function]
389 | static uint8_t swap_byte(uint8_t x)
| ^~~~~~~~~
ch347_spi.c:149:32: warning: ‘transfer_ins’ defined but not used [-Wunused-variable]
149 | static struct libusb_transfer *transfer_ins[USB_IN_TRANSFERS] = {0};
| ^~~~~~~~~~~~
ch347_spi.c:148:32: warning: ‘transfer_out’ defined but not used [-Wunused-variable]
148 | static struct libusb_transfer *transfer_out = NULL;
| ^~~~~~~~~~~~
ch347_spi.c:74:35: warning: ‘spispeeds’ defined but not used [-Wunused-const-variable=]
74 | static const struct device_speeds spispeeds[] = {
| ^~~~~~~~~
In file included from main.c:35:
ch347_i2c.h:9:22: error: expected ‘)’ before ‘*’ token
9 | typedef int(__stdcall * pCH347OpenDevice)(unsigned long iIndex);
| ^ ~
| )
ch347_i2c.h:11:22: error: expected ‘)’ before ‘*’ token
11 | typedef int(__stdcall * pCH347CloseDevice)(unsigned long iIndex);
| ^~
| )
ch347_i2c.h:12:32: error: expected ‘)’ before ‘*’ token
12 | typedef unsigned long(__stdcall * pCH347SetTimeout)(
| ^~
| )
ch347_i2c.h:23:32: error: expected ‘)’ before ‘*’ token
23 | typedef unsigned long(__stdcall * pCH347WriteData)(
| ^~
| )
ch347_i2c.h:31:32: error: expected ‘)’ before ‘*’ token
31 | typedef unsigned long(__stdcall * pCH347ReadData)(
| ^~
| )
ch347_i2c.h:94: warning: "mch347_EPP_IO_MAX" redefined
94 | #define mch347_EPP_IO_MAX 0xFF /* Unused on the source */
|
ch347_i2c.h:93: note: this is the location of the previous definition
93 | #define mch347_EPP_IO_MAX ( mch347_PACKET_LENGTH - 1 ) /* Unused on the source */
|
In file included from i2c_eeprom.c:17:
ch347_i2c.h:9:22: error: expected ‘)’ before ‘*’ token
9 | typedef int(__stdcall * pCH347OpenDevice)(unsigned long iIndex);
| ^ ~
| )
ch347_i2c.h:11:22: error: expected ‘)’ before ‘*’ token
11 | typedef int(__stdcall * pCH347CloseDevice)(unsigned long iIndex);
| ^~
| )
ch347_i2c.h:12:32: error: expected ‘)’ before ‘*’ token
12 | typedef unsigned long(__stdcall * pCH347SetTimeout)(
| ^~
| )
ch347_i2c.h:23:32: error: expected ‘)’ before ‘*’ token
23 | typedef unsigned long(__stdcall * pCH347WriteData)(
| ^~
| )
ch347_i2c.h:31:32: error: expected ‘)’ before ‘*’ token
31 | typedef unsigned long(__stdcall * pCH347ReadData)(
| ^~
| )
ch347_i2c.h:94: warning: "mch347_EPP_IO_MAX" redefined
94 | #define mch347_EPP_IO_MAX 0xFF /* Unused on the source */
|
ch347_i2c.h:93: note: this is the location of the previous definition
93 | #define mch347_EPP_IO_MAX ( mch347_PACKET_LENGTH - 1 ) /* Unused on the source */
|
In file included from /usr/include/stdio.h:980,
from mw_eeprom.c:20:
In function ‘printf’,
inlined from ‘mw_init’ at mw_eeprom.c:170:2:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:86:10: warning: dangling pointer to ‘tmp’ may be used [-Wdangling-pointer=]
86 | return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mw_eeprom.c: In function ‘mw_init’:
mw_eeprom.c:151:18: note: ‘tmp’ declared here
151 | char *p, tmp[32];
| ^~~
In file included from ch347_i2c.c:28:
ch347_i2c.h:9:22: error: expected ‘)’ before ‘*’ token
9 | typedef int(__stdcall * pCH347OpenDevice)(unsigned long iIndex);
| ^ ~
| )
ch347_i2c.h:11:22: error: expected ‘)’ before ‘*’ token
11 | typedef int(__stdcall * pCH347CloseDevice)(unsigned long iIndex);
| ^~
| )
ch347_i2c.h:12:32: error: expected ‘)’ before ‘*’ token
12 | typedef unsigned long(__stdcall * pCH347SetTimeout)(
| ^~
| )
ch347_i2c.h:23:32: error: expected ‘)’ before ‘*’ token
23 | typedef unsigned long(__stdcall * pCH347WriteData)(
| ^~
| )
ch347_i2c.h:31:32: error: expected ‘)’ before ‘*’ token
31 | typedef unsigned long(__stdcall * pCH347ReadData)(
| ^~
| )
ch347_i2c.h:94: warning: "mch347_EPP_IO_MAX" redefined
94 | #define mch347_EPP_IO_MAX 0xFF /* Unused on the source */
|
ch347_i2c.h:93: note: this is the location of the previous definition
93 | #define mch347_EPP_IO_MAX ( mch347_PACKET_LENGTH - 1 ) /* Unused on the source */
|
ch347_i2c.c: In function ‘ch347_i2c_write’:
ch347_i2c.c:119:5: error: unknown type name ‘boolean’
119 | boolean first = true;
| ^~~~~~~
ch347_i2c.c:156:36: error: ‘devHandle’ undeclared (first use in this function); did you mean ‘handle’?
156 | ret = libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, outptr - i2c_dev.obuf, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~
| handle
ch347_i2c.c:156:36: note: each undeclared identifier is reported only once for each function it appears in
ch347_i2c.c:156:105: warning: passing argument 5 of ‘libusb_bulk_transfer’ from incompatible pointer type [-Wincompatible-pointer-types]
156 | ret = libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, outptr - i2c_dev.obuf, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~~
| |
| long unsigned int *
In file included from ch347_i2c.c:21:
/xxxx/SNANDer/build/libs/include/libusb-1.0/libusb.h:2043:14: note: expected ‘int *’ but argument is of type ‘long unsigned int *’
2043 | int *actual_length, unsigned int timeout);
| ~~~~~^~~~~~~~~~~~~
ch347_i2c.c:162:86: warning: passing argument 5 of ‘libusb_bulk_transfer’ from incompatible pointer type [-Wincompatible-pointer-types]
162 | ret = libusb_bulk_transfer(devHandle, BULK_READ_ENDPOINT, i2c_dev.ibuf, 512, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~~
| |
| long unsigned int *
/xxxx/SNANDer/build/libs/include/libusb-1.0/libusb.h:2043:14: note: expected ‘int *’ but argument is of type ‘long unsigned int *’
2043 | int *actual_length, unsigned int timeout);
| ~~~~~^~~~~~~~~~~~~
ch347_i2c.c:170:50: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
170 | fprintf(stderr, "failed to get ACKs %d of %d\r\n", actuallen, wlen + 1);
| ~^ ~~~~~~~~~
| | |
| int long unsigned int
| %ld
ch347_i2c.c: In function ‘ch347_i2c_read’:
ch347_i2c.c:213:40: error: ‘devHandle’ undeclared (first use in this function); did you mean ‘handle’?
213 | int ret = libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, ptr - i2c_dev.obuf, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~
| handle
ch347_i2c.c:213:106: warning: passing argument 5 of ‘libusb_bulk_transfer’ from incompatible pointer type [-Wincompatible-pointer-types]
213 | int ret = libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, ptr - i2c_dev.obuf, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~~
| |
| long unsigned int *
/xxxx/SNANDer/build/libs/include/libusb-1.0/libusb.h:2043:14: note: expected ‘int *’ but argument is of type ‘long unsigned int *’
2043 | int *actual_length, unsigned int timeout);
| ~~~~~^~~~~~~~~~~~~
ch347_i2c.c:218:86: warning: passing argument 5 of ‘libusb_bulk_transfer’ from incompatible pointer type [-Wincompatible-pointer-types]
218 | ret = libusb_bulk_transfer(devHandle, BULK_READ_ENDPOINT, i2c_dev.ibuf, 512, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~~
| |
| long unsigned int *
/xxxx/SNANDer/build/libs/include/libusb-1.0/libusb.h:2043:14: note: expected ‘int *’ but argument is of type ‘long unsigned int *’
2043 | int *actual_length, unsigned int timeout);
| ~~~~~^~~~~~~~~~~~~
ch347_i2c.c:225:41: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
225 | fprintf(stderr, "actuallen(%d) != bytestoread(%d)\b", actuallen, bytestoread);
| ~^ ~~~~~~~~~
| | |
| int long unsigned int
| %ld
ch347_i2c.c: In function ‘ch347delay_ms’:
ch347_i2c.c:319:26: error: ‘devHandle’ undeclared (first use in this function); did you mean ‘handle’?
319 | libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, 3, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~
| handle
ch347_i2c.c:319:75: warning: passing argument 5 of ‘libusb_bulk_transfer’ from incompatible pointer type [-Wincompatible-pointer-types]
319 | libusb_bulk_transfer(devHandle, BULK_WRITE_ENDPOINT, i2c_dev.obuf, 3, &actuallen, DEFAULT_TIMEOUT);
| ^~~~~~~~~~
| |
| long unsigned int *
/xxxx/SNANDer/build/libs/include/libusb-1.0/libusb.h:2043:14: note: expected ‘int *’ but argument is of type ‘long unsigned int *’
2043 | int *actual_length, unsigned int timeout);
| ~~~~~^~~~~~~~~~~~~
ch347_i2c.c: At top level:
ch347_i2c.c:279:6: warning: ‘cbBulkOut’ defined but not used [-Wunused-function]
279 | void cbBulkOut(struct libusb_transfer *transfer)
| ^~~~~~~~~
ch347_i2c.c:252:6: warning: ‘cbBulkIn’ defined but not used [-Wunused-function]
252 | void cbBulkIn(struct libusb_transfer *transfer)
| ^~~~~~~~
make: *** [Makefile:49: snander] Error 1
make: Leaving directory '/xxxx/SNANDer/src'
make: Entering directory '/xxxx/SNANDer/src'
rm -f snander res.bin
make: Leaving directory '/xxxx/SNANDer/src'
xxxx@xxxx:~/xxxx/SNANDer$
@minkione Hi, The previous version had a problem due to the current system judgment. It has been fixed. https://github.com/ZhiyuanYuanNJ/SNANDer
这样修改后再编译出来的上位机好像识别编程器时有问题
编译出来的64位的程序用起来有问题
编译出来的64位的程序用起来有问题
因为是动态加载库方式,64位需要改为,LoadLibrary("CH347DLLA64.DLL");
修好了
另外ch347分支的不适合在linux下使用,虽然能编译出来,但其实是用不了的
具体是什么现象,是用的什么flash,我有时间时候再看下
@minkione Hi, The previous version had a problem due to the current system judgment. It has been fixed. https://github.com/ZhiyuanYuanNJ/SNANDer Thanks a lot! I just tried it and compiles fine! However I noticed some issues related with I2C...
@minkione Where was the program you used published, was it compiled by yourself, and what is the code repository address?
For Linux I did compile like this: And for Windows I downloaded this:
I did further tests even with @Droid-MAX 's ch347 branch...
git clone https://github.com/Droid-MAX/SNANDer snandertest
cd snandertest
git checkout ch347
./build-for-linux.sh
I get SNANDer working with the CH347T but not with the CH347F while trying to read an I2C Flash 24c08.
@minkione Hi, Updated fix, can try again. https://github.com/ZhiyuanYuanNJ/SNANDer
Hi, it works on Linux! Thanks a lot! Could you please compile it for Windows? Thus I will give it a try there too. 😊
windows: snander.zip
Yeah. Works too. Xie xie! 😊
I noticed one interesting issue... the SPI dump of the same SPI flash memory give different SHA1 hash. On both windows and linux.
Is it a phenomenon when using SPI: - r data.bin to read?
Is it a phenomenon when using SPI: - r data.bin to read?
支持ch347了吗,能刷写nand闪存了吗?
在Windows上读取I2C-EEPROM时会有这样的报错 failed to get ACKs 1 of 3 用的是沁恒官方的驱动 Status: BAD(-1) 不过板子上对应的i2c操作指示灯有反应
在Windows上读取I2C-EEPROM时会有这样的报错 failed to get ACKs 1 of 3 用的是沁恒官方的驱动 Status: BAD(-1)
已修改
对了,我是没有安装eeprom芯片进行测试的,因为之前用ch341a编程器时,没装芯片进行读取也是ok,所以我以为347不装芯片直接进行读取也是可以的。。
好像microwire/93c系列的芯片操作暂不支持。。
Is it a phenomenon when using SPI: - r data.bin to read?
Correct!
Some differences between different SPI dumps. As you see, the differences are not consistent between the files... The bytes change in different positions...
I'm not quite sure where the problem is. I used NOR Flash: W25Q16JQ, Flash Size: 2 MB, read it three times, and the files are consistent
@minkione Try project flashrom:https://github.com/flashrom/flashrom, have same problem? flashroom.zip
Intersting behaviour happening... On Linux flashrom works perfect (I did use and compile the flashrom version from github). 3 different dumps of the same SPI flash memory... and same SHA1. All good.
Tried with another SPI flash... Now everything looks working fine! on both flashrom and SNANDer. 👍 Probably it is that specific SPI Flash that creates issues for some reasons...
在linux系统中使用ch347版本的snander时,如果没有插上ch347编程器直接执行snander -i命令的话会crash,也会报段错误
在linux系统中使用ch347版本的snander时,如果没有插上ch347编程器直接执行snander -i命令的话会crash,也会报段错误
返回值错了,已修正
现在支持ch347了吗
最好是使用官方的ch347开发板
现在支持ch347了吗
可以使用,https://github.com/ZhiyuanYuanNJ/SNANDer/releases/tag/v1.0
The CH347 supports hardware SPI for faster speed