mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
cli_classic.c: add -x option for do_extract()
This change introduces a new option to extract all layout regions to files with the name of each region (or with the provided filename via -i region:file). It is implemented by mutating the flash layout to include all regions and backfilling the entry->file with entry->name (replacing spaces with underscores) Signed-off-by: Daniel Campello <campello@chromium.org> Change-Id: I8c69223fa92cf5b50abe070f1ab9f19d3b42f6ff Reviewed-on: https://review.coreboot.org/c/flashrom/+/52450 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
0969e43b3f
commit
ce983bccaa
@ -40,7 +40,7 @@ static void cli_classic_usage(const char *name)
|
|||||||
#endif
|
#endif
|
||||||
"\n\t-p <programmername>[:<parameters>] [-c <chipname>]\n"
|
"\n\t-p <programmername>[:<parameters>] [-c <chipname>]\n"
|
||||||
"\t\t(--flash-name|--flash-size|\n"
|
"\t\t(--flash-name|--flash-size|\n"
|
||||||
"\t\t [-E|(-r|-w|-v) <file>]\n"
|
"\t\t [-E|-x|(-r|-w|-v) <file>]\n"
|
||||||
"\t\t [(-l <layoutfile>|--ifd| --fmap|--fmap-file <file>) [-i <region>[:<file>]]...]\n"
|
"\t\t [(-l <layoutfile>|--ifd| --fmap|--fmap-file <file>) [-i <region>[:<file>]]...]\n"
|
||||||
"\t\t [-n] [-N] [-f])]\n"
|
"\t\t [-n] [-N] [-f])]\n"
|
||||||
"\t[-V[V[V]]] [-o <logfile>]\n\n", name);
|
"\t[-V[V[V]]] [-o <logfile>]\n\n", name);
|
||||||
@ -58,6 +58,7 @@ static void cli_classic_usage(const char *name)
|
|||||||
" -f | --force force specific operations (see man page)\n"
|
" -f | --force force specific operations (see man page)\n"
|
||||||
" -n | --noverify don't auto-verify\n"
|
" -n | --noverify don't auto-verify\n"
|
||||||
" -N | --noverify-all verify included regions only (cf. -i)\n"
|
" -N | --noverify-all verify included regions only (cf. -i)\n"
|
||||||
|
" -x | --extract extract regions to files\n"
|
||||||
" -l | --layout <layoutfile> read ROM layout from <layoutfile>\n"
|
" -l | --layout <layoutfile> read ROM layout from <layoutfile>\n"
|
||||||
" --wp-disable disable write protection\n"
|
" --wp-disable disable write protection\n"
|
||||||
" --wp-enable enable write protection\n"
|
" --wp-enable enable write protection\n"
|
||||||
@ -167,7 +168,7 @@ int main(int argc, char *argv[])
|
|||||||
int flash_name = 0, flash_size = 0;
|
int flash_name = 0, flash_size = 0;
|
||||||
int set_wp_enable = 0, set_wp_disable = 0, wp_status = 0;
|
int set_wp_enable = 0, set_wp_disable = 0, wp_status = 0;
|
||||||
int set_wp_range = 0, set_wp_region = 0, wp_list = 0;
|
int set_wp_range = 0, set_wp_region = 0, wp_list = 0;
|
||||||
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
|
int read_it = 0, extract_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
|
||||||
int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
|
int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
|
||||||
struct flashrom_layout *layout = NULL;
|
struct flashrom_layout *layout = NULL;
|
||||||
enum programmer prog = PROGRAMMER_INVALID;
|
enum programmer prog = PROGRAMMER_INVALID;
|
||||||
@ -188,7 +189,7 @@ int main(int argc, char *argv[])
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned int wp_start = 0, wp_len = 0;
|
unsigned int wp_start = 0, wp_len = 0;
|
||||||
|
|
||||||
static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:";
|
static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:x";
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
{"read", 1, NULL, 'r'},
|
{"read", 1, NULL, 'r'},
|
||||||
{"write", 1, NULL, 'w'},
|
{"write", 1, NULL, 'w'},
|
||||||
@ -196,6 +197,7 @@ int main(int argc, char *argv[])
|
|||||||
{"verify", 1, NULL, 'v'},
|
{"verify", 1, NULL, 'v'},
|
||||||
{"noverify", 0, NULL, 'n'},
|
{"noverify", 0, NULL, 'n'},
|
||||||
{"noverify-all", 0, NULL, 'N'},
|
{"noverify-all", 0, NULL, 'N'},
|
||||||
|
{"extract", 0, NULL, 'x'},
|
||||||
{"chip", 1, NULL, 'c'},
|
{"chip", 1, NULL, 'c'},
|
||||||
{"verbose", 0, NULL, 'V'},
|
{"verbose", 0, NULL, 'V'},
|
||||||
{"force", 0, NULL, 'f'},
|
{"force", 0, NULL, 'f'},
|
||||||
@ -287,6 +289,10 @@ int main(int argc, char *argv[])
|
|||||||
case 'N':
|
case 'N':
|
||||||
dont_verify_all = 1;
|
dont_verify_all = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
cli_classic_validate_singleop(&operation_specified);
|
||||||
|
extract_it = 1;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
chip_to_probe = strdup(optarg);
|
chip_to_probe = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
@ -658,7 +664,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!(read_it | write_it | verify_it | erase_it | flash_name | flash_size
|
if (!(read_it | write_it | verify_it | erase_it | flash_name | flash_size
|
||||||
| set_wp_range | set_wp_region | set_wp_enable |
|
| set_wp_range | set_wp_region | set_wp_enable |
|
||||||
set_wp_disable | wp_status | wp_list)) {
|
set_wp_disable | wp_status | wp_list | extract_it)) {
|
||||||
msg_ginfo("No operations were specified.\n");
|
msg_ginfo("No operations were specified.\n");
|
||||||
goto out_shutdown;
|
goto out_shutdown;
|
||||||
}
|
}
|
||||||
@ -813,6 +819,8 @@ int main(int argc, char *argv[])
|
|||||||
programmer_delay(100000);
|
programmer_delay(100000);
|
||||||
if (read_it)
|
if (read_it)
|
||||||
ret = do_read(fill_flash, filename);
|
ret = do_read(fill_flash, filename);
|
||||||
|
else if (extract_it)
|
||||||
|
ret = do_extract(fill_flash);
|
||||||
else if (erase_it)
|
else if (erase_it)
|
||||||
ret = do_erase(fill_flash);
|
ret = do_erase(fill_flash);
|
||||||
else if (write_it)
|
else if (write_it)
|
||||||
|
1
flash.h
1
flash.h
@ -357,6 +357,7 @@ int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *
|
|||||||
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);
|
||||||
void finalize_flash_access(struct flashctx *);
|
void finalize_flash_access(struct flashctx *);
|
||||||
int do_read(struct flashctx *, const char *filename);
|
int do_read(struct flashctx *, const char *filename);
|
||||||
|
int do_extract(struct flashctx *);
|
||||||
int do_erase(struct flashctx *);
|
int do_erase(struct flashctx *);
|
||||||
int do_write(struct flashctx *, const char *const filename, const char *const referencefile);
|
int do_write(struct flashctx *, const char *const filename, const char *const referencefile);
|
||||||
int do_verify(struct flashctx *, const char *const filename);
|
int do_verify(struct flashctx *, const char *const filename);
|
||||||
|
@ -2695,6 +2695,12 @@ int do_read(struct flashctx *const flash, const char *const filename)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int do_extract(struct flashctx *const flash)
|
||||||
|
{
|
||||||
|
prepare_layout_for_extraction(flash);
|
||||||
|
return do_read(flash, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int do_erase(struct flashctx *const flash)
|
int do_erase(struct flashctx *const flash)
|
||||||
{
|
{
|
||||||
const int ret = flashrom_flash_erase(flash);
|
const int ret = flashrom_flash_erase(flash);
|
||||||
|
19
layout.c
19
layout.c
@ -15,6 +15,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -308,6 +309,24 @@ int normalize_romentries(const struct flashctx *flash)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void prepare_layout_for_extraction(struct flashctx *flash)
|
||||||
|
{
|
||||||
|
const struct flashrom_layout *const l = get_layout(flash);
|
||||||
|
unsigned int i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < l->num_entries; ++i) {
|
||||||
|
l->entries[i].included = true;
|
||||||
|
|
||||||
|
if (!l->entries[i].file)
|
||||||
|
l->entries[i].file = strdup(l->entries[i].name);
|
||||||
|
|
||||||
|
for (j = 0; l->entries[i].file[j]; j++) {
|
||||||
|
if (isspace(l->entries[i].file[j]))
|
||||||
|
l->entries[i].file[j] = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const struct romentry *layout_next_included_region(
|
const struct romentry *layout_next_included_region(
|
||||||
const struct flashrom_layout *const l, const chipoff_t where)
|
const struct flashrom_layout *const l, const chipoff_t where)
|
||||||
{
|
{
|
||||||
|
1
layout.h
1
layout.h
@ -69,5 +69,6 @@ int process_include_args(struct flashrom_layout *l, const struct layout_include_
|
|||||||
const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
|
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_included(const struct flashrom_layout *, const struct romentry *);
|
||||||
int included_regions_overlap(const struct flashrom_layout *const flashrom_layout);
|
int included_regions_overlap(const struct flashrom_layout *const flashrom_layout);
|
||||||
|
void prepare_layout_for_extraction(struct flashrom_flashctx *flash);
|
||||||
|
|
||||||
#endif /* !__LAYOUT_H__ */
|
#endif /* !__LAYOUT_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user