Edward O'Callaghan has submitted this change. ( https://review.coreboot.org/c/flashrom/+/52530 )
Change subject: cli_classic.c: reorder writeprotect operation processing ......................................................................
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 --- M cli_classic.c 1 file changed, 64 insertions(+), 63 deletions(-)
Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved
diff --git a/cli_classic.c b/cli_classic.c index 57f8dfb..58e81cd 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -680,8 +680,9 @@ 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,66 +705,6 @@ goto out_shutdown; }
- if (wp_status) { - if (fill_flash->chip->wp && fill_flash->chip->wp->wp_status) { - ret |= fill_flash->chip->wp->wp_status(fill_flash); - } else { - msg_gerr("Error: write protect is not supported on this flash chip.\n"); - ret = 1; - } - goto out_shutdown; - } - - /* 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); - } else { - msg_gerr("Error: write protect is not supported on this flash chip.\n"); - ret = 1; - goto out_shutdown; - } - } - - if (!ret && set_wp_enable) { - enum wp_mode wp_mode; - - if (wp_mode_opt) - wp_mode = get_wp_mode(wp_mode_opt); - else - wp_mode = WP_MODE_HARDWARE; /* default */ - - if (wp_mode == WP_MODE_UNKNOWN) { - msg_gerr("Error: Invalid WP mode: "%s"\n", wp_mode_opt); - ret = 1; - goto out_shutdown; - } - - if (fill_flash->chip->wp && fill_flash->chip->wp->enable) { - ret |= fill_flash->chip->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; - } - } - - 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); - } 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) || @@ -803,8 +744,68 @@ ret = 1; goto out_shutdown; } - flashrom_layout_set(fill_flash, layout); + + if (wp_status) { + 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_release; + } + + /* Note: set_wp_disable should be done before setting the range */ + if (set_wp_disable) { + 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_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; + + if (wp_mode_opt) + wp_mode = get_wp_mode(wp_mode_opt); + else + wp_mode = WP_MODE_HARDWARE; /* default */ + + if (wp_mode == WP_MODE_UNKNOWN) { + msg_gerr("Error: Invalid WP mode: "%s"\n", wp_mode_opt); + ret = 1; + goto out_release; + } + + 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_release; + } + } + + if (wp_list) { + msg_ginfo("Valid write protection ranges:\n"); + 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_release; + } + 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 @@ else if (verify_it) ret = do_verify(fill_flash, filename);
+out_release: flashrom_layout_release(layout); - out_shutdown: programmer_shutdown(); out: