1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

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 <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/66647
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Evan Benn <evanbenn@google.com>
Reviewed-by: Sam McNally <sammc@google.com>
Reviewed-by: Thomas Heijligen <src@posteo.de>
This commit is contained in:
Edward O'Callaghan 2022-08-12 11:07:16 +10:00 committed by Edward O'Callaghan
parent c9ebfad95f
commit b2b154802b
3 changed files with 34 additions and 36 deletions

View File

@ -357,6 +357,40 @@ static int wp_cli(
return 0; 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 <region>[:<filename>]')
* 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) static int do_read(struct flashctx *const flash, const char *const filename)
{ {

View File

@ -870,41 +870,6 @@ notfound:
return chip - flashchips; 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 <region>[:<filename>]')
* 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. * @brief Writes content from buffer to one or more files.
* *

View File

@ -423,7 +423,6 @@ void print_banner(void);
void list_programmers_linebreak(int startcol, int cols, int paren); void list_programmers_linebreak(int startcol, int cols, int paren);
int selfcheck(void); int selfcheck(void);
int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); 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_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 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); int prepare_flash_access(struct flashctx *, bool read_it, bool write_it, bool erase_it, bool verify_it);