nfd / spi-flash-programmer

SPI flash programmer sketch and client library for Arduino
Creative Commons Zero v1.0 Universal
98 stars 26 forks source link

could not write page 0x00000000 #18

Closed thndrtk closed 1 year ago

nfd commented 3 years ago

This is a generic message when something goes wrong with the write, and because it's the first page it's likely that it can't communicate with the chip at all. Try again with --debug=verbose.

thndrtk commented 3 years ago

I know it's connected properly it can read and it can write but only my bios file said it can't write it

modante commented 1 year ago

I get the same error when trying to flash this file:

python3 spi_flash_programmer_client.py -l -1 -d /dev/ttyUSB0 -f Archer-MR200v2_recovery.bin write --debug=verbose
Opening serial connection
Serial connection opened successfully
Command: HELLO
Send: '>'
Waiting for '>'
Recv: '>'
Reading until '>'
Recv: 'S'
Recv: 'P'
Recv: 'I'
Recv: ' '
Recv: 'F'
Recv: 'l'
Recv: 'a'
Recv: 's'
Recv: 'h'
Recv: ' '
Recv: 'p'
Recv: 'r'
Recv: 'o'
Recv: 'g'
Recv: 'r'
Recv: 'a'
Recv: 'm'
Recv: 'm'
Recv: 'e'
Recv: 'r'
Recv: ' '
Recv: 'v'
Recv: '1'
Recv: '.'
Recv: '0'
Recv: '
'
Recv: '
'
Recv: '>'
Connected to 'SPI Flash programmer v1.0'
Command: ERASE_SECTOR 0          ] 0/31744 - 00:00:00
Send: 'k00000000'
Waiting for 'k'
Recv: 'k'
Send: 'sff00001000000000fd00001000000000830200100000000081020010000000007f020010000000007d020010000000007b02001000000000790200100000000077020010000000007502001000000000730200100000000071020010000000006f020010000000006d020010000000006b02001000000000690200100000000067020010000000006502001000000000630200100000000061020010000000005f020010000000005d020010000000005b02001000000000590200100000000057020010000000005502001000000000530200100000000051020010000000004f020010000000004d020010000000004b020010000000004902001000000000'
Waiting for 's'
Recv: 's'
Send: 'w00000000'
Waiting for 'w'
Recv: 'w'
Command: FLASH_READ_MULTIPLE 0
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
CRC is valid
Command: ERASE_SECTOR 0          ] 0/31744 - 00:00:00
Send: 'k00000000'
Waiting for 'k'
Recv: 'k'
Send: 'sff00001000000000fd00001000000000830200100000000081020010000000007f020010000000007d020010000000007b02001000000000790200100000000077020010000000007502001000000000730200100000000071020010000000006f020010000000006d020010000000006b02001000000000690200100000000067020010000000006502001000000000630200100000000061020010000000005f020010000000005d020010000000005b02001000000000590200100000000057020010000000005502001000000000530200100000000051020010000000004f020010000000004d020010000000004b020010000000004902001000000000'
Waiting for 's'
Recv: 's'
Send: 'w00000000'
Waiting for 'w'
Recv: 'w'
Command: FLASH_READ_MULTIPLE 0
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
CRC is valid
Command: ERASE_SECTOR 0          ] 0/31744 - 00:00:00
Send: 'k00000000'
Waiting for 'k'
Recv: 'k'
Send: 'sff00001000000000fd00001000000000830200100000000081020010000000007f020010000000007d020010000000007b02001000000000790200100000000077020010000000007502001000000000730200100000000071020010000000006f020010000000006d020010000000006b02001000000000690200100000000067020010000000006502001000000000630200100000000061020010000000005f020010000000005d020010000000005b02001000000000590200100000000057020010000000005502001000000000530200100000000051020010000000004f020010000000004d020010000000004b020010000000004902001000000000'
Waiting for 's'
Recv: 's'
Send: 'w00000000'
Waiting for 'w'
Recv: 'w'
Command: FLASH_READ_MULTIPLE 0
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
Command: FLASH_READ 0
Send: 'r00000000'
Waiting for 'r'
Recv: 'r'
CRC is valid
Could not write page 0x00000000
[################################] 0/31744 - 00:00:00
Aborting

I was able to dump the entire content of the eeprom at 115200 baud rate. I changed baud rate to 57600 in .ino and .py before to write but this happens. Any idea?

nfd commented 1 year ago

What chip are you examining? Some require a special code to enable writes.

modante commented 1 year ago

What chip are you examining? Some require a special code to enable writes.

Winbond W25Q64 (8MB) The EEPROM included in TP-Link Archer MR200 router: https://openwrt.org/toh/tp-link/archer_mr200

nfd commented 1 year ago

This chip is write protected by default. See section 5.2 of the datasheet here: https://www.pjrc.com/store/w25q64fv.pdf

The Python client has commands options to set, check, or disable write protection. You might want to try those first before delving into modifying the programmer for your chip.

modante commented 1 year ago

I checked protection and is disabled:

$ python3 spi_flash_programmer_client.py -d /dev/ttyUSB0 check-protection --debug=verbose
Opening serial connection
Serial connection opened successfully
Command: HELLO
Send: '>'
Waiting for '>'
Recv: '>'
Reading until '>'
Recv: 'S'
Recv: 'P'
Recv: 'I'
Recv: ' '
Recv: 'F'
Recv: 'l'
Recv: 'a'
Recv: 's'
Recv: 'h'
Recv: ' '
Recv: 'p'
Recv: 'r'
Recv: 'o'
Recv: 'g'
Recv: 'r'
Recv: 'a'
Recv: 'm'
Recv: 'm'
Recv: 'e'
Recv: 'r'
Recv: ' '
Recv: 'v'
Recv: '1'
Recv: '.'
Recv: '0'
Recv: '
'
Recv: '
'
Recv: '>'
Connected to 'SPI Flash programmer v1.0'
Command: WITE_PROTECTION_CHECK
Send: 'x'
Waiting for 'x'
Recv: 'x'
Configuration is unprotected
Flash content is unprotected
Done
modante commented 1 year ago

I have also tried to disconnect /WP pin from 3.3 and connect it to GND and I cannot avoid the same error when trying to write the firmware. I had originally connected the /WP pin to 3.3v

modante commented 1 year ago

Finally I got to flash the firmware on W25Q64 EEPROM changing #define SPI_SPEED F_CPU/12 instead of #define SPI_SPEED F_CPU/2 I left baudrate at 115200. After 2 and half hours, the firmware was written and I could unbrick the router :-)

nfd commented 1 year ago

Oh hooray, thanks for reporting! Quite an odd failure mode don't you think? Or perhaps we need to wait a while after the write before trying to read back, and the slow SPI speed just happened to slow it down enough that that happened (effectively)?

modante commented 1 year ago

I wouldn't know what to say, I don't have much technical knowledge

Any suggestion to improve the speed?

nfd commented 1 year ago

I think probably what we should be doing is reading the status register and checking the BUSY bit and waiting until it's cleared before we attempt to read the page back. Unfortunately I don't have the set-up to test such a thing at the moment though.

modante commented 1 year ago

If I can help you in any way, I can make some tests with my setup :-)