diff options
author | Duncan Laurie <dlaurie@google.com> | 2017-07-23 00:36:27 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-27 17:47:58 +0000 |
commit | 8bae64484f8b655415acfb7ff84051b40bade659 (patch) | |
tree | 9ad2a38f15a5d8f139e6dd92927dd558906d1f79 /common | |
parent | 38285ff21c3da34e8c9ae1c33bc7623ef7447195 (diff) | |
download | chrome-ec-8bae64484f8b655415acfb7ff84051b40bade659.tar.gz |
system_is_locked: Use static variable to track state
When CONFIG_SYSTEM_UNLOCKED is not defined the function to
check if flash is write protected (flash_get_protect()) can
take up to 7ms to execute, and this function is called up to
18 times when booting from RO.
Use a static variable to track the status so we do not spend
so long executing this one function.
Without this change I would regularly see a PD hard reset when
booting without a battery and the system would fail to boot.
BUG=b:63957122
BRANCH=eve
TEST=manual testing to reliably boot without a battery on Eve
Change-Id: I806a215b5745b41ce0d99aeb6853ebfecb0cb7d1
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Reviewed-on: https://chromium-review.googlesource.com/582542
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2320002
Tested-by: Patryk Duda <pdk@semihalf.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Patryk Duda <pdk@semihalf.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/system.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/common/system.c b/common/system.c index 4f308c6795..2d3cfe29d9 100644 --- a/common/system.c +++ b/common/system.c @@ -164,11 +164,16 @@ static uint32_t __attribute__((unused)) get_size(enum ec_image copy) int system_is_locked(void) { + static int is_locked = -1; + if (force_locked) return 1; + if (is_locked != -1) + return is_locked; #ifdef CONFIG_SYSTEM_UNLOCKED /* System is explicitly unlocked */ + is_locked = 0; return 0; #elif defined(CONFIG_FLASH) @@ -177,13 +182,17 @@ int system_is_locked(void) * is not protected. */ if ((EC_FLASH_PROTECT_GPIO_ASSERTED | EC_FLASH_PROTECT_RO_NOW) & - ~flash_get_protect()) + ~flash_get_protect()) { + is_locked = 0; return 0; + } /* If WP pin is asserted and lock is applied, we're locked */ + is_locked = 1; return 1; #else /* Other configs are locked by default */ + is_locked = 1; return 1; #endif } |