rpi_setup.md 18 KB

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.

This only covers SOIC-8 flash chips, for now. SOIC-16 guide coming later (for now, it should be easy enough for you to figure this out for SOIC-16).

Back to previous index

[](#raspberry-pi-thinkpad-x60t60-and-macbook-21){#user-content-raspberry-pi-thinkpad-x60t60-and-macbook-21 .anchor}Raspberry Pi (ThinkPad X60/T60 and Macbook 2,1)

The Raspberry Pi (a multipurpose \$25 GNU+Linux computer) can be used as a BIOS flashing tool, thanks to its GPIO pins and SPI support.

Note: The Raspberry Pi Model A is not supported, since it has no GPIO pins.

[](#disassembling-the-thinkpad){#user-content-disassembling-the-thinkpad .anchor}Disassembling the ThinkPad

Follow the X60 Hardware Maintenance Manual or T60 Hardware Maintenance Manual to disassemble the laptop, until you can access the BIOS chip.

For photos, follow the Libreboot T60 Recovery Guide.

  • On the X60, the BIOS chip is on the bottom of the motherboard, under a layer of protective black tape.
  • On the T60, the BIOS chip is just under the palmrest, but blocked by a magnesium frame (which you will have to remove).

[](#pomona-clip-pinout){#user-content-pomona-clip-pinout .anchor}Pomona Clip Pinout

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):

 8-pin for X60:

~~~~ LCD (Front) ~~~~
        8765
        ----
        |  |
        ----
        1234
~~~ Palmrest (back) ~~

Pin # SPI Pin Name BP (Seeed) BP (Spkfun) Beagleboard Black Raspberry Pi


1 CS White Red Pin 17 24 2 MISO Black Brown Pin 21 21 3 not used not used not used not used not used 4 GND Brown Black Pin 1 25 5 MOSI Gray Orange Pin 18 19 6 CLK Purple Yellow Pin 22 23 7 not used not used not used not used not used 8 3.3V red White 3.3V PSU RED 17

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. It can be a challenge, but keep trying.

[](#how-to-supply-power-to-the-flashchip){#user-content-how-to-supply-power-to-the-flashchip .anchor}How to supply power to the flashchip

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.

I have found that the SST chips work best with the 8th pin, while the Macronix chips require an AC Adapter to power up.

Never connect both the 8th pin and the AC adapter at the same time.

Your results may vary.

[](#reading-the-flashchip){#user-content-reading-the-flashchip .anchor}Reading the Flashchip

First, visually inspect (with a magnifying glass) the type of flashchip on the motherboard.

Next, download and compile the latest Flashrom source code on the Raspberry Pi.

sudo apt-get install build-essential pciutils usbutils libpci-dev libusb-dev libftdi1 libftdi-dev zlib1g-dev subversion
svn co svn://flashrom.org/flashrom/trunk flashrom
cd flashrom
make
sudo modprobe spi_bcm2708
sudo modprobe spidev

If your chip is an SST, run this command:

sudo ./flashrom -p linux_spi:dev=/dev/spidev0.0 -r test.rom

If your chip is a Macronix, run this command:

sudo ./flashrom -c "MX25L1605" -p linux_spi:dev=/dev/spidev0.0 -r test.rom

Next, check the md5sum of the dump:

md5sum test.rom

Run the flashrom command again to make a second dump. Then, check the md5sum of the second dump:

md5sum test.rom

If the md5sums match after three tries, flashrom has managed to read the flashchip precisely (but not always accurately). You may try and flash Libreboot now.

[](#flashing-libreboot){#user-content-flashing-libreboot .anchor}Flashing Libreboot

Note: replace /path/to/libreboot.rom with the location of your chosen ROM, such as ../bin/x60/libreboot_usqwerty.rom):

If your chip is an SST, run this command:

sudo ./flashrom -p linux_spi:dev=/dev/spidev0.0 -w /path/to/libreboot.rom

If your chip is a Macronix, run this command:

sudo ./flashrom -c "MX25L1605" -p linux_spi:dev=/dev/spidev0.0 -w /path/to/libreboot.rom

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.

[](#sources){#user-content-sources .anchor}Sources

[](#raspberry-pi-pinout-diagrams){#user-content-raspberry-pi-pinout-diagrams .anchor}Raspberry Pi Pinout Diagrams

MCP 3008 Pin Pi GPIO Pin # Pi Pin Name


16 VDD 1 3.3 V 15 VREF 1 3.3 V 14 AGND 6 GND 13 CLK 23 GPIO11 SPI0_SCLK 12 DOUT 21 GPIO09 SPI0_MISO 11 DIN 19 GPIO10 SPI0_MOSI 10 CS 24 GPIO08 CE0 9 DGND 6 GND

[](#raspberry-pi-thinkpad-x200){#user-content-raspberry-pi-thinkpad-x200 .anchor}Raspberry Pi (ThinkPad X200)

[](#requirements){#user-content-requirements .anchor}Requirements:

  • An x86, x86_64, or arm7l (for changing the libreboot.rom image mac address)
  • Raspberry Pi and peripherals
  • Relevant SOIC clip
  • 6 female - female jumpers
  • Internet connection
  • Screw drivers

Follow the ThinkPad X200: Initial installation guide to disassemble the laptop, and access the BIOS rom chip.

Note: x86# refers to commands to be run on the x86 computer, and pi# refers to commands to be run on the pi. A good practice is to make a work directory to keep your libreboot stuff inside.

x86# mkdir ~/work

Download NOOBS from The Raspberry Pi Foundation. Torrent download recommended, and remember to seed. :)

If you're running Raspian, you can do sudo raspi-config, enable SPI under Advanced and then spidev will be enabled. Simple, eh?

Download Libreboot from their releases page. For your safety, verify the GPG signature as well.

x86# gpg --keyserver prefered.keyserver.org --recv-keys 0x656F212E

x86# for signature in $(ls *.sig); do gpg --verify $signature; done

Extract NOOBS and libreboot.

x86# mkdir ~/work/noobs

x86# unzip ~/Downloads/NOOBS_v1_4_1.zip -d ~/work/noobs/

x86# cd ~/work && tar -xvJf ~/Downloads/libreboot_bin.tar.xz

Install Noobs to your fat32 formatted SD card

x86# cp -R ~/work/noobs/* /path/to/mounted/SDcard/

[](#set-up-noobs-on-raspberry-pi){#user-content-set-up-noobs-on-raspberry-pi .anchor}Set up NOOBS on Raspberry Pi

Plug in the NOOBs SDCard to your Raspberry Pi, and enable the following under 'Advanced Options':

SSH server

SPI

I2C

On first boot

pi# sudo apt-get update && sudo apt-get dist-upgrade && reboot

On second boot

pi# sudo apt-get update && sudo apt-get install libftdi1 libftdi-dev libusb-dev libpci-dev subversion

Other dependencies that should already be installed with the noobs base install include:

pciutils, zlib, libusb, build-essential

If they are missing then install them.

Download and build flashrom.

pi# svn co svn://flashrom.org/flashrom/trunk ~/flashrom

pi# cd ~/flashrom

pi# make

pi# sudo make install

On your x86 box change the libreboot.rom mac address

x86# cd ~/work/libreboot_bin/

Change the mac address on the libreboot images to match yours.

x86# ./ich9macchange XX:XX:XX:XX:XX:XX

Move the libreboot.rom image over to your pi

x86# scp ~/work/libreboot_bin/<path_to_your_bin> pi@your.pi.address:~/flashrom/libreboot.rom

Shutdown your pi, write down your rom chip model, and wire up the clip

pi# sudo shutdown now -hP

Chip model name

Pinout. You may want to download the image so you can zoom in on the text.

Pin # SPI Pin Name 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 S0/SIO1 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 S1/SIO0 19 16 SCLK 23

Note: The raspberry pi 3.3V rail should be sufficient to power the chip during flashing, so no external power supply should be required; however, at the time of writing that has only been tested and confirmed for one chip, the MX25L6405D.

Macronix Spec sheet so you can adjust your pinout for 8 pin 4Mb chips as necessary

At this point connect your SOIC clip to the rom chip before powering on your PI.

Power on your Pi, and run the following. Ensure you swap out "your_chip_name" with the proper name/model of your chip. Check that it can be read successfully. If you cannot read the chip and receive an error similar to "no EEPROM Detected" or "0x0 Chip detected" then you may want to try powering off your PI, and switching the two pins which are connected to the IO ports. I.E. Connect pins (clip)8 to (pi)19 and pins (clip)15 to (pi)21

pi# cd ~/flashrom

pi# ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=512 --chip <your_chip_name> -r romread1.rom

pi# ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=512 --chip <your_chip_name> -r romread2.rom

pi# ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=512 --chip <your_chip_name> -r romread3.rom

pi# sha512sum romread*.rom

If they are identical sha512 hashes then you can generally assume that it's safe to flash your rom.

pi# ./flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=512 --chip <your_chip_name> -w libreboot.rom

It may fail a couple times, but keep at it and when you get the message Verifying flash... Verified or Warning: Chip content is identical to the requested image then you're done.

Shut down your pi, put your box back together, and install a libre OS for great good!

[](#raspberry-pi-c720-chromebook){#user-content-raspberry-pi-c720-chromebook .anchor}Raspberry Pi (C720 Chromebook)

The Raspberry Pi (a multipurpose \$25 GNU+Linux computer) can be used as a BIOS flashing tool, thanks to its GPIO pins and SPI support.

[](#what-you-need){#user-content-what-you-need .anchor}What you need

  • \$25 - Raspberry Pi Model B (Rev.2 or higher)
  • \$10-20 - SOIC-8 Pomona Clip
    • Usually comes bundled with nice, color-colored female to female wires

[](#raspberry-pi-pinouts){#user-content-raspberry-pi-pinouts .anchor}Raspberry Pi Pinouts

GPIO Pinouts:

*Diagram made by "Pacman" from Win-Raid Forums*

SOIC Pinouts:

[](#plugging-in-the-soic-clip){#user-content-plugging-in-the-soic-clip .anchor}Plugging in the SOIC Clip

We have to connect the Raspberry Pi to the SOIC Clip as shown in the below diagram (using the f-f wires usually included with the Pomona clip).

SOIC Pinouts for C720 Chromebook

(C720 Only?) The diagram depicts a "bridged" connection. You will need to fashion one with some copper wire:

Bridged wires

Plug in the wires to the clip as shown below:

Pomona Clip connections

Plug in the other end of the wires to the Raspberry Pi as shown below:

Raspberry Pi connections

(C720 only?) Plug in the "bridged" wires as shown below:

Bridged wires connected

Finally, put the Pomona SOIC clip on the chip:

Pomona Clip Connected

[](#flashrom){#user-content-flashrom .anchor}Flashrom

Once it's all set up, flashrom works out of the box.

[](#sources-1){#user-content-sources-1 .anchor}Sources

Copyright © 2014, 2015 Lawrence Wu sagnessagiel@gmail.com\ Copyright © 2015 snuffeluffegus <>\ Copyright © 2015 Kevin Keijzer <>\ Copyright © 2016 Leah Rowe info@minifree.org\ Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 4.0 International license or any later version published by Creative Commons; A copy of the license can be found at ../cc-by-sa-4.0.txt

Updated versions of the license (when available) can be found at https://creativecommons.org/licenses/by-sa/4.0/legalcode

UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.

TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.

The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.