diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-01-11 14:17:33 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-12 21:05:11 -0800 |
commit | 8c12f0a53f93e12530081fcbe164dab48257e58d (patch) | |
tree | ce2873f66b05e28ad2d9b0170c52f5856f74eb1e /chip/mec1322/flash.c | |
parent | 14533749af1c89f3b0224092c580ebe147611299 (diff) | |
download | chrome-ec-8c12f0a53f93e12530081fcbe164dab48257e58d.tar.gz |
flash: Pass more precise parameter to flash_[physical_]protect_at_boot
In preparation for adding the rollback protection block, pass
EC_FLASH_PROTECT_RO/ALL_AT_BOOT to flash_[physical_]protect_at_boot,
instead of an enumeration no protection/RO/ALL.
This will later allow us to protect/unprotect the rollback region only,
by adding a EC_FLASH_PROTECT_ROLLBACK_AT_BOOT flag.
BRANCH=none
BUG=chrome-os-partner:61671
TEST=Build hammer with CONFIG_CMD_FLASH command, so that write protection
can be checked with flasherase/flashwrite.
TEST=On hammer (stm32f072):
flashinfo => RO+RW not protected
flashwp true; reboot => only RO protected
flashwp rw; reboot => RO+RW protected
flashwp norw; reboot => only RO protected
TEST=On reef (npcx):
deassert WP, flashwp false; flashinfo => RO+RW not protected
flashwp true => only RO protected
reboot => only RO protected
flashwp rw => RO+RW protected
reboot => only RO protected
Change-Id: Iec96a7377baabc9100fc59de0a31505095a3499f
Reviewed-on: https://chromium-review.googlesource.com/430518
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/mec1322/flash.c')
-rw-r--r-- | chip/mec1322/flash.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/chip/mec1322/flash.c b/chip/mec1322/flash.c index 1564b93b48..2cd8dd156d 100644 --- a/chip/mec1322/flash.c +++ b/chip/mec1322/flash.c @@ -187,32 +187,31 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) * Once write protect is enabled, it will stay enabled until HW PIN is * de-asserted and SRP register is unset. * - * However, this implementation treats FLASH_WP_ALL as FLASH_WP_RO but - * tries to remember if "all" region is protected. + * However, this implementation treats EC_FLASH_PROTECT_ALL_AT_BOOT as + * EC_FLASH_PROTECT_RO_AT_BOOT but tries to remember if "all" region + * is protected. * - * @param range The range to protect. + * @param new_flags to protect (only EC_FLASH_PROTECT_*_AT_BOOT are + * taken care of) * @return EC_SUCCESS, or nonzero if error. */ -int flash_physical_protect_at_boot(enum flash_wp_range range) +int flash_physical_protect_at_boot(uint32_t new_flags) { int offset, size, ret; enum spi_flash_wp flashwp = SPI_WP_NONE; - switch (range) { - case FLASH_WP_NONE: + if ((new_flags & (EC_FLASH_PROTECT_RO_AT_BOOT | + EC_FLASH_PROTECT_ALL_AT_BOOT)) == 0) { + /* Clear protection */ offset = size = 0; flashwp = SPI_WP_NONE; - break; - case FLASH_WP_ALL: - entire_flash_locked = 1; - /* Fallthrough */ - case FLASH_WP_RO: + } else { + if (new_flags & EC_FLASH_PROTECT_ALL_AT_BOOT) + entire_flash_locked = 1; + offset = CONFIG_WP_STORAGE_OFF; size = CONFIG_WP_STORAGE_SIZE; flashwp = SPI_WP_HARDWARE; - break; - default: - return EC_ERROR_INVAL; } ret = spi_flash_set_protect(offset, size); |