Flashrom

From Leo's Notes
Revision as of 04:23, 18 December 2021 by Leo (talk | contribs) (Initial Content)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 18 December 2021, at 04:23.

Flashrom is a utility to read flash.

Cheat sheet

Task Command
Dump a ROM connected via SPI flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=32768 -r dump.bin
Dump a ROM via SPI using a specific chip definition flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=600 -c "MX25L12835F/MX25L12845E/MX25L12865E" -w dump.bin
Write a ROM via SPI flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=32768 -w new-data-to-rom.bin

Using flashrom with a Raspberry Pi

Raspberry Pi GPIO Header
Raspberry Pi GPIO Header
RPi header SPI flash MX25L Pin
25 GND 10
24 CS 7
23 SCK (CLK) 16
21 DO (MISO) 8
19 DI (MOSI) 15
17 VCC 3.3v 2

To read the chip using a Raspberry Pi and flashrom, we can use 1x serial IO by connecting the pins according to this table:

The WriteProtect (WP#, pin 9) should be connected to GND according to the datasheet. Leaving it floating still seems to work.

Refer to the Raspberry Pi pinout at https://i.stack.imgur.com/eLPtx.png.

The Raspberry Pi should have SPI enabled by adding this line to /boot/config.txt:

device_tree_param=spi=on

The /dev/spidev0.0 device should exist and flashrom should be able to detect the flash chip.

[root@alarmpi alarm]# flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=1000
flashrom v1.0 on Linux 4.14.92-1-ARCH (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 Macronix flash chip "MX25L12805D" (16384 kB, SPI) on linux_spi.
Found Macronix flash chip "MX25L12835F/MX25L12845E/MX25L12865E" (16384 kB, SPI) on linux_spi.
Multiple flash chip definitions match the detected chip(s): "MX25L12805D", "MX25L12835F/MX25L12845E/MX25L12865E"
Please specify which chip definition to use with the -c <chipname> option.

Dump the data using -r filename.

[root@alarmpi alarm]# flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=300 -c "MX25L12835F/MX25L12845E/MX25L12865E" -r dump7.dat
flashrom v1.0 on Linux 4.14.92-1-ARCH (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 Macronix flash chip "MX25L12835F/MX25L12845E/MX25L12865E" (16384 kB, SPI) on linux_spi.
Reading flash... done.