Edward O'Callaghan has uploaded this change for review.

View Change

flashrom: Convert do_read() into a libflashrom user

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 the do_read() provider wrapper into a pure
libflashrom user.

BUG=b:208132085
TEST=`$ sudo ./flashrom -p internal -r /tmp/bios.bin`

Change-Id: Id2addadb891c482ee3f69da806062d7a88776675
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M flashrom.c
1 file changed, 17 insertions(+), 3 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/30/60430/1
diff --git a/flashrom.c b/flashrom.c
index 48d953b..445db30 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -2193,13 +2193,27 @@

int do_read(struct flashctx *const flash, const char *const filename)
{
- if (prepare_flash_access(flash, true, false, false, false))
+ int ret;
+
+ unsigned long size = flash->chip->total_size * 1024;
+ unsigned char *buf = calloc(size, sizeof(unsigned char));
+ if (!buf) {
+ msg_gerr("Memory allocation failed!\n");
return 1;
+ }

- const int ret = read_flash_to_file(flash, filename);
+ ret = flashrom_image_read(flash, buf, size);
+ if (ret > 0)
+ goto free_out;

- finalize_flash_access(flash);
+ if (write_buf_to_include_args(flash, buf)) {
+ ret = 1;
+ goto free_out;
+ }
+ ret = write_buf_to_file(buf, size, filename);

+free_out:
+ free(buf);
return ret;
}


To view, visit change 60430. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id2addadb891c482ee3f69da806062d7a88776675
Gerrit-Change-Number: 60430
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange