From 4af07d9b00e8bf9724d60dfd30d6aa3724565a6f Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Tue, 13 Jun 2017 15:54:32 -0700 Subject: [PATCH] g: provide an API to set rollback counter to ensure rollback with the board ID match happening in the RW we need to be able to set the rollback counter to a value which would guarantee a fallback during the next boot. BRANCH=cr50 BUG=b:35586335 TEST=with the rest of the patches verified the ability to set the counter to trigger a fallback on the next reboot. Change-Id: I161f39354e5523121e26e8ad84a791a8b06e5123 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/535976 Reviewed-by: Randall Spangler Reviewed-by: Mary Ruthven --- chip/g/system.c | 7 +++++++ chip/g/system_chip.h | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/chip/g/system.c b/chip/g/system.c index f1b45c802e..b3ded8f963 100644 --- a/chip/g/system.c +++ b/chip/g/system.c @@ -523,6 +523,13 @@ int system_process_retry_counter(void) return corrupt_header(newer_image); } +void system_ensure_rollback(void) +{ + GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, REG0, 1); + GREG32(PMU, LONG_LIFE_SCRATCH0) = RW_BOOT_MAX_RETRY_COUNT + 1; + GWRITE_FIELD(PMU, LONG_LIFE_SCRATCH_WR_EN, REG0, 0); +} + int system_rolling_reboot_suspected(void) { if (GREG32(PMU, LONG_LIFE_SCRATCH0) > 50) { diff --git a/chip/g/system_chip.h b/chip/g/system_chip.h index 251c2d3007..ce63f3eab8 100644 --- a/chip/g/system_chip.h +++ b/chip/g/system_chip.h @@ -57,8 +57,7 @@ int system_battery_cutoff_support_required(void); */ void system_update_rollback_mask(void); -/* - ** +/** * Scan INFO1 rollback map and infomap fields of both RW and RW_B image * headers, and return a string showing how many zeros are there at the base * of in each of these objects. @@ -68,4 +67,10 @@ void system_update_rollback_mask(void); */ void system_get_rollback_bits(char *value, size_t value_size); +/** + * Set the rollback counter to a value which would ensure a rollback on the + * next boot. + */ +void system_ensure_rollback(void); + #endif /* __CROS_EC_SYSTEM_CHIP_H */