mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 15:33:42 +02:00
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>
This commit is contained in:
parent
7a2d7efd83
commit
35547ed3af
21
flashrom.c
21
flashrom.c
@ -2192,13 +2192,28 @@ _free_ret:
|
|||||||
|
|
||||||
int do_read(struct flashctx *const flash, const char *const filename)
|
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;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user