Edward O'Callaghan has uploaded this change for review.
flashrom.c: Move {read,write}_buf_from_include_args() to layout
It makes more sense for these to be apart of layout.c.
BUG=b:208132085
TEST=`make`
Change-Id: I61d4460ea26e07b67c99baeae5cb3840c25cb913
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Spotted-by: Anastasia Klimchuk <aklm@chromium.org>
---
M flash.h
M flashrom.c
M layout.c
M layout.h
4 files changed, 69 insertions(+), 68 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/86/61286/1
diff --git a/flash.h b/flash.h
index e464dd4..391a2d4 100644
--- a/flash.h
+++ b/flash.h
@@ -350,9 +350,7 @@
void list_programmers_linebreak(int startcol, int cols, int paren);
int selfcheck(void);
int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
-int read_buf_from_include_args(const struct flashctx *const flash, unsigned char *buf);
int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename);
-int write_buf_to_include_args(const struct flashctx *const flash, unsigned char *buf);
int prepare_flash_access(struct flashctx *, bool read_it, bool write_it, bool erase_it, bool verify_it);
void finalize_flash_access(struct flashctx *);
int do_read(struct flashctx *, const char *filename);
diff --git a/flashrom.c b/flashrom.c
index c7adba8..ffe738b 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -920,43 +920,6 @@
}
/**
- * @brief Reads content to buffer from one or more files.
- *
- * Reads content to supplied buffer from files. If a filename is specified for
- * individual regions using the partial read syntax ('-i <region>[:<filename>]')
- * then this will read file data into the corresponding region in the
- * supplied buffer.
- *
- * @param flashctx Flash context to be used.
- * @param buf Chip-sized buffer to write data to
- * @return 0 on success
- */
-int read_buf_from_include_args(const struct flashctx *const flash,
- unsigned char *buf)
-{
- const struct flashrom_layout *const layout = get_layout(flash);
- const struct romentry *entry = NULL;
-
- /*
- * Content will be read from -i args, so they must not overlap since
- * we need to know exactly what content to write to the ROM.
- */
- if (included_regions_overlap(layout)) {
- msg_gerr("Error: Included regions must not overlap when writing.\n");
- return 1;
- }
-
- while ((entry = layout_next_included(layout, entry))) {
- if (!entry->file)
- continue;
- if (read_buf_from_file(buf + entry->start,
- entry->end - entry->start + 1, entry->file))
- return 1;
- }
- return 0;
-}
-
-/**
* @brief Writes passed data buffer into a file
*
* @param buf Buffer with data to write
@@ -1017,35 +980,6 @@
}
/**
- * @brief Writes content from buffer to one or more files.
- *
- * Writes content from supplied buffer to files. If a filename is specified for
- * individual regions using the partial read syntax ('-i <region>[:<filename>]')
- * then this will write files using data from the corresponding region in the
- * supplied buffer.
- *
- * @param flashctx Flash context to be used.
- * @param buf Chip-sized buffer to read data from
- * @return 0 on success
- */
-int write_buf_to_include_args(const struct flashctx *const flash,
- unsigned char *buf)
-{
- const struct flashrom_layout *const layout = get_layout(flash);
- const struct romentry *entry = NULL;
-
- while ((entry = layout_next_included(layout, entry))) {
- if (!entry->file)
- continue;
- if (write_buf_to_file(buf + entry->start,
- entry->end - entry->start + 1, entry->file))
- return 1;
- }
-
- return 0;
-}
-
-/**
* @brief Reads the included layout regions into a buffer.
*
* If there is no layout set in the given flash context, the whole chip will
diff --git a/layout.c b/layout.c
index 05bee19..d33ac21 100644
--- a/layout.c
+++ b/layout.c
@@ -299,6 +299,72 @@
return ret;
}
+/**
+ * @brief Reads content to buffer from one or more files.
+ *
+ * Reads content to supplied buffer from files. If a filename is specified for
+ * individual regions using the partial read syntax ('-i <region>[:<filename>]')
+ * then this will read file data into the corresponding region in the
+ * supplied buffer.
+ *
+ * @param flashctx Flash context to be used.
+ * @param buf Chip-sized buffer to write data to
+ * @return 0 on success
+ */
+int read_buf_from_include_args(const struct flashrom_flashctx *const flash,
+ unsigned char *buf)
+{
+ const struct flashrom_layout *const layout = get_layout(flash);
+ const struct romentry *entry = NULL;
+
+ /*
+ * Content will be read from -i args, so they must not overlap since
+ * we need to know exactly what content to write to the ROM.
+ */
+ if (included_regions_overlap(layout)) {
+ msg_gerr("Error: Included regions must not overlap when writing.\n");
+ return 1;
+ }
+
+ while ((entry = layout_next_included(layout, entry))) {
+ if (!entry->file)
+ continue;
+ if (read_buf_from_file(buf + entry->start,
+ entry->end - entry->start + 1, entry->file))
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * @brief Writes content from buffer to one or more files.
+ *
+ * Writes content from supplied buffer to files. If a filename is specified for
+ * individual regions using the partial read syntax ('-i <region>[:<filename>]')
+ * then this will write files using data from the corresponding region in the
+ * supplied buffer.
+ *
+ * @param flashctx Flash context to be used.
+ * @param buf Chip-sized buffer to read data from
+ * @return 0 on success
+ */
+int write_buf_to_include_args(const struct flashrom_flashctx *const flash,
+ unsigned char *buf)
+{
+ const struct flashrom_layout *const layout = get_layout(flash);
+ const struct romentry *entry = NULL;
+
+ while ((entry = layout_next_included(layout, entry))) {
+ if (!entry->file)
+ continue;
+ if (write_buf_to_file(buf + entry->start,
+ entry->end - entry->start + 1, entry->file))
+ return 1;
+ }
+
+ return 0;
+}
+
void prepare_layout_for_extraction(struct flashctx *flash)
{
const struct flashrom_layout *const l = get_layout(flash);
diff --git a/layout.h b/layout.h
index abbdc22..5e41b89 100644
--- a/layout.h
+++ b/layout.h
@@ -59,6 +59,9 @@
int process_include_args(struct flashrom_layout *, const struct layout_include_args *);
void cleanup_include_args(struct layout_include_args **);
+int read_buf_from_include_args(const struct flashrom_flashctx *const flash, unsigned char *buf);
+int write_buf_to_include_args(const struct flashrom_flashctx *const flash, unsigned char *buf);
+
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 *);
To view, visit change 61286. To unsubscribe, or for help writing mail filters, visit settings.