Flashrom: Difference between revisions

From Leo's Notes
This page was last edited on 18 December 2021, at 04:36.
mNo edit summary
No edit summary
Line 1: Line 1:
Flashrom is a utility to read flash.
Flashrom is a utility to read flash.


== Cheat sheet ==
==Cheat sheet==
{| class="wikitable"
{| class="wikitable"
!Task
!Task
Line 16: Line 16:
|}
|}


== Using flashrom with a Raspberry Pi ==
==Using flashrom with a Raspberry Pi==
[[File:Raspberry Pi GPIO Header.png|alt=Raspberry Pi GPIO Header|thumb|731x731px|Raspberry Pi GPIO Header]]
 
=== Pinouts ===
[[File:Raspberry Pi GPIO Header.png|alt=Raspberry Pi GPIO Header|thumb|513x513px|Raspberry Pi GPIO Header]]Refer to the table below and the diagram on the right for the pinouts to your Raspberry Pi and the SPI rom device.
{| class="wikitable"
{| class="wikitable"
!RPi header!!SPI flash!!MX25L Pin
!RPi header!!SPI Function!![https://www.mxic.com.tw/Lists/Datasheet/Attachments/7397/MX25L12835F,%203V,%20128Mb,%20v1.6.pdf MX25L] 16-Pin SOP
!HM25Q 8-Pin SOP
|-
|-
|25||GND||10
|25||GND||10
|4
|-
|-
|24||CS||7
|24||CS||7
|1
|-
|-
|23||SCK (CLK)||16
|23||SCK (CLK)||16
|6
|-
|-
|21||DO (MISO)||8
|21||DO (MISO)||8
|2
|-
|-
|19||DI (MOSI)||15
|19||DI (MOSI)||15
|5
|-
|-
|17||VCC 3.3v||2
|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:
|8
 
|-
The WriteProtect (WP#, pin 9) should be connected to GND according to the datasheet. Leaving it floating still seems to work.
|
|WP#
|9
|3
|-
|
|HOLD# / RESET#
|3
|7
|}The MX25L - 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 {{code|/boot/config.txt}}:{{highlight|lang=text|code=
The Raspberry Pi should have SPI enabled by adding this line to {{code|/boot/config.txt}}:{{highlight|lang=text|code=

Revision as of 04:36, 18 December 2021

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

Pinouts

Raspberry Pi GPIO Header
Raspberry Pi GPIO Header

Refer to the table below and the diagram on the right for the pinouts to your Raspberry Pi and the SPI rom device.

RPi header SPI Function MX25L 16-Pin SOP HM25Q 8-Pin SOP
25 GND 10 4
24 CS 7 1
23 SCK (CLK) 16 6
21 DO (MISO) 8 2
19 DI (MOSI) 15 5
17 VCC 3.3v 2 8
WP# 9 3
HOLD# / RESET# 3 7

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


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.