diff options
author | Sam McNally <sammc@chromium.org> | 2022-10-18 20:31:28 +1100 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-17 09:24:43 +0000 |
commit | 57318f0ff4e47394e767d8752cd04a0eb7a89164 (patch) | |
tree | 224d4fd0cf846441486afcbefd7ac8eabda196a6 | |
parent | 5b6985240bc5e673ec2a744bedda7e22583cea77 (diff) | |
download | vboot-57318f0ff4e47394e767d8752cd04a0eb7a89164.tar.gz |
host/lib: Add flashrom_read_region() to read just the requested region
The region parameter to flashrom_read_image() is essentially unusable in
isolation since it reads just the requested region into a buffer sized
to the entire flash, at the offset of the region within the flash.
Remove its unused region parameter and split the functionality of
requesting a region into flashrom_read_region() which stores just the
requested region into a buffer sized to the region.
BUG=b:253966060
TEST=futility update --detect-model -a <archive> works as expected
BRANCH=None
Signed-off-by: Sam McNally <sammc@chromium.org>
Change-Id: Ibf6c152dd42fbc99c1742fb077bc6aa35feeed08
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3965583
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r-- | futility/updater_utils.c | 2 | ||||
-rw-r--r-- | host/lib/flashrom_drv.c | 29 | ||||
-rw-r--r-- | host/lib/include/flashrom.h | 3 |
3 files changed, 30 insertions, 4 deletions
diff --git a/futility/updater_utils.c b/futility/updater_utils.c index a41c4038..978936fa 100644 --- a/futility/updater_utils.c +++ b/futility/updater_utils.c @@ -672,7 +672,7 @@ static int read_flash(struct flashrom_params *params, if (get_config_quirk(QUIRK_EXTERNAL_FLASHROM, cfg)) return external_flashrom(FLASH_READ, params, &cfg->tempfiles); - return flashrom_read_image(params->image, NULL, params->verbose); + return flashrom_read_image(params->image, params->verbose); } static int write_flash(struct flashrom_params *params, diff --git a/host/lib/flashrom_drv.c b/host/lib/flashrom_drv.c index a9479c29..56eeb8a7 100644 --- a/host/lib/flashrom_drv.c +++ b/host/lib/flashrom_drv.c @@ -46,8 +46,10 @@ static char *flashrom_extract_params(const char *str, char **prog, char **params return tmp; } -int flashrom_read_image(struct firmware_image *image, const char *region, - int verbosity) +static int flashrom_read_image_impl(struct firmware_image *image, + const char *region, + unsigned int *region_start, + unsigned int *region_len, int verbosity) { int r = 0; size_t len = 0; @@ -106,6 +108,10 @@ int flashrom_read_image(struct firmware_image *image, const char *region, r |= flashrom_image_read(flashctx, image->data, len); + if (r == 0 && region) + r |= flashrom_layout_get_region_range(layout, region, + region_start, region_len); + err_cleanup: flashrom_layout_release(layout); flashrom_flash_release(flashctx); @@ -118,6 +124,25 @@ err_init: return r; } +int flashrom_read_image(struct firmware_image *image, int verbosity) +{ + return flashrom_read_image_impl(image, NULL, NULL, NULL, verbosity); +} + +int flashrom_read_region(struct firmware_image *image, const char *region, + int verbosity) +{ + unsigned int start, len; + int r = flashrom_read_image_impl(image, region, &start, &len, + verbosity); + if (r != 0) + return r; + + memmove(image->data, image->data + start, len); + image->size = len; + return 0; +} + int flashrom_write_image(const struct firmware_image *image, const char * const regions[], const struct firmware_image *diff_image, diff --git a/host/lib/include/flashrom.h b/host/lib/include/flashrom.h index e2d3fb38..81d6ba98 100644 --- a/host/lib/include/flashrom.h +++ b/host/lib/include/flashrom.h @@ -40,7 +40,8 @@ struct firmware_image { * @return VB2_SUCCESS on success, or a relevant error. */ vb2_error_t flashrom_read(struct firmware_image *image, const char *region); -int flashrom_read_image(struct firmware_image *image, const char *region, +int flashrom_read_image(struct firmware_image *image, int verbosity); +int flashrom_read_region(struct firmware_image *image, const char *region, int verbosity); /** |