This is a very simple Arduino sketch and Python client to program SPI flash chips. It's probably not very nice or tolerant, but it does at least have error correction and fast verification (and needs both!)
It requires pySerial.
To use it, write the Arduino program, connect your chip, and run the Python client.
Connect the chip as follows, assuming you have an 8-pin SSOP Flash chip:
Chip pin | Arduino pin |
1 /SS | 10 |
2 MISO | 12 |
3 /WP | +3.3V |
4 GND | GND |
5 MOSI | 11 |
6 SCK | 13 |
7 /HOLD | +3.3V |
8 VDD | +3.3V |
You will need an Arduino running at 3.3V logic.
python3 spi_flash_programmer_client.py -d /dev/cu.usbserial --flash-offset 0 -s 4096 -f dump.bin read
python3 spi_flash_programmer_client.py -d /dev/cu.usbserial --flash-offset 0 -s 4096 -f dump.bin write
python3 spi_flash_programmer_client.py -d /dev/cu.usbserial --flash-offset 0 -s 4096 -f dump.bin verify
- Try reducing the serial speed from 115200 to 57600. You'll have to edit the value in both the .ino and the .py.
- Play with the SPCR setting in the .ino according to the datasheet.
I used this to write a 16MB flash chip for the wr703n router running OpenWRT. Recent versions of OpenWRT detect the larger Flash and automatically use it, so you don't need to do any patching. U-Boot still thinks the chip is 4MB large, but Linux doesn't seem to care. So all you need to do is copy the image and write the ART (wireless firmware) partition to the right spot, which is right at the end of Flash.
I guess if you do a system upgrade which puts the kernel image somewhere after the first 4MB you might be in trouble, so upgrade u-boot before doing that.
-
Connect the original chip and dump it:
python3 spi_flash_programmer_client.py -s 4096 -f wr703n.orig.bin read
-
Connect the new chip and write it:
python3 spi_flash_programmer_client.py -s 4096 -f wr703n.orig.bin write
-
Verify the write.
python3 spi_flash_programmer_client.py -s 4096 -f wr703n.orig.bin verify
-
Write the ART partition to the final 64k of the chip (the magic numbers are 16M-64K and 4M-64K respectively).
python3 spi_flash_programmer_client.py -f wr703n.orig.bin --flash-offset 16711680 --file-offset 4128768 write
-
Verify the ART partition.
python3 spi_flash_programmer_client.py -f wr703n.orig.bin --flash-offset 16711680 --file-offset 4128768 verify
-
Solder the new chip in.
If you try this, let me know!