summaryrefslogtreecommitdiff
path: root/chip/stm32/flash-f.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2014-10-09 15:19:22 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-15 23:55:55 +0000
commit82915c25029c0bc2c018cfc080d913255ed82aac (patch)
tree1da32cff8e9e01142b63960fd454ff2b1832278a /chip/stm32/flash-f.c
parent5ff320f66e990a5efe8270f6125ed7c55699d50c (diff)
downloadchrome-ec-82915c25029c0bc2c018cfc080d913255ed82aac.tar.gz
Write protect support for STM32F0
On STM32F0, we cannot work around the hard fault triggered when trying to protect the whole flash. Therefore, we need to go with the ALL_AT_BOOT approach. When write protect is enabled, instead of setting ALL_NOW flag to immediately lock down the entire flash, we need to set ALL_AT_BOOT and then reboot to have the protection take effect. BUG=chrome-os-partner:32745 TEST=Along with the next CL. On Ryu: 1. Enable HW WP. Check the output of 'ectool flashprotect' and see correct flags. 2. 'flashrom -p ec --wp-range 0 0x10000'. Check RO_AT_BOOT is set. 3. Reboot EC and check RO_NOW is enabled. 4. Boot the system and check ALL_NOW is set. 5. Update BIOS and reboot. Check software sync updates EC-RW. 6. 'flashrom -p ec --wp-disable' and check it fails. 7. Disable HW WP and reboot EC. Check RO_NOW and ALL_NOW are cleared. 8. 'flashrom -p ec --wp-disable' and check RO_AT_BOOT is cleared. TEST=Enable/disable WP on Spring. Check RO_AT_BOOT/ALL_NOW can be set properly. BRANCH=samus Change-Id: I1c7c4f98f2535f1c8a1c7daaa88d47412d015977 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/222622 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/stm32/flash-f.c')
-rw-r--r--chip/stm32/flash-f.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c
index 29e2c062d7..e457aea8ce 100644
--- a/chip/stm32/flash-f.c
+++ b/chip/stm32/flash-f.c
@@ -426,8 +426,9 @@ int flash_pre_init(void)
* to the check above. One of them should be able to
* go away.
*/
- flash_protect_ro_at_boot(
- prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT);
+ flash_protect_at_boot(
+ (prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) ?
+ FLASH_WP_RO : FLASH_WP_NONE);
need_reset = 1;
}
} else {
@@ -441,6 +442,19 @@ int flash_pre_init(void)
}
}
+ if (!!(prot_flags & EC_FLASH_PROTECT_ALL_AT_BOOT) !=
+ !!(prot_flags & EC_FLASH_PROTECT_ALL_NOW)) {
+ /*
+ * ALL_AT_BOOT and ALL_NOW should be both set or both unset
+ * at boot. If they are not, it must be that the chip requires
+ * OBL_LAUNCH to be set to reload option bytes. Let's reset
+ * the system with OBL_LAUNCH set.
+ * This assumes OBL_LAUNCH is used for hard reset in
+ * chip/stm32/system.c.
+ */
+ need_reset = 1;
+ }
+
if (need_reset)
system_reset(SYSTEM_RESET_HARD | SYSTEM_RESET_PRESERVE_FLAGS);