Edward O'Callaghan has submitted this change. ( https://review.coreboot.org/c/flashrom/+/60430 )
Change subject: flashrom: Convert do_read() into a libflashrom user ......................................................................
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` TEST=`$ sudo ./flashrom -p internal -l /tmp/layout -i FOO -r /tmp/foo.bin`
Change-Id: Id2addadb891c482ee3f69da806062d7a88776675 Signed-off-by: Edward O'Callaghan quasisec@google.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/60430 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Anastasia Klimchuk aklm@chromium.org --- M flashrom.c 1 file changed, 18 insertions(+), 3 deletions(-)
Approvals: build bot (Jenkins): Verified Anastasia Klimchuk: Looks good to me, approved
diff --git a/flashrom.c b/flashrom.c index 1cdddab..257112f 100644 --- a/flashrom.c +++ b/flashrom.c @@ -2192,13 +2192,28 @@
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; + } + if (filename) + ret = write_buf_to_file(buf, size, filename);
+free_out: + free(buf); return ret; }
4 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.