From 3b24f8ac3f13969b745bae6239d2b7780d6e79cf Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Sun, 7 Aug 2016 19:11:45 -0700 Subject: cr50: try recovering from rolling reboots Sometimes a perfectly sane image enters rolling reboot mode in case some data change triggered a bug which prevents the normal startup and causes a reset. The most likely task causing in in case of cr50 would be the tpm task. Let's add another check of the restart counter: should it reach the value of 50, do not start the TPM task. BRANCH=none BUG=chrome-os-partner:55708 TEST=with this code plus an unaligned access introduced in tpm initialization sequence in both RW_A and RW_B, program the full image on the dev board. Observe the device reset 50 time is rapid succession and then stop with the following message on the console: Bldr |511709 retry|50 Himg =4F992103..408D193E Hfss =384E4655..EE13EBD0 Hinf =44D21600..B70529BD jump @00044000 --- UART initialized after reboot --- [Reset cause: rtc-alarm] [Image: RW, cr50_v1.1.5044-8d6f7a2+ private-cr51:v0.0.68-633229c ... + cryptoc:v0.0.4-5319e83 2016-08-07 19:37:16 vbendeb@kvasha] [0.004130 Inits done] [0.006919 Active NVram partition set to 0] Console is enabled; type HELP for help. > system_rolling_reboot_suspected: roling reboots suspected. Try \ powercycling to clear this condition. [0.010502 Task 2 (TPM) exited!] Change-Id: I6b08c5c1a02da9edf9bdf394e57cc56d2e595ad1 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/366892 Reviewed-by: Bill Richardson --- chip/g/system.c | 16 ++++++++++++++++ common/tpm_registers.c | 3 +++ include/system.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/chip/g/system.c b/chip/g/system.c index 9bc3a26b8e..461f05a462 100644 --- a/chip/g/system.c +++ b/chip/g/system.c @@ -353,6 +353,22 @@ int system_process_retry_counter(void) */ return corrupt_other_header(other); } + +int system_rolling_reboot_suspected(void) +{ + if (GREG32(PMU, LONG_LIFE_SCRATCH0) > 50) { + /* + * The chip has restarted 50 times without the restart counter + * cleared. There must be something wrong going, the chip is + * likely in rolling reboot. + */ + ccprintf("%s: Try powercycling to clear this condition.\n", + __func__); + return 1; + } + + return 0; +} #endif uint32_t system_get_board_properties(void) diff --git a/common/tpm_registers.c b/common/tpm_registers.c index 94b1636b0a..6811c1d758 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -571,6 +571,9 @@ static void call_extension_command(struct tpm_cmd_header *tpmh, void tpm_task(void) { + if (system_rolling_reboot_suspected()) + return; + tpm_init(); sps_tpm_enable(); while (1) { diff --git a/include/system.h b/include/system.h index 1c04ee3404..7b08683ac0 100644 --- a/include/system.h +++ b/include/system.h @@ -489,4 +489,12 @@ uint32_t system_get_board_properties(void); */ uint32_t system_board_properties_callback(void); +/** + * A function provided by some platforms to hint that something is going + * wrong. + * + * @return a boolean, set to True if rolling reboot condition is suspected. + */ +int system_rolling_reboot_suspected(void); + #endif /* __CROS_EC_SYSTEM_H */ -- cgit v1.2.1