Daniel Campello has uploaded this change for review.
cli_classic.c: implement set_wp_region operation
set_wp_region allows to set the wp_range based on a layout region.
Signed-off-by: Daniel Campello <campello@chromium.org>
Change-Id: Ibad68a038ab38b9986b0d8b5f5eb6c73b20ef381
---
M cli_classic.c
M layout.c
M layout.h
3 files changed, 42 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/31/52531/1
diff --git a/cli_classic.c b/cli_classic.c
index 78ae76f..f9a2a14 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -66,6 +66,7 @@
" --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"
@@ -254,6 +255,7 @@
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
@@ -480,6 +482,10 @@
}
#endif /* STANDALONE */
break;
+ case OPTION_WP_SET_REGION:
+ set_wp_region = 1;
+ wp_region = strdup(optarg);
+ break;
default:
cli_classic_abort_usage(NULL);
break;
@@ -746,8 +752,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;
@@ -812,8 +819,8 @@
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;
@@ -823,8 +830,8 @@
/* 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;
@@ -834,7 +841,16 @@
/* 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);
+ ret |= wp->set_range(fill_flash, wp_start, wp_len);
+ }
+
+ if (set_wp_region && wp_region) {
+ if (get_region_range(layout, wp_region, &wp_start, &wp_len)) {
+ ret = 1;
+ goto out_shutdown;
+ }
+ ret |= wp->set_range(fill_flash, wp_start, wp_len);
+ free(wp_region);
}
if (!ret && set_wp_enable) {
@@ -851,8 +867,8 @@
goto out_shutdown;
}
- 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;
@@ -862,8 +878,8 @@
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;
diff --git a/layout.c b/layout.c
index 7fd203d..4d1dd56 100644
--- a/layout.c
+++ b/layout.c
@@ -184,6 +184,20 @@
return 0;
}
+int get_region_range(struct flashrom_layout *const l, const char *name,
+ unsigned int *start, unsigned int *len)
+{
+ size_t i;
+ for (i = 0; i < l->num_entries; ++i) {
+ if (!strcmp(l->entries[i].name, name)) {
+ *start = l->entries[i].start;
+ *len = l->entries[i].end - l->entries[i].start + 1;
+ return 0;
+ }
+ }
+ return 1;
+}
+
/* process -i arguments
* returns 0 to indicate success, >0 to indicate failure
*/
diff --git a/layout.h b/layout.h
index 327f5bf..f574097 100644
--- a/layout.h
+++ b/layout.h
@@ -65,6 +65,8 @@
struct flashrom_flashctx;
const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);
+int get_region_range(struct flashrom_layout *const l, const char *name,
+ unsigned int *start, unsigned int *len);
int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
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 *);
To view, visit change 52531. To unsubscribe, or for help writing mail filters, visit settings.