From c76f9852c4e62d134f57f134c30d73289e4a72a7 Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Thu, 30 Mar 2017 17:13:03 -0700 Subject: [PATCH] cr50: wp: Only use RAM val on wake from hibernate. When Cr50 resumes from hibernate, it should use the WP state that was stored in the long life scratch registers. All other boots should simply follow the state of the BATT_PRES_L pin. BUG=b:36659750 BRANCH=master,cr50 TEST=Power on Cr50 via battery, verify that WP_L remains asserted. Change-Id: I516d43b6540d7c543e7629f8709ce63515bb7f76 Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/464258 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Mary Ruthven --- board/cr50/wp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/board/cr50/wp.c b/board/cr50/wp.c index c381f81b3b..63ca909c9b 100644 --- a/board/cr50/wp.c +++ b/board/cr50/wp.c @@ -207,14 +207,15 @@ static void init_console_lock_and_wp(void) uint8_t key; const struct tuple *t; uint8_t lock_state; + uint32_t reset_flags; + reset_flags = system_get_reset_flags(); /* * On an unexpected reboot or a system rollback reset the console lock * and write protect states. */ if (system_rollback_detected() || - !(system_get_reset_flags() & - (RESET_FLAG_HIBERNATE | RESET_FLAG_POWER_ON))) { + !(reset_flags & (RESET_FLAG_HIBERNATE | RESET_FLAG_POWER_ON))) { /* Reset the console lock to the default value */ CPRINTS("Setting console lock to default."); set_console_lock_state(console_restricted_state); @@ -238,10 +239,15 @@ static void init_console_lock_and_wp(void) set_console_lock_state(lock_state); } - if (GREG32(PMU, LONG_LIFE_SCRATCH1) & BOARD_WP_ASSERTED) - set_wp_state(1); - else - set_wp_state(0); + if (reset_flags & RESET_FLAG_HIBERNATE) { + if (GREG32(PMU, LONG_LIFE_SCRATCH1) & BOARD_WP_ASSERTED) + set_wp_state(1); + else + set_wp_state(0); + } else if (reset_flags & RESET_FLAG_POWER_ON) { + /* Use BATT_PRES_L as the source for write protect. */ + set_wp_state(!gpio_get_level(GPIO_BATT_PRES_L)); + } } /* This must run after initializing the NVMem partitions. */ DECLARE_HOOK(HOOK_INIT, init_console_lock_and_wp, HOOK_PRIO_DEFAULT+1);