summaryrefslogtreecommitdiff
path: root/chip/mec1322/flash.c
diff options
context:
space:
mode:
authorAndrey Petrov <andrey.petrov@intel.com>2015-06-10 10:33:39 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-16 18:47:22 +0000
commitef4d930f88ecf150bffa5761af72e7fa68b77afd (patch)
tree18326cf15cbadd91030fbc5ca988bd7ee45e00ff /chip/mec1322/flash.c
parentd705a4d208826a3666e4c201a6379434bc8695e8 (diff)
downloadchrome-ec-ef4d930f88ecf150bffa5761af72e7fa68b77afd.tar.gz
cyan: fix issues with write protection
* Fixes cyan/board.h to use correct SPI part * Adds new flash protection regions in spi_flash_reg.c * Sets SRP register in flash_physical_protect_at_boot() * Fixes a bug in COMPARE_BIT macro * Makes spi_flash_set_status() fail only when both HW pin is asserted AND SRP(s) are set * Makes sure set_flash_set_status() completes before returning BUG=chrome-os-partner:40908 BRANCH=master TEST=on Cyan: With WP pin de-asserted: flashrom -p ec --wp-enable flashrom -p ec --wp-status, make sure it is enabled flashrom -p ec --wp-disable flashrom -p ec --status, make sure it is disabled flashrom -p ec --wp-enable Assert WP pin (either with screwdriver or dut-control) flashrom -p ec --wp-disable make sure it failed Change-Id: I338cc906b73e723fdbb37f7c2fd0c4da358b6c8e Signed-off-by: Andrey Petrov <andrey.petrov@intel.com> Reviewed-on: https://chromium-review.googlesource.com/276671 Reviewed-by: Shawn N <shawnn@chromium.org> Tested-by: Divya Jyothi <divya.jyothi@intel.com> Commit-Queue: Divya Jyothi <divya.jyothi@intel.com>
Diffstat (limited to 'chip/mec1322/flash.c')
-rw-r--r--chip/mec1322/flash.c82
1 files changed, 19 insertions, 63 deletions
diff --git a/chip/mec1322/flash.c b/chip/mec1322/flash.c
index a893ba7868..f263d42755 100644
--- a/chip/mec1322/flash.c
+++ b/chip/mec1322/flash.c
@@ -97,22 +97,9 @@ int flash_physical_erase(int offset, int size)
*/
int flash_physical_get_protect(int bank)
{
-#ifdef CONFIG_WP_ENABLE
-/*
- * TODO(crosbug/p/40908): This section was causing SPI to lock up
- * while installing via firmware updater. Disabled it temporarily.
- * will get re-enabled after Flash protection is tested under all
- * scenarios
- */
-
- uint32_t addr = bank * CONFIG_FLASH_BANK_SIZE;
- int ret;
-
- ret = spi_flash_check_protect(addr, CONFIG_FLASH_BANK_SIZE);
- return ret;
-#else
- return 0;
-#endif
+ return spi_flash_check_protect(CONFIG_FLASH_BASE_SPI +
+ bank * CONFIG_FLASH_BANK_SIZE,
+ CONFIG_FLASH_BANK_SIZE);
}
/**
@@ -123,29 +110,18 @@ int flash_physical_get_protect(int bank)
*/
int flash_physical_protect_now(int all)
{
-#ifdef CONFIG_WP_ENABLE
-/*
- * TODO(crosbug/p/40908): This section was causing SPI to lock up
- * while installing via firmware updater. Disabled it temporarily.
- * will get re-enabled after Flash protection is tested under all
- * scenarios
- */
-
int offset, size, ret;
if (all) {
- offset = 0;
+ offset = CONFIG_FLASH_BASE_SPI;
size = CONFIG_FLASH_PHYSICAL_SIZE;
} else {
- offset = CONFIG_WP_OFF;
+ offset = CONFIG_WP_OFF + CONFIG_FLASH_BASE_SPI;
size = CONFIG_WP_SIZE;
}
ret = spi_flash_set_protect(offset, size);
return ret;
-#else
- return 0;
-#endif
}
/**
@@ -159,21 +135,14 @@ uint32_t flash_physical_get_protect_flags(void)
{
uint32_t flags = 0;
-#ifdef CONFIG_WP_ENABLE
-/*
- * TODO(crosbug/p/40908): This section was causing SPI to lock up
- * while installing via firmware updater. Disabled it temporarily.
- * will get re-enabled after Flash protection is tested under all
- * scenarios
- */
-
- if (spi_flash_check_protect(CONFIG_RO_STORAGE_OFF, CONFIG_RO_SIZE)) {
+ if (spi_flash_check_protect(CONFIG_FLASH_BASE_SPI +
+ CONFIG_RO_STORAGE_OFF, CONFIG_RO_SIZE)) {
flags |= EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW;
- if (spi_flash_check_protect(CONFIG_RW_STORAGE_OFF,
+ if (spi_flash_check_protect(CONFIG_FLASH_BASE_SPI +
+ CONFIG_RW_STORAGE_OFF,
CONFIG_RW_SIZE))
flags |= EC_FLASH_PROTECT_ALL_NOW;
}
-#endif
return flags;
}
@@ -198,22 +167,14 @@ uint32_t flash_physical_get_valid_flags(void)
uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
{
uint32_t ret = 0;
+ enum spi_flash_wp wp_status = SPI_WP_NONE;
-#ifdef CONFIG_WP_ENABLE
-/*
- * TODO(crosbug/p/40908): This section was causing SPI to lock up
- * while installing via firmware updater. Disabled it temporarily.
- * will get re-enabled after Flash protection is tested under all
- * scenarios
- */
-
- enum spi_flash_wp wp_status = spi_flash_check_wp();
+ wp_status = spi_flash_check_wp();
if (wp_status == SPI_WP_NONE || (wp_status == SPI_WP_HARDWARE &&
!(cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED)))
ret = EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW |
EC_FLASH_PROTECT_ALL_NOW;
-#endif
return ret;
}
@@ -230,35 +191,30 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags)
*/
int flash_physical_protect_at_boot(enum flash_wp_range range)
{
-#ifdef CONFIG_WP_ENABLE
-/*
- * TODO(crosbug/p/40908): This section was causing SPI to lock up
- * while installing via firmware updater. Disabled it temporarily.
- * will get re-enabled after Flash protection is tested under all
- * scenarios
- */
-
int offset, size, ret;
+ enum spi_flash_wp flashwp = SPI_WP_NONE;
switch (range) {
case FLASH_WP_NONE:
offset = size = 0;
+ flashwp = SPI_WP_NONE;
break;
case FLASH_WP_RO:
- offset = CONFIG_WP_OFF;
+ offset = CONFIG_FLASH_BASE_SPI + CONFIG_WP_OFF;
size = CONFIG_WP_SIZE;
+ flashwp = SPI_WP_HARDWARE;
break;
case FLASH_WP_ALL:
- offset = 0;
+ offset = CONFIG_FLASH_BASE_SPI;
size = CONFIG_FLASH_PHYSICAL_SIZE;
+ flashwp = SPI_WP_HARDWARE;
break;
}
ret = spi_flash_set_protect(offset, size);
+ if (ret == EC_SUCCESS)
+ ret = spi_flash_set_wp(flashwp);
return ret;
-#else
- return 0;
-#endif
}
/**