Flashing a SPI (BIOS) chip with an Arduino

In this post I will share how you can use an Arduino to flash/program chips through the Serial Peripheral Interface (SPI). I used this method myself to repair a ASUS-P5B motherboard that had it’s BIOS erased after a failed update.

Requirements

Hardware

  • Arduino Uno/Duemilanove or Mega (more info here)
  • A chip that is supported by flashrom (full list available here)

Software

  • VM Player/Workstation (I tried using Virtualbox but for some reason it does not play nice, flashrom will see the chip but will not actually read or write)
  • An Ubuntu 16 or 18 Virtual Machine
  • flashrom
  • fser-duino

The process

Installing git, flashrom and dependencies for frser-duino

sudo apt install git flashrom gcc-avr binutils-avr avr-libc avrdude

Getting frser-duino and preparing the Arduino

git clone --recursive git://github.com/urjaman/frser-duino
cd frser-duino
make ftdi
sudo make flash-ftdi

Connecting the Arduino to the SPI chip

The following image is an example schematic taken from the flashrom GitHub and shows the pins on the Arduino and the pins on the chip they should connect to (please note that PB0 does not have to be connected):

The image below shows the pinout for the MX25L8005:

Please note that different manufacturers might use different pinouts for their chips and you should therefore always check the datasheet for the correct one.

Flashing the SPI chip

To verify that everything is working correctly we first run flashrom without any operations:

sudo flashrom -p serprog:dev=/dev/ttyUSB0:2000000

The output should look like this:

flashrom v0.9.9-91-g0bfa819 on Linux 4.10.0-28-generic (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
serprog: Programmer name is "frser-duino"
Found Macronix flash chip "MX25L8005" (1024 kB, SPI) on serprog.
No operations were specified.

If the previous command worked as expected we are now ready for our final step. To write the new BIOS to the chip we use the following command:

sudo flashrom -p serprog:dev=/dev/ttyUSB0:2000000 -w [NEWBIOS]

The output should look like this:

flashrom v0.9.9-91-g0bfa819 on Linux 4.10.0-28-generic (x86_64) flashrom is free software, get the source code at https://flashrom.org Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns). serprog: Programmer name is "frser-duino" Found Macronix flash chip "MX25L8005" (1024 kB, SPI) on serprog. Reading old flash chip contents... done. Erasing and writing flash chip... Erase/write done. Verifying flash... VERIFIED. 

And that is it. We have successfully flashed a chip using the SPI interface. If you have any questions or feedback about this post please leave a comment below!

References