mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-02 14:33:18 +02:00
writeprotect, cli_classic: delete old writeprotect code
Delete writeprotect code that was previously extracted from the cros tree. This is the first of a series of commits adding writeprotect support. Following commits incrementally implement writeprotect operations, culminating in writeprotect support for three example chips: GD25LQ128, GD25Q32, and GD25Q256. BUG=b:195381327,b:153800563 BRANCH=none TEST=flashrom -{r,w,E} TEST=flashrom --wp-{enable,disable,range,list,status} at end of patch series Change-Id: I67e9b31f86465e5a8f7d3def637198671ee818a8 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/58474 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:

committed by
Anastasia Klimchuk

parent
8d50fad443
commit
4571361d0e
173
cli_classic.c
173
cli_classic.c
@ -29,7 +29,6 @@
|
||||
#include "flashchips.h"
|
||||
#include "fmap.h"
|
||||
#include "programmer.h"
|
||||
#include "writeprotect.h"
|
||||
#include "libflashrom.h"
|
||||
|
||||
static void cli_classic_usage(const char *name)
|
||||
@ -60,12 +59,6 @@ static void cli_classic_usage(const char *name)
|
||||
" -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"
|
||||
" --wp-disable disable write protection\n"
|
||||
" --wp-enable enable write protection\n"
|
||||
" --wp-list list write protect range\n"
|
||||
" --wp-status show write protect status\n"
|
||||
" --wp-range=<start>,<len> set write protect range\n"
|
||||
" --wp-region <region> set write protect region\n"
|
||||
" --flash-name read out the detected flash name\n"
|
||||
" --flash-size read out the detected flash size\n"
|
||||
" --fmap read ROM layout from fmap embedded in ROM\n"
|
||||
@ -128,32 +121,6 @@ static bool check_file(FILE *file)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int parse_wp_range(unsigned int *start, unsigned int *len)
|
||||
{
|
||||
char *endptr = NULL, *token = NULL;
|
||||
|
||||
if (!optarg) {
|
||||
msg_gerr("Error: No wp-range values provided\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
token = strtok(optarg, ",");
|
||||
if (!token) {
|
||||
msg_gerr("Error: Invalid wp-range argument format\n");
|
||||
return -1;
|
||||
}
|
||||
*start = strtoul(token, &endptr, 0);
|
||||
|
||||
token = strtok(NULL, ",");
|
||||
if (!token) {
|
||||
msg_gerr("Error: Invalid wp-range argument format\n");
|
||||
return -1;
|
||||
}
|
||||
*len = strtoul(token, &endptr, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_read(struct flashctx *const flash, const char *const filename)
|
||||
{
|
||||
int ret;
|
||||
@ -264,8 +231,6 @@ int main(int argc, char *argv[])
|
||||
int list_supported_wiki = 0;
|
||||
#endif
|
||||
int flash_name = 0, flash_size = 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 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;
|
||||
struct flashrom_layout *layout = NULL;
|
||||
@ -277,15 +242,8 @@ int main(int argc, char *argv[])
|
||||
OPTION_FLASH_CONTENTS,
|
||||
OPTION_FLASH_NAME,
|
||||
OPTION_FLASH_SIZE,
|
||||
OPTION_WP_STATUS,
|
||||
OPTION_WP_SET_RANGE,
|
||||
OPTION_WP_SET_REGION,
|
||||
OPTION_WP_ENABLE,
|
||||
OPTION_WP_DISABLE,
|
||||
OPTION_WP_LIST,
|
||||
};
|
||||
int ret = 0;
|
||||
unsigned int wp_start = 0, wp_len = 0;
|
||||
|
||||
static const char optstring[] = "r:Rw:v:nNVEfc:l:i:p:Lzho:x";
|
||||
static const struct option long_options[] = {
|
||||
@ -308,12 +266,6 @@ int main(int argc, char *argv[])
|
||||
{"flash-name", 0, NULL, OPTION_FLASH_NAME},
|
||||
{"flash-size", 0, NULL, OPTION_FLASH_SIZE},
|
||||
{"get-size", 0, NULL, OPTION_FLASH_SIZE}, // (deprecated): back compatibility.
|
||||
{"wp-status", 0, 0, OPTION_WP_STATUS},
|
||||
{"wp-range", required_argument, NULL, OPTION_WP_SET_RANGE},
|
||||
{"wp-region", 1, 0, OPTION_WP_SET_REGION},
|
||||
{"wp-enable", optional_argument, 0, OPTION_WP_ENABLE},
|
||||
{"wp-disable", 0, 0, OPTION_WP_DISABLE},
|
||||
{"wp-list", 0, 0, OPTION_WP_LIST},
|
||||
{"list-supported", 0, NULL, 'L'},
|
||||
{"list-supported-wiki", 0, NULL, 'z'},
|
||||
{"programmer", 1, NULL, 'p'},
|
||||
@ -333,8 +285,6 @@ int main(int argc, char *argv[])
|
||||
char *tempstr = NULL;
|
||||
char *pparam = NULL;
|
||||
struct layout_include_args *include_args = NULL;
|
||||
char *wp_mode_opt = NULL;
|
||||
char *wp_region = NULL;
|
||||
|
||||
/*
|
||||
* Safety-guard against a user who has (mistakenly) closed
|
||||
@ -463,26 +413,6 @@ int main(int argc, char *argv[])
|
||||
cli_classic_validate_singleop(&operation_specified);
|
||||
flash_size = 1;
|
||||
break;
|
||||
case OPTION_WP_STATUS:
|
||||
wp_status = 1;
|
||||
break;
|
||||
case OPTION_WP_LIST:
|
||||
wp_list = 1;
|
||||
break;
|
||||
case OPTION_WP_SET_RANGE:
|
||||
if (parse_wp_range(&wp_start, &wp_len) < 0)
|
||||
cli_classic_abort_usage("Incorrect wp-range arguments provided.\n");
|
||||
|
||||
set_wp_range = 1;
|
||||
break;
|
||||
case OPTION_WP_ENABLE:
|
||||
set_wp_enable = 1;
|
||||
if (optarg)
|
||||
wp_mode_opt = strdup(optarg);
|
||||
break;
|
||||
case OPTION_WP_DISABLE:
|
||||
set_wp_disable = 1;
|
||||
break;
|
||||
case 'L':
|
||||
cli_classic_validate_singleop(&operation_specified);
|
||||
list_supported = 1;
|
||||
@ -565,10 +495,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif /* STANDALONE */
|
||||
break;
|
||||
case OPTION_WP_SET_REGION:
|
||||
set_wp_region = 1;
|
||||
wp_region = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
cli_classic_abort_usage(NULL);
|
||||
break;
|
||||
@ -768,33 +694,15 @@ int main(int argc, char *argv[])
|
||||
goto out_shutdown;
|
||||
}
|
||||
|
||||
if (!(read_it | write_it | verify_it | erase_it | flash_name | flash_size
|
||||
| set_wp_range | set_wp_region | set_wp_enable |
|
||||
set_wp_disable | wp_status | wp_list | extract_it)) {
|
||||
const bool any_op = read_it || write_it || verify_it || erase_it ||
|
||||
flash_name || flash_size || extract_it;
|
||||
|
||||
|
||||
if (!any_op) {
|
||||
msg_ginfo("No operations were specified.\n");
|
||||
goto out_shutdown;
|
||||
}
|
||||
|
||||
if (set_wp_enable && set_wp_disable) {
|
||||
msg_ginfo("Error: --wp-enable and --wp-disable are mutually exclusive\n");
|
||||
ret = 1;
|
||||
goto out_shutdown;
|
||||
}
|
||||
if (set_wp_range && set_wp_region) {
|
||||
msg_gerr("Error: Cannot use both --wp-range and --wp-region simultaneously.\n");
|
||||
ret = 1;
|
||||
goto out_shutdown;
|
||||
}
|
||||
|
||||
struct wp *wp = fill_flash->chip->wp;
|
||||
if (set_wp_range || set_wp_region) {
|
||||
if (!wp || !wp->set_range) {
|
||||
msg_gerr("Error: write protect is not supported on this flash chip.\n");
|
||||
ret = 1;
|
||||
goto out_shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
if (flash_name) {
|
||||
if (fill_flash->chip->vendor && fill_flash->chip->name) {
|
||||
printf("vendor=\"%s\" name=\"%s\"\n",
|
||||
@ -849,76 +757,6 @@ int main(int argc, char *argv[])
|
||||
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 (set_wp_region && wp_region) {
|
||||
if (flashrom_layout_get_region_range(layout, wp_region, &wp_start, &wp_len)) {
|
||||
ret = 1;
|
||||
goto out_release;
|
||||
}
|
||||
ret |= wp->set_range(fill_flash, wp_start, wp_len);
|
||||
free(wp_region);
|
||||
}
|
||||
|
||||
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);
|
||||
@ -952,7 +790,6 @@ int main(int argc, char *argv[])
|
||||
else if (verify_it)
|
||||
ret = do_verify(fill_flash, filename);
|
||||
|
||||
out_release:
|
||||
flashrom_layout_release(layout);
|
||||
out_shutdown:
|
||||
flashrom_programmer_shutdown(NULL);
|
||||
|
Reference in New Issue
Block a user