User Tools

Site Tools


bios:notes:rpi_flashrom

Information

  • Using a Raspberry Pi to read and write to a 8-pin chip using flashrom

Requirements

  • Raspberry Pi 1) 2)
  • Raspbian 3)
  • flashrom 4)
  • Pomona SOIC Clip Model 5250, 8 Pin 5) 6)
  • Male to Female Breadboard wires 7)
  • TODO: Separate notes for 16-pin if needed

Pi

Configuration

  • Install Raspbian
  • Update Raspbian packages
  • Enable SPI 8)

Pins

Physical

  • The physical numbering and order of the pins on a Pi
  • [ ] represents a pin
  • O represents a mounting hole
  • The ASCII art assumes the I/O ports are on the right-side and the pins are at the top
  • 1, 2, 3, 4, 37, 38, 39, and 40 are unused and only provided for reference as to pin order
 -----------------------------------------------------------------------------------------------------   ----------
| [ 2] [ 4] [  ] [  ] [  ] [  ] [  ] [  ] [  ] [  ] [  ] [24] [  ] [  ] [  ] [  ] [  ] [  ] [38] [40] | |          |
O [ 1] [ 3] [  ] [  ] [  ] [  ] [  ] [  ] [17] [19] [21] [23] [25] [  ] [  ] [  ] [  ] [  ] [37] [39] O |   USB    |
|                                                                                                     | |          |
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV (chips and other stuff below) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

GPIO

 -----------------------------------------------------------------------------------------------------------   ----------
| [5v  ] [  ] [  ] [  ] [  ] [  ] [  ] [  ] [    ] [  ] [  ] [ 8] [   ] [  ] [  ] [  ] [  ] [  ] [  ] [21 ] | |          |
O [3.3V] [  ] [  ] [  ] [  ] [  ] [  ] [  ] [3.3V] [10] [ 9] [11] [GND] [  ] [  ] [  ] [  ] [  ] [  ] [GND] O |   USB    |
|                                                                                                           | |          |
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV (chips and other stuff below) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

W25Q64FV

Information

  • This chip is commonly used as a BIOS chip on computer motherboards
  • Detects as a W25Q64.V in flashrom
  • :!: On a XPS 13, the chip identifies as a W25Q256.V and follows the same pin layout and instructions 9)

Pins

  • Numbering of the pins on the chip according to the spec sheet
      --------
[1]__|O       |__[8]
[2]__|  Chip  |__[7]
[3]__|        |__[6]
[4]__|        |__[5]
      --------

Pin Descriptions

  • What the pins on the chip do
        --------
[/CS]__|O       |__[VCC]
 [DO]__|  Chip  |__[/HOLD]
[/WP]__|        |__[CLK]
[GND]__|        |__[DI]
        --------

SOIC Clip to Pi Pins

  • The \ \ represents the springs on the clip
  • This image assumes the clip's pins are on the left and right side in the same orientation as the above pictures 10)
  • The numbers here refer to the physical pins on the Pi and their numbering, not GPIO pin numbers
[24]      [17]
[21] \ \  [  ]
[  ]  \ \ [23]
[25]      [19]

flashrom

Install

Pre-compiled

  • As of 2018/04/27, this supports a W25Q64FV
  • As of 2018/12/09, this does not support a W25Q256.V 11)
sudo apt install 'flashrom'

Git Compile

Dependencies

sudo apt install libpci-dev libftdi-dev libusb-1.0-0-dev git-core build-essential

Get Source

rm -Rf ~/'flashrom' && git clone -b 'master' 'https://github.com/flashrom/flashrom.git' ~/'flashrom' --depth '1'

Build

cd ~/'flashrom' && make --jobs='4' && sync

Test Chip Read

  • Assumes the SOIC clip is connected to the Pi correctly and that SPI is enabled
  • All 3 md5sums need to match to ensure consistent read/write to the chip
  • spispeed=8000 is necessary for reading from a W25Q64FV chip
sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --read ~/'test1.bin' && sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --read ~/'test2.bin' && sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --read ~/'test3.bin' && sync
md5sum ~/'test1.bin' && md5sum ~/'test2.bin' && md5sum ~/'test3.bin'
rm -fv ~/'test2.bin' ~/'test3.bin' && sync

Backup

  • :!: Super-important to have a checksum-verified back-up to fall-back to when doing BIOS modifications
  • Back this up somewhere external before doing anything else
  • To be extra safe, also md5sum it and compare to above tests
  • :!: spispeed=8000 is necessary for reading from a W25Q64FV chip
sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --read ~/'backup-original.bin' && sync
md5sum ~/'test1.bin' && md5sum ~/'backup-original.bin'
rm -fv ~/'test1.bin' && sync

Flash

  • Change x to the location of the new ROM you want flashed
  • :!: spispeed=8000 is necessary for writing to a W25Q64FV chip
  • :!: Change spispeed as-needed
sync && sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --write x

me_cleaner

  • TODO: Is ifdtool better for HAP bit?

Get Source

git clone -b 'master' 'https://github.com/corna/me_cleaner.git' ~/'me_cleaner' --depth '1'

Check Original BIOS

python ~/'me_cleaner/me_cleaner.py' --check ~/'backup-original.bin'

Clean ME

  • --descriptor caused an Acer laptop to not boot; remove if it causes problems
  • --soft-disable-only can be used to set the MeAltDisable or HAP bit only and not remove partitions 12)
  • Use no arguments in order to remove partitions and not touch MeAltDisable or HAP bit
python ~/'me_cleaner/me_cleaner.py' --soft-disable --descriptor --output ~/'me_cleaner-soft-disable-descriptor.bin' ~/'backup-original.bin'

Flash Modified BIOS

  • Change spispeed as-needed
sync && sudo flashrom --programmer 'linux_spi':'dev=/dev/spidev0.0,spispeed=8000' --write ~/'me_cleaner-soft-disable-descriptor.bin'

Clean-up

cd ~ && rm -Rf ~/'flashrom' && sync

Verifying ME

Windows

  • TODO: Involves MEManuf and -VERBOSE flag

Linux

Coreboot

  • Need Coreboot sources for some utilities
cd ~ && mkdir -p ~/'Projects' && rm -Rf ~/'Projects/coreboot/src' && git clone --branch 'master' --depth '1' 'https://github.com/coreboot/coreboot.git' ~/'Projects/coreboot/src' && sync

intelmetool

Dependencies
sudo dnf install 'pciutils-devel'
Compile

cd ~/'Projects/coreboot/src/util/intelmetool' && make --jobs='3' && sync
Run

cd ~/'Projects/coreboot/src/util/intelmetool' && sudo ~/'Projects/coreboot/src/util/intelmetool/intelmetool' --help

ifdtool

Dependencies
sudo dnf install 'pciutils-devel'
Compile

cd ~/'Projects/coreboot/src/util/ifdtool' && make --jobs='3' && sync
Notes
  • Can be used to set the HAP bit, similar to me_cleaner's --soft-disable-only
  • Can be used to dump information about ME on a BIOS image, good for checking if it's a valid dump like me_cleaner's --check option
  • Can unlock R/W on chip areas much more thoroughly than me_cleaner
Run

cd ~/'Projects/coreboot/src/util/ifdtool' && ~/'Projects/coreboot/src/util/ifdtool/ifdtool' --help
2)
I've only tested the 2 Model B and 3 Model B
4)
in Raspbian repos or can be compiled
6)
any similar 8-pin SOIC clip should work
7)
to connect the SOIC clip to the Pi's GPIO pins
8)
TODO: Is this needed? May be enabled out-the-box
9)
TODO: separate notes?
10)
the circle notch on the chip is top-left
11)
this requires a Git build
12)
safest option if in doubt
/usr/local/www/wiki/data/pages/bios/notes/rpi_flashrom.txt · Last modified: by 127.0.0.1