diff options
author | Edward O'Callaghan <quasisec@google.com> | 2021-10-28 12:45:38 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-25 02:02:01 +0000 |
commit | 0cd8ad2c330ee40beb54c2ce3def4ba6ea84fa3c (patch) | |
tree | 5bc807f2ed020e2bac8f2ce997618d419c82ca75 | |
parent | 91ffb514310bbc1fff166a049d9a40d11850f314 (diff) | |
download | vboot-0cd8ad2c330ee40beb54c2ce3def4ba6ea84fa3c.tar.gz |
vboot_reference/futility: Port R path to using libflashrom
Use libflashrom API over sub-processing the flashrom CLI.
Squash in,
Use buffer instead of temp file in load_system_firmware().
BUG=b:203715651
BRANCH=none
TEST=cros deploy to nocturne and ran:
`/usr/sbin/chromeos-firmwareupdate --mode=recovery --wp=1`.
&& `$ cros_run_unit_tests --board nocturne --packages vboot_reference`.
Cq-Depend: chromium:3295109
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Change-Id: Ib78f7aa6606adb8d5ce72282c55b8e3b9e3b3cde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3247853
Tested-by: Edward O'Callaghan <quasisec@chromium.org>
Auto-Submit: Edward O'Callaghan <quasisec@chromium.org>
Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
-rw-r--r-- | futility/updater_utils.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c index 3c7b3730..dec0dab9 100644 --- a/futility/updater_utils.c +++ b/futility/updater_utils.c @@ -27,7 +27,6 @@ #define FLASHROM_OUTPUT_WP_PATTERN "write protect is " enum flashrom_ops { - FLASHROM_READ, FLASHROM_WP_STATUS, }; @@ -562,11 +561,6 @@ static int host_flashrom(enum flashrom_ops op, const char *image_path, } switch (op) { - case FLASHROM_READ: - op_cmd = "-r"; - assert(image_path); - break; - case FLASHROM_WP_STATUS: op_cmd = "--wp-status"; assert(image_path == NULL); @@ -652,6 +646,37 @@ static char *flashrom_extract_params(const char *str, char **prog, char **params return tmp; } +static int host_flashrom_read(struct firmware_image *image) +{ + int r = 0; + size_t len = 0; + + char *programmer, *params; + char *tmp = flashrom_extract_params(image->programmer, &programmer, ¶ms); + + struct flashrom_programmer *prog = NULL; + struct flashrom_flashctx *flashctx = NULL; + + flashrom_set_log_callback((flashrom_log_callback *)&flashrom_print_cb); + + r |= flashrom_init(1); + r |= flashrom_programmer_init(&prog, programmer, params); + r |= flashrom_flash_probe(&flashctx, prog, NULL); + + len = flashrom_flash_getsize(flashctx); + image->data = calloc(1, len); + image->size = len; + image->file_name = strdup("<none>"); + + r |= flashrom_image_read(flashctx, image->data, len); + + r |= flashrom_programmer_shutdown(prog); + flashrom_flash_release(flashctx); + free(tmp); + + return r; +} + static int host_flashrom_write(const struct firmware_image *image, const char *region, const struct firmware_image *diff_image) @@ -750,26 +775,10 @@ int load_system_firmware(struct firmware_image *image, struct tempfile *tempfiles, int verbosity) { int r; - const char *tmp_path = create_temp_file(tempfiles); - - if (!tmp_path) - return -1; - r = host_flashrom(FLASHROM_READ, tmp_path, image->programmer, - verbosity, NULL, NULL); - /* - * The verbosity for host_flashrom will be translated to - * (verbosity-1)*'-V', and usually 3*'-V' is enough for debugging. - */ - const int debug_verbosity = 4; - if (r && verbosity < debug_verbosity) { - /* Read again, with verbose messages for debugging. */ - WARN("Failed reading system firmware (%d), try again...\n", r); - r = host_flashrom(FLASHROM_READ, tmp_path, image->programmer, - debug_verbosity, NULL, NULL); - } + r = host_flashrom_read(image); if (!r) - r = load_firmware_image(image, tmp_path, NULL); + r = parse_firmware_image(image); return r; } |