How to use the command flashrom (with examples)

How to use the command flashrom (with examples)

The flashrom command is a versatile tool used to read, write, verify, and erase flash chips. It is commonly employed for tasks such as updating firmware, recovering bricked devices, or creating backups of important data stored in flash memory. In this article, we will explore several use cases of the flashrom command, along with their corresponding examples.

Use case 1: Probe the chip, ensuring the wiring is correct

Code:

flashrom --programmer programmer

Motivation: This use case is useful when you want to ensure that the wiring to the flash chip is correct before performing any further actions. It allows you to mitigate any potential risks caused by incorrect connections.

Explanation: The --programmer flag specifies the programmer to be used for accessing the flash chip. By providing the name of the programmer as an argument (e.g., programmer), flashrom will probe the chip and verify the correct wiring.

Example output:

Found chip "SST25VF064C" (8192 kB, SPI) on programmer.

Use case 2: Read flash and save it to a file

Code:

flashrom -p programmer --read path/to/file

Motivation: This use case allows you to create a backup of the contents stored in the flash chip. It can serve as a safety net in case of data corruption or when you need to revert to the original state of the flash memory.

Explanation: The -p flag, followed by the programmer name (programmer), specifies the programmer to use. The --read flag indicates that we want to read the flash memory. Finally, the path/to/file argument specifies the location and name of the file where the read data will be saved.

Example output:

Reading flash... done.

Use case 3: Write a file to the flash

Code:

flashrom -p programmer --write path/to/file

Motivation: This use case allows you to write specific data to the flash chip. It is commonly used for firmware updates or modifying the contents of the flash memory.

Explanation: Similar to the previous use case, the -p flag and programmer argument are used to specify the programmer. The --write flag indicates that we want to write to the flash memory. The path/to/file argument points to the file that contains the data to be written.

Example output:

Writing flash... done.

Use case 4: Verify the flash against a file

Code:

flashrom -p programmer --verify path/to/file

Motivation: This use case allows you to verify that the flash memory matches the content of a specific file. By comparing the data, you can ensure that the writing process was successful and that the flash memory is accurate.

Explanation: The -p flag and programmer argument are used to specify the programmer, just like in the previous use cases. The --verify flag indicates that we want to verify the flash memory against the data provided in the specified file (path/to/file).

Example output:

Verifying flash... VERIFIED.

Use case 5: Probe the chip using Raspberry Pi

Code:

flashrom -p linux_spi:dev=/dev/spidev0.0

Motivation: This use case is useful when working with a Raspberry Pi to probe flash chips. It allows you to leverage the SPI interface available on the Raspberry Pi to interact with flash memory.

Explanation: The -p flag specifies the programmer to use, and the argument linux_spi:dev=/dev/spidev0.0 indicates the usage of the SPI interface (linux_spi) located at /dev/spidev0.0. This configuration allows flashrom to communicate with the flash chip connected to the specified SPI bus on the Raspberry Pi.

Example output:

Found chip "MX25L6405D/MX25L6406E/MX25L6408E" (8192 kB, SPI) on linux_spi.

Conclusion:

The flashrom command is a powerful tool that facilitates the reading, writing, verification, and erasure of flash chips. Through various use cases, we have explored how to probe chips, read and write flash memory, verify data integrity, and utilize a Raspberry Pi for chip probing. With this knowledge, you can confidently employ flashrom to carry out a wide range of tasks involving flash memory manipulation.

Related Posts

How to use the command jadx (with examples)

How to use the command jadx (with examples)

The jadx command is a Dex to Java decompiler that is used to produce Java source code from Android Dex and APK files.

Read More
How to use the command 'dvc fetch' (with examples)

How to use the command 'dvc fetch' (with examples)

DVC fetch is a command that allows users to download DVC tracked files and directories from a remote repository.

Read More
How to use the command 'reg compare' (with examples)

How to use the command 'reg compare' (with examples)

The ‘reg compare’ command in Windows is used to compare keys and their values in the Windows registry.

Read More