====== Information ======
* Using a Raspberry Pi to read and write to a 8-pin chip using flashrom
====== Requirements ======
* Raspberry Pi ((https://www.raspberrypi.org/products/)) ((I've only tested the **2 Model B** and **3 Model B**))
* Raspbian ((https://www.raspbian.org/))
* flashrom ((in Raspbian repos or can be compiled))
* Pomona SOIC Clip Model 5250, 8 Pin ((https://www.pomonaelectronics.com/products/test-clips/soic-clip-8-pin)) ((any similar 8-pin SOIC clip should work))
* Male to Female Breadboard wires ((to connect the SOIC clip to the Pi's GPIO pins))
* TODO: Separate notes for 16-pin if needed
====== Pi ======
===== Configuration =====
* Install Raspbian
* Update Raspbian packages
* Enable SPI ((TODO: Is this needed? May be enabled out-the-box))
===== 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 ====
* https://www.raspberrypi.org/documentation/usage/gpio/images/gpio-numbers-pi2.png
* The GPIO 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
* 5v, far-left 3.3v, 21, and far-right GND are unused and only provided for reference
----------------------------------------------------------------------------------------------------------- ----------
| [5v ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ 8] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [21 ] | | |
O [3.3V] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [3.3V] [10] [ 9] [11] [GND] [ ] [ ] [ ] [ ] [ ] [ ] [GND] O | USB |
| | | |
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV (chips and other stuff below) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
====== W25Q64FV ======
===== Information =====
* [[https://www.pjrc.com/store/w25q64fv.pdf|Spec Sheet]]
* 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 ((TODO: separate notes?))
===== 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 ((the circle notch on the chip is top-left))
* The numbers here refer to the [[#physical|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'' ((this requires a Git build))
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 =====
* https://github.com/corna/me_cleaner/blob/master/me_cleaner.py#L478
* ''--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 ((safest option if in doubt))
* 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 ==
* [[linux;distros;fedora_workstation_gnome|Fedora Workstation (GNOME)]]
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 ==
* [[linux;distros;fedora_workstation_gnome|Fedora Workstation (GNOME)]]
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