Flashing a BIOS chip with a Raspberry Pi

I made this post as a addition or supplement to my “Flashing a BIOS chip with an Arduino” post.

While doing some research online I found several articles/posts from people using a Raspberry Pi to flash SPI flash chips. Apparently the Raspberry Pi  is very suitable for this kind of thing as it has a SPI interface and is able to run linux. I was eager to try this out for myself so I got out my Pi 3 model B and got to work. For this project I used a Winbond 25X80 salvaged from a motherboard I had lying around.

Preparing the RaspberryPi

I’ve tried different versions of Raspbian but Jessie lite seems to works best for me. It is available for download here: https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/

Install the packages needed by flashrom by using the following command:

sudo apt-get install pciutils libpci-dev libusb-1.0 libusb-dev git

Build and install flashrom using the commands below:

git clone https://github.com/flashrom/flashrom.git
cd flashrom
make && make install

Before continuing we need to enable the SPI interfaces on the Raspberry Pi. This can be done either by editing the config file found at /boot/config.txt and uncommenting the line that says #dtparam=spi=on or by using raspi-config. Run raspi-config, and under interfaces enable SPI.

After rebooting the SPI interfaces are available under /dev/spidev0.0 and /dev/spidev0.1.

Connecting the Raspberry to the SPI flash chip

The table below show the connections between the RaspberryPi and the chip.

RPi pin SPI flash
25 GND
24 CS
23 SCK
21 DO
19 DI
17 VCC 3.3V and /HOLD and /WP

In order to verify flashrom is working correctly and the chip is detected properly we run flashrom without any operation. Example output can be found below:

pi@raspberrypi:~ $ flashrom -p linux_spi:dev=/dev/spidev0.1
flashrom v0.9.9-91-g0bfa819 on Linux 4.9.35-v7+ (arm7l)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns). 
Found Winbond flash chip "W25X80" (1024 kB, SPI) on linux_spi. 
No operations were specified.

Now that we have verified everything is in order we can start writing the BIOS to the chip:

pi@raspberrypi:~ $ flashrom -p linux_spi:dev=/dev/spidev0.1 -w YOURBIOS
flashrom v0.9.9-91-g0bfa819 on Linux 4.9.35-v7+ (armv7l)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
Found Winbond flash chip "W25X80" (1024 kB, SPI) on linux_spi.
Reading old flash chip contents... done.
Erasing and writing flash chip... Erase/write done.
Verifying flash... VERIFIED.

And that is that.

Resources:

Flashing a bios chip with an Arduino

In this post I will describe how to flash a BIOS (SPI) chip using a Arduino Duemilanove. I first learned about this method after reading about it on hackaday. At the time I had a Asus P5B motherboard that suffered from a bad BIOS flash and needed to be recovered. I tried other methods before but found none were as easy as this one.

So lets get started.

The requirements

Hardware

  • Arduino Duemilanove (full list can be found here https://www.flashrom.org/Serprog/Arduino_flasher )
  • A flash chip that is supported by flashrom ( full list available here https://www.flashrom.org/Supported_hardware )

Software

  • Ubuntu 16.04 VM
  • Flashrom
  • Fser-duino

Preparing the environment

Installing Git and the dependencies needed for Flashrom and frser-duino:

sudo apt-get install git libpci-dev libusb-dev libusb-1.0 gcc-avr binutils-avr gdb-avr avr-libc avrdude

Compiling and installing Flashrom

git clone git://github.com/flashrom/flashrom.git
cd flashrom
make && make install

Preparing the Arduino Duemilanove

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

The table below shows which pins on the Arduino should go to which pin on the SPI flash chip.

Arduino Pins SPI Pins
12 SO
11 SI
10 CS
13 SCLK
3.3V VCC +/WP + /HOLD
GND GND

Flashing the SPI chip

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

tom@ubuntu-vm:~$ sudo flashrom -p serprog:dev=/dev/ttyUSB0:2000000
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.

As can be seen from the above command output, both the Arduino and the SPI chip are detected. Now we can continue with writing the new BIOS to the chip:

tom@ubuntu-vm:~$ sudo flashrom -p serprog:dev=/dev/ttyUSB0:2000000 -w <NEWBIOS>

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 thats it, the new BIOS is written to the chip and all that is left is testing if my computer boots up again.

Resources:

HP ENVY SPECIFIC: