diff options
author | Nikolai Artemiev <nartemiev@google.com> | 2021-10-21 02:28:23 +1100 |
---|---|---|
committer | Anastasia Klimchuk <aklm@chromium.org> | 2022-03-01 04:32:43 +0000 |
commit | 4cb8464e902e14ccc910398fc55874627d88be9b (patch) | |
tree | 2c447936fb80588379e5e3a97bb0f742c4c62718 | |
parent | a548fe5a0341ec1318a0df911f90313d82e2a573 (diff) | |
download | flashrom-4cb8464e902e14ccc910398fc55874627d88be9b.tar.gz flashrom-4cb8464e902e14ccc910398fc55874627d88be9b.tar.bz2 flashrom-4cb8464e902e14ccc910398fc55874627d88be9b.zip |
writeprotect: add set_wp_range()
BUG=b:195381327,b:153800563
BRANCH=none
TEST=flashrom --wp-{status,range}
Change-Id: I7d26f43fb05c5828b9839bb57a28fa1088dcd9a0
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/58482
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r-- | libflashrom.h | 3 | ||||
-rw-r--r-- | writeprotect.c | 37 |
2 files changed, 36 insertions, 4 deletions
diff --git a/libflashrom.h b/libflashrom.h index c9138da2..83a62503 100644 --- a/libflashrom.h +++ b/libflashrom.h @@ -127,7 +127,8 @@ enum flashrom_wp_result { FLASHROM_WP_ERR_OTHER = 2, FLASHROM_WP_ERR_READ_FAILED = 3, FLASHROM_WP_ERR_WRITE_FAILED = 4, - FLASHROM_WP_ERR_VERIFY_FAILED = 5 + FLASHROM_WP_ERR_VERIFY_FAILED = 5, + FLASHROM_WP_ERR_RANGE_UNSUPPORTED = 6 }; enum flashrom_wp_mode { diff --git a/writeprotect.c b/writeprotect.c index b619a242..82ecd8e6 100644 --- a/writeprotect.c +++ b/writeprotect.c @@ -314,6 +314,40 @@ static enum flashrom_wp_result get_ranges_and_wp_bits(struct flashctx *flash, st return FLASHROM_WP_OK; } +static bool ranges_equal(struct wp_range a, struct wp_range b) +{ + return (a.start == b.start) && (a.len == b.len); +} + +/* + * Modify the range-related bits in a wp_bits structure so they select a given + * protection range. Bits that control the protection mode are not changed. + */ +static int set_wp_range(struct wp_bits *bits, struct flashctx *flash, const struct wp_range range) +{ + struct wp_range_and_bits *ranges = NULL; + size_t count; + + enum flashrom_wp_result ret = get_ranges_and_wp_bits(flash, *bits, &ranges, &count); + if (ret != FLASHROM_WP_OK) + return ret; + + /* Search for matching range */ + ret = FLASHROM_WP_ERR_RANGE_UNSUPPORTED; + for (size_t i = 0; i < count; i++) { + + if (ranges_equal(ranges[i].range, range)) { + *bits = ranges[i].bits; + ret = 0; + break; + } + } + + free(ranges); + + return ret; +} + static bool chip_supported(struct flashctx *flash) { return (flash->chip != NULL) && (flash->chip->decode_range != NULL); @@ -354,13 +388,10 @@ enum flashrom_wp_result wp_write_cfg(struct flashctx *flash, const struct flashr ret = read_wp_bits(&bits, flash); /* Set protection range */ - /* TODO: implement set_wp_range() and use it */ - /* if (ret == FLASHROM_WP_OK) ret = set_wp_range(&bits, flash, cfg->range); if (ret == FLASHROM_WP_OK) ret = write_wp_bits(flash, bits); - */ /* Set protection mode */ /* TODO: implement set_wp_mode() and use it */ |