title: How to program an SPI flash chip with the Raspberry Pi ...
This document exists as a guide for reading from or writing to an SPI flash chip with the Raspberry Pi, using the flashrom software. Most revisions of the RPi should work, so long as it has SPI on the GPIO header.
A more popular flasher nowadays is the CH341A: DO NOT use it, it has 5V logic on the data lines which will cause damage to your system if you use it. We recommend the RPi or SMT32 Blue Pill (the latter will be documented on the Retroboot website at a later date. I, Leah Rowe, have some bluepills and I will be experimenting with them).
The Raspberry Pi (a $25 single board computer - SBC) can be used as a 25xx flashing tool (25XX NOR flash via SPI protocol).
If your flash chip is a SOIC-8 and mounted to a mainboard, you can use a test clip. This is a special clip (popular brand is the Pomona 5252 test clip). This is called In System Programming or ISP for short.
There exist many different clips online. Search for SO8/SOIC8/SO-IC8/SOIC-8 test clip. It will either be a Pomona 5252 or look very similar to it. The RPi has male GPIO header pins, on which you can use female dupont leads; on the other end you normally also use female lead, so get female 2.54mm / 0.1inch dupont female-female (F-F) leads.
Some test clips will have the pins too close, but you can bend them so that your dupont leads will fit. Alternatively, you can use a dupont lead on the RPi GPIO header but on the test clip side, strip, tin and solder to the pins on the test clip (and use heatshrink tubing for insulation and strain relief).
Diagram of the 26 GPIO Pins of the Raspberry Pi Model B (for the Model B+ with 40 pins, start counting from the right and leave 14 pins):
Pin # 25xx signal Raspberry Pi
1 CS 24 2 MISO 21 3 not used not used 4 GND 25 5 MOSI 19 6 CLK 23 7 not used not used 8 3.3V
Make sure the pinouts are correct; otherwise, Flashrom will fail to
detect a chip, or it will "detect" a 0x0
chip. Finally, make sure
that the Pomona clip makes contact with the metal wires of the chip.
DO NOT connect +3.3V until the clip is connected. This is why dupont leads are good. Pin 1 on the RPi GPIO header is 3.3v. Leave it disconnected but when the clip is connected, plug in the dupont lead to the 3.3v pin on the RPi to active power. This reduces the risk of shorting +3.3v to something when you're connecting the test clip.
There are two ways to supply power to the chip: plugging in an AC adapter (without turning the laptop on), and using the 8th 3.3v pin.
NOTE: The AC adapter trick (on laptops) doesn't always work, but on some laptops it will work. Verify this by checking the DC voltage on pin 8 of the flash chip (SOIC-8 one). If it's not 3.3v, then on some laptops you can also enable Wake on LAN and plug in both AC adapter (laptop battery charger cable) and the LAN cable and sometimes that will active the 3.3v power rail; between 2.7v to 3.6v is acceptable.
Otherwise, your raspberry pi has 3.3v on it, on pin 1. However, note that some other components on the laptop (or other) mainboard might be powered aswell when doing this, and the RPi might not be able to provide enough current (in this situation, a proper lab PSU might be beneficial).
Never connect both the 8th pin and the AC adapter at the same time.
First, visually inspect (with a magnifying glass) the type of flashchip on the motherboard.
In the Retroboot build system, from the Git repository, you can download and install flashrom. Do this after downloading the Retroboot Git repository:
cd retroboot
sudo ./build dependencies ubuntu2004
./download flashrom
./build module flashrom
A flashrom/
directory will be present, with a flashrom
executable inside
of it. If you got an error about missing package when running the dependencies
command above, tweak resources/scripts/build/dependencies/ubuntu2004
. That
script downloads and installs build dependencies in apt-get and it is intended
for use on x86-64 systems running Ubuntu 20.04, but it should work in Raspbian
on the Raspberry Pi.
In your Raspberry Pi, which we assume you're running the latest Raspbian version on, do this:
sudo raspi-config
Under Interface section, you can enable the SPI interface.
Run this command to see if 25xx flash is detected, with your RPi connected via test clip:
sudo ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=32768
NOTE: On some systems, higher speeds will be unstable. On those systems, try
lower speed like spispeed=4096
or even spispeed=2048
which should, in most
cases, work just fine but it will obviously be slower. The spispeed=32768
setting works just fine on X220/X230 if you use short wires (within 10cm long).
If flash chip is detected you may try reading (dumping) the flash contents now, or you can try flashing it with a new ROM.
Note: replace /path/to/retroboot.rom
with the location of your chosen ROM file.
Next, run this command:
sudo ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=32768 -w /path/to/retroboot.rom
Again, use a lower spispeed
value if you need to, for stability.
Once that command outputs the following, the flash has completed successfully. If not, just flash again.
Reading old flash chip contents... done.
Erasing and writing flash chip... Erase/write done.
Verifying flash... VERIFIED.
If you have this type of chip, use Pomona 5250 clip or similar test clip. The steps are identical, except for a different pinout. See below:
Pin # 25xx signal Raspberry Pi Pin #
1 not used not used 2 3.3V 1 3 not used not used 4 not used not used 5 not used not used 6 not used not used 7 CS# 24 8 MISO 21 9 not used not used 10 GND 25 11 not used not used 12 not used not used 13 not used not used 14 not used not used 15 MOSI 19 16 SCLK 23
WSON8 has the same pinout as SOIC8, but it's a ball mounted QFN (quad flat pack, no leads). There are no clips for it.
We recommend this:
External re-flashing with SOIC8 clip is now very easy, if you ever need to do so later on, using ISP method as documented above.
An example of the above is on the following YouTube videos:
Flashing new SOIC8 chip with SOIC/DIP adapter socked on a breadboard, connected to RPi: https://www.youtube.com/watch?v=tguch_iPBZQ
Replacing WSON8 flash with SOIC8 on a ThinkPad X200 Tablet, for Libreboot: https://www.youtube.com/watch?v=MxMKJsg5IEU
This page is available under the CC BY SA 4.0 Check Retroboot Git repository for history of who owns what part of the document. It was forked from the Libreboot project, so check ownership history in the Libreboot git repository aswell.