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) { diff --git a/flashrom.c b/flashrom.c index b66ad8929..d438053af 100644 --- a/flashrom.c +++ b/flashrom.c @@ -870,41 +870,6 @@ notfound: return chip - flashchips; } -/** - * @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 - */ -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; -} - /** * @brief Writes content from buffer to one or more files. * diff --git a/include/flash.h b/include/flash.h index d5001c1d5..fe1005a47 100644 --- a/include/flash.h +++ b/include/flash.h @@ -423,7 +423,6 @@ void print_banner(void); 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 flashrom_layout *const layout, 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 flashrom_layout *const layout, unsigned char *buf); int prepare_flash_access(struct flashctx *, bool read_it, bool write_it, bool erase_it, bool verify_it);