summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorSam McNally <sammc@chromium.org>2022-10-18 20:31:28 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-17 09:24:43 +0000
commit57318f0ff4e47394e767d8752cd04a0eb7a89164 (patch)
tree224d4fd0cf846441486afcbefd7ac8eabda196a6 /host
parent5b6985240bc5e673ec2a744bedda7e22583cea77 (diff)
downloadvboot-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>
Diffstat (limited to 'host')
-rw-r--r--host/lib/flashrom_drv.c29
-rw-r--r--host/lib/include/flashrom.h3
2 files changed, 29 insertions, 3 deletions
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);
/**