1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

flashrom: Drop read_flash_to_file() usage

Aspire towards a goal of making cli_classic more of just
a user of libflashrom than having quasi-parallel paths in
flashrom.c

This converts remaining read_flash_to_file() usage to the
do_read() provider wrapper around libflashrom.

BUG=b:208132085
TEST=`
sudo ./flashrom -p ft2232_spi:type=232H,divisor=1000 -f -r out -c W25X05
Flashrom output:

No EEPROM/flash device found.
Force read (-f -r -c) requested, pretending the chip is there:
Assuming Winbond flash chip "W25X05" (64 kB, SPI) on ft2232_spi.
Please note that forced reads most likely contain garbage.
Block protection could not be disabled!
Reading flash... done.
Data read:

xxd out-1khz
00000000: 0000 07ff ffff e000 0000 7fff fffe 0000  ................
00000010: 0007 ffff ffe0 0000 007f ffff fe00 0000  ................
00000020: 07ff ffff e000 0000 7fff fffe 0000 0007  ................
00000030: ffff ffe0 0000 007f ffff fe00 0000 0fff  ................
xxd out-100khz
00000000: b6db 6db6 db6d b6db 6db6 db6d b6db 6db6  ..m..m..m..m..m.
00000010: db6d b6db 6db6 db6d b6db 6db6 db6d b6db  .m..m..m..m..m..
00000020: 6db6 db6d b6db 6db6 db24 9249 2492 4924  m..m..m..$.I$.I$
00000030: 9249 2492 4924 9249 2492 4924 9249 2492  .I$.I$.I$.I$.I$.
`

Change-Id: I4b690b688acf9d5deb46e8642a252a2132ea8c73
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Tested-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/59291
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Edward O'Callaghan 2021-11-15 15:47:15 +11:00 committed by Edward O'Callaghan
parent f3d09b5997
commit 086f0c8e4f
4 changed files with 3 additions and 44 deletions

View File

@ -916,14 +916,9 @@ int main(int argc, char *argv[])
ret = 1;
goto out_shutdown;
}
if (map_flash(&flashes[0]) != 0) {
free(flashes[0].chip);
ret = 1;
goto out_shutdown;
}
msg_cinfo("Please note that forced reads most likely contain garbage.\n");
ret = read_flash_to_file(&flashes[0], filename);
unmap_flash(&flashes[0]);
flashrom_flag_set(&flashes[0], FLASHROM_FLAG_FORCE, !!force);
ret = do_read(&flashes[0], filename);
free(flashes[0].chip);
goto out_shutdown;
}

View File

@ -1265,7 +1265,7 @@ int probe_variable_size(struct flashctx *flash)
* Once that happens, we need to have special hacks in functions:
*
* erase_and_write_flash() in flashrom.c
* read_flash_to_file()
* do_read()
* handle_romentries()
* ...
*

View File

@ -1070,41 +1070,6 @@ static int read_by_layout(struct flashctx *const flashctx, uint8_t *const buffer
return 0;
}
int read_flash_to_file(struct flashctx *flash, const char *filename)
{
unsigned long size = flash->chip->total_size * 1024;
unsigned char *buf = calloc(size, sizeof(unsigned char));
int ret = 0;
msg_cinfo("Reading flash... ");
if (!buf) {
msg_gerr("Memory allocation failed!\n");
msg_cinfo("FAILED.\n");
return 1;
}
if (!flash->chip->read) {
msg_cerr("No read function available for this flash chip.\n");
ret = 1;
goto out_free;
}
if (read_by_layout(flash, buf)) {
msg_cerr("Read operation failed!\n");
ret = 1;
goto out_free;
}
if (write_buf_to_include_args(flash, buf)) {
ret = 1;
goto out_free;
}
if (filename)
ret = write_buf_to_file(buf, size, filename);
out_free:
free(buf);
msg_cinfo("%s.\n", ret ? "FAILED" : "done");
return ret;
}
/* Even if an error is found, the function will keep going and check the rest. */
static int selfcheck_eraseblocks(const struct flashchip *chip)
{

View File

@ -410,7 +410,6 @@ void unmap_flash(struct flashctx *flash);
int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int erase_flash(struct flashctx *flash);
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
int read_flash_to_file(struct flashctx *flash, const char *filename);
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran, const uint8_t erased_value);
void emergency_help_message(void);