From b2b154802ba50fc218b54a40c9498476f368b950 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Fri, 12 Aug 2022 11:07:16 +1000 Subject: flashrom.c: Move read_buf_from_include_args() into cli_classic.c The read_buf_from_include_args() helper is only ever used by the cli frontend therefore make it static local to the user. BUG=b:242246291 TEST=builds Change-Id: I9dee63d67320085e16c64eefb2723169f49f07aa Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/66647 Tested-by: build bot (Jenkins) Reviewed-by: Evan Benn Reviewed-by: Sam McNally Reviewed-by: Thomas Heijligen --- cli_classic.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cli_classic.c') diff --git a/cli_classic.c b/cli_classic.c index 81299210d..267f3c611 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -357,6 +357,40 @@ static int wp_cli( return 0; } +/** + * @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 [:]') + * then this will read file data into the corresponding region in the + * supplied buffer. + * + * @param layout The layout to be used. + * @param buf Chip-sized buffer to write data to + * @return 0 on success + */ +static int read_buf_from_include_args(const struct flashrom_layout *const layout, unsigned char *buf) +{ + 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; +} static int do_read(struct flashctx *const flash, const char *const filename) { -- cgit v1.2.3