summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2022-01-07 11:25:07 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2022-01-11 22:53:44 +0000
commitf31bb81de166a408b562296dc7f772421ecd4e2d (patch)
treed2fe7647082ffb5dbabaf309d44a755f7b0ac5d2
parent00b8e8552876a9d050c9f73e853a84965452ba40 (diff)
downloadflashrom-f31bb81de166a408b562296dc7f772421ecd4e2d.tar.gz
flashrom-f31bb81de166a408b562296dc7f772421ecd4e2d.tar.bz2
flashrom-f31bb81de166a408b562296dc7f772421ecd4e2d.zip
layout: Hoist get_region_range() into libflashrom API
While using the libflashrom API to read specific regions there is no currently no general way to find the offset into the read buffer of the expected region. flashrom_layout_include_region() probably should have returned the region offset and size if it was included. However to avoid a change in API signature we can instead hoist up get_region_range() into the API to be called after. BUG=b:207808292 TEST=`make` && tested in porting cbfstool use-case. Change-Id: I8cf95b5eaec943a51d0ea668f26a56bf6d6b4446 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/60881 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sam McNally <sammc@google.com>
-rw-r--r--cli_classic.c2
-rw-r--r--layout.c35
-rw-r--r--layout.h2
-rw-r--r--libflashrom.h2
-rw-r--r--libflashrom.map1
-rw-r--r--tests/layout.c2
6 files changed, 28 insertions, 16 deletions
diff --git a/cli_classic.c b/cli_classic.c
index d69b7985f..1b9c5ba3a 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -782,7 +782,7 @@ int main(int argc, char *argv[])
}
if (set_wp_region && wp_region) {
- if (get_region_range(layout, wp_region, &wp_start, &wp_len)) {
+ if (flashrom_layout_get_region_range(layout, wp_region, &wp_start, &wp_len)) {
ret = 1;
goto out_release;
}
diff --git a/layout.c b/layout.c
index 534debaa2..05bee19c5 100644
--- a/layout.c
+++ b/layout.c
@@ -188,18 +188,6 @@ static int find_romentry(struct flashrom_layout *const l, char *name, char *file
return 0;
}
-int get_region_range(struct flashrom_layout *const l, const char *name,
- unsigned int *start, unsigned int *len)
-{
- const struct romentry *const entry = _layout_entry_by_name(l, name);
- if (entry) {
- *start = entry->start;
- *len = entry->end - entry->start + 1;
- return 0;
- }
- return 1;
-}
-
/* process -i arguments
* returns 0 to indicate success, >0 to indicate failure
*/
@@ -445,6 +433,29 @@ int flashrom_layout_include_region(struct flashrom_layout *const layout, const c
}
/**
+ * @brief Get given region's offset and length.
+ *
+ * @param layout The layout to alter.
+ * @param name The name of the region.
+ * @param start The start address to be written.
+ * @param len The length of the region to be written.
+ *
+ * @return 0 on success,
+ * 1 if the given name can't be found.
+ */
+int flashrom_layout_get_region_range(struct flashrom_layout *const l, const char *name,
+ unsigned int *start, unsigned int *len)
+{
+ const struct romentry *const entry = _layout_entry_by_name(l, name);
+ if (entry) {
+ *start = entry->start;
+ *len = entry->end - entry->start + 1;
+ return 0;
+ }
+ return 1;
+}
+
+/**
* @brief Free a layout.
*
* @param layout Layout to free.
diff --git a/layout.h b/layout.h
index 713241f61..abbdc22c1 100644
--- a/layout.h
+++ b/layout.h
@@ -59,8 +59,6 @@ int register_include_arg(struct layout_include_args **, const char *arg);
int process_include_args(struct flashrom_layout *, const struct layout_include_args *);
void cleanup_include_args(struct layout_include_args **);
-int get_region_range(struct flashrom_layout *, const char *name,
- unsigned int *start, unsigned int *len);
const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
const struct romentry *layout_next(const struct flashrom_layout *, const struct romentry *);
diff --git a/libflashrom.h b/libflashrom.h
index 3bd6855d7..557978d4d 100644
--- a/libflashrom.h
+++ b/libflashrom.h
@@ -114,6 +114,8 @@ int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout,
struct flashrom_flashctx *, const uint8_t *buf, size_t len);
int flashrom_layout_add_region(struct flashrom_layout *, size_t start, size_t end, const char *name);
int flashrom_layout_include_region(struct flashrom_layout *, const char *name);
+int flashrom_layout_get_region_range(struct flashrom_layout *, const char *name,
+ unsigned int *start, unsigned int *len);
void flashrom_layout_release(struct flashrom_layout *);
void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *);
diff --git a/libflashrom.map b/libflashrom.map
index feb20f83e..2249d3549 100644
--- a/libflashrom.map
+++ b/libflashrom.map
@@ -14,6 +14,7 @@ LIBFLASHROM_1.0 {
flashrom_image_verify;
flashrom_image_write;
flashrom_init;
+ flashrom_layout_get_region_range;
flashrom_layout_include_region;
flashrom_layout_read_fmap_from_buffer;
flashrom_layout_read_fmap_from_rom;
diff --git a/tests/layout.c b/tests/layout.c
index 59e409bb7..1e7e31d16 100644
--- a/tests/layout.c
+++ b/tests/layout.c
@@ -121,7 +121,7 @@ void layout_pass_sanity_checks_test_success(void **state)
printf("done\n");
printf("Asserting region range... ");
- get_region_range(layout, "region", &start, &len);
+ flashrom_layout_get_region_range(layout, "region", &start, &len);
assert_int_equal(start, region_start);
assert_int_equal(len, region_end - region_start + 1);
printf("done\n");