Attention is currently required from: Simon Buhrow, Nico Huber. Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/58467 )
Change subject: flashchips.c: big erase blocksize first ......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
Just a starting point for discussion. […]
Have you tried with random data? You can create a file with random data like this:
dd if=/dev/urandom of=random_data_1.bin count=1 bs=8MiB
Replace `8MiB` with the size of your flash chip. Then, make a copy of the file (I use `random_data_2.bin` in the commands) and change the first 16 bytes with this:
dd if=/dev/urandom of=random_data_2.bin count=1 bs=16 conv=notrunc
Then, flash the first file and measure how long flashing the second file takes, without erasing anything manually:
sudo flashrom -p ft2232_spi:type=2232H,port=A -w random_data_1.bin -VV
time sudo flashrom -p ft2232_spi:type=2232H,port=A -w random_data_2.bin -VV
I expect the measured time to increase dramatically with this change. This is because flashrom is smart and only rewrites the parts of the chip which have changed. With a larger erase block size, the part of the flash chip that needs to be rewritten is much larger.
Instead, it would be much better to have flashrom automatically choose the optimal erase block size. I think something like this would be a good start:
1. Using the smallest erase block size as unit, determine which blocks need to be erased. 2. Try to use larger erase block sizes: check if multiple successive small blocks that need to be erased can instead be erased at once with a larger block eraser. 3. Proceed with erasing and rewriting with the obtained results.
IIRC, flashrom currently erases and writes one block at a time. Even though erasing all the blocks first would be easier to implement, it would be significantly more dangerous in case something goes wrong. This is especially important when flashing internally (i.e. firmware updates) because errors can result in a non-booting computer.