summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Campello <campello@chromium.org>2021-04-19 18:37:56 -0600
committerEdward O'Callaghan <quasisec@chromium.org>2021-05-04 02:18:11 +0000
commit6509912a1de079dd7cbd173d0232e23787b2ec67 (patch)
tree4dcbba435ba63adbc93a00ac816d229c3894f103
parentce983bccaab450d358854494f15c2d8a1846d56b (diff)
downloadflashrom-6509912a1de079dd7cbd173d0232e23787b2ec67.tar.gz
flashrom-6509912a1de079dd7cbd173d0232e23787b2ec67.tar.bz2
flashrom-6509912a1de079dd7cbd173d0232e23787b2ec67.zip
cli_classic.c: reorder writeprotect operation processing
Make sure that layout is set before. Also as the comment instructs make sure that set_rw_range happens before set_wp_enable. Signed-off-by: Daniel Campello <campello@chromium.org> Change-Id: I7480d3f947aaaf30093d056226fe0c402763efdc Reviewed-on: https://review.coreboot.org/c/flashrom/+/52530 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r--cli_classic.c123
1 files changed, 62 insertions, 61 deletions
diff --git a/cli_classic.c b/cli_classic.c
index 57f8dfba0..58e81cd92 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -680,8 +680,9 @@ int main(int argc, char *argv[])
goto out_shutdown;
}
+ struct wp *wp = fill_flash->chip->wp;
if (set_wp_range || set_wp_region) {
- if (!fill_flash->chip->wp || !fill_flash->chip->wp->set_range) {
+ if (!wp || !wp->set_range) {
msg_gerr("Error: write protect is not supported on this flash chip.\n");
ret = 1;
goto out_shutdown;
@@ -704,27 +705,73 @@ int main(int argc, char *argv[])
goto out_shutdown;
}
+ if (layoutfile) {
+ layout = get_global_layout();
+ } else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
+ process_include_args(layout, include_args))) {
+ ret = 1;
+ goto out_shutdown;
+ } else if (fmap && fmapfile) {
+ struct stat s;
+ if (stat(fmapfile, &s) != 0) {
+ msg_gerr("Failed to stat fmapfile \"%s\"\n", fmapfile);
+ ret = 1;
+ goto out_shutdown;
+ }
+
+ size_t fmapfile_size = s.st_size;
+ uint8_t *fmapfile_buffer = malloc(fmapfile_size);
+ if (!fmapfile_buffer) {
+ ret = 1;
+ goto out_shutdown;
+ }
+
+ if (read_buf_from_file(fmapfile_buffer, fmapfile_size, fmapfile)) {
+ ret = 1;
+ free(fmapfile_buffer);
+ goto out_shutdown;
+ }
+
+ if (flashrom_layout_read_fmap_from_buffer(&layout, fill_flash, fmapfile_buffer, fmapfile_size) ||
+ process_include_args(layout, include_args)) {
+ ret = 1;
+ free(fmapfile_buffer);
+ goto out_shutdown;
+ }
+ free(fmapfile_buffer);
+ } else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0,
+ fill_flash->chip->total_size * 1024) || process_include_args(layout, include_args))) {
+ ret = 1;
+ goto out_shutdown;
+ }
+ flashrom_layout_set(fill_flash, layout);
+
if (wp_status) {
- if (fill_flash->chip->wp && fill_flash->chip->wp->wp_status) {
- ret |= fill_flash->chip->wp->wp_status(fill_flash);
+ if (wp && wp->wp_status) {
+ ret |= wp->wp_status(fill_flash);
} else {
msg_gerr("Error: write protect is not supported on this flash chip.\n");
ret = 1;
}
- goto out_shutdown;
+ goto out_release;
}
/* Note: set_wp_disable should be done before setting the range */
if (set_wp_disable) {
- if (fill_flash->chip->wp && fill_flash->chip->wp->disable) {
- ret |= fill_flash->chip->wp->disable(fill_flash);
+ if (wp && wp->disable) {
+ ret |= wp->disable(fill_flash);
} else {
msg_gerr("Error: write protect is not supported on this flash chip.\n");
ret = 1;
- goto out_shutdown;
+ goto out_release;
}
}
+ /* Note: set_wp_range must happen before set_wp_enable */
+ if (set_wp_range) {
+ ret |= wp->set_range(fill_flash, wp_start, wp_len);
+ }
+
if (!ret && set_wp_enable) {
enum wp_mode wp_mode;
@@ -736,75 +783,29 @@ int main(int argc, char *argv[])
if (wp_mode == WP_MODE_UNKNOWN) {
msg_gerr("Error: Invalid WP mode: \"%s\"\n", wp_mode_opt);
ret = 1;
- goto out_shutdown;
+ goto out_release;
}
- if (fill_flash->chip->wp && fill_flash->chip->wp->enable) {
- ret |= fill_flash->chip->wp->enable(fill_flash, wp_mode);
+ if (wp && wp->enable) {
+ ret |= wp->enable(fill_flash, wp_mode);
} else {
msg_gerr("Error: write protect is not supported on this flash chip.\n");
ret = 1;
- goto out_shutdown;
+ goto out_release;
}
}
if (wp_list) {
msg_ginfo("Valid write protection ranges:\n");
- if (fill_flash->chip->wp && fill_flash->chip->wp->list_ranges) {
- ret |= fill_flash->chip->wp->list_ranges(fill_flash);
+ if (wp && wp->list_ranges) {
+ ret |= wp->list_ranges(fill_flash);
} else {
msg_gerr("Error: write protect is not supported on this flash chip.\n");
ret = 1;
}
- goto out_shutdown;
- }
-
- /* Note: set_wp_range must happen before set_wp_enable */
- if (set_wp_range) {
- ret |= fill_flash->chip->wp->set_range(fill_flash, wp_start, wp_len);
- }
-
- if (layoutfile) {
- layout = get_global_layout();
- } else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
- process_include_args(layout, include_args))) {
- ret = 1;
- goto out_shutdown;
- } else if (fmap && fmapfile) {
- struct stat s;
- if (stat(fmapfile, &s) != 0) {
- msg_gerr("Failed to stat fmapfile \"%s\"\n", fmapfile);
- ret = 1;
- goto out_shutdown;
- }
-
- size_t fmapfile_size = s.st_size;
- uint8_t *fmapfile_buffer = malloc(fmapfile_size);
- if (!fmapfile_buffer) {
- ret = 1;
- goto out_shutdown;
- }
-
- if (read_buf_from_file(fmapfile_buffer, fmapfile_size, fmapfile)) {
- ret = 1;
- free(fmapfile_buffer);
- goto out_shutdown;
- }
-
- if (flashrom_layout_read_fmap_from_buffer(&layout, fill_flash, fmapfile_buffer, fmapfile_size) ||
- process_include_args(layout, include_args)) {
- ret = 1;
- free(fmapfile_buffer);
- goto out_shutdown;
- }
- free(fmapfile_buffer);
- } else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0,
- fill_flash->chip->total_size * 1024) || process_include_args(layout, include_args))) {
- ret = 1;
- goto out_shutdown;
+ goto out_release;
}
- flashrom_layout_set(fill_flash, layout);
flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE, !!force);
#if CONFIG_INTERNAL == 1
flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE_BOARDMISMATCH, !!force_boardmismatch);
@@ -828,8 +829,8 @@ int main(int argc, char *argv[])
else if (verify_it)
ret = do_verify(fill_flash, filename);
+out_release:
flashrom_layout_release(layout);
-
out_shutdown:
programmer_shutdown();
out: