SPI flash¶
Experimental
Tested against a fake flashrom only so far; the API may change in minor releases.
See the SPI flash guide for an introduction.
spiflash
¶
Wrappers around the flashrom CLI for reading and (carefully) writing SPI flash.
Example
from hwntools import Flashrom
fr = Flashrom("ch341a_spi")
print(fr.detect()) # ['W25Q128.V']
image = fr.read("dump.bin") # reads twice and compares
FlashChip
dataclass
¶
A chip reported by flashrom. size is in bytes.
Flashrom
¶
Flashrom(programmer: str = 'ch341a_spi', chip: str | None = None, flashrom: str = 'flashrom', extra_args: Sequence[str] = (), timeout: float = 1800.0)
Run flashrom with a fixed programmer (ch341a_spi, linux_spi:dev=..., ...).
Writing and erasing require force=True; reads are verified by reading twice.
detect
¶
detect() -> list[FlashChip]
Probe the programmer and return the detected chip(s).
When several chip definitions match (common for clones), set chip= to one of
the returned names.
read
¶
Read the whole chip. With verify it is read twice and both reads must match.
On a mismatch (loose clip, marginal wiring) up to tries pairs are attempted.
write
¶
Program image to the chip. Destructive: requires force=True.
Make (and verify) a backup with read first.