summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Sukhomlinov <sukhomlinov@google.com>2023-03-28 19:47:32 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-07 22:08:29 +0000
commit44a748a92f840bc3d4f74ae3b22a8f080d755441 (patch)
tree1012c43b2f76d38b1d51f3d9b185bdca8f008486
parentc1c637bb53eaa9de9ead652dc9908eef6c15b8a5 (diff)
downloadchrome-ec-44a748a92f840bc3d4f74ae3b22a8f080d755441.tar.gz
cr50: update TRNG timeout handlingstabilize-15415.B-cr50_stab
1. Due to large share of devices with slow TRNG increase timeout cycles from 0x7ff to 0xfff. 2. Increase total reset attempts from 16 to 32. 2. Log number of resets. BUG=b:211648605 TEST=make CRYPTO_TEST=1 Change-Id: Ib0f9472d6f84c39cd7576f374ab482e522a39809 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4380143 Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Code-Coverage: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
-rw-r--r--board/cr50/dcrypto/trng.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/board/cr50/dcrypto/trng.c b/board/cr50/dcrypto/trng.c
index a67d5ef766..e93d0bb051 100644
--- a/board/cr50/dcrypto/trng.c
+++ b/board/cr50/dcrypto/trng.c
@@ -34,16 +34,15 @@ static volatile struct trng_reg *reg_trng = (void *)(GC_TRNG_BASE_ADDR);
/**
* Attempts to read TRNG_EMPTY before reporting a stall. Practically data should
- * be available in less than 0x7ff cycles under normal conditions. 0x7ff was
- * chosen to match the hardware TRNG TIMEOUT_COUNTER. Test on boards with slow
- * TRNG before reducing this number.
+ * be available in less than 0xfff cycles under normal conditions.
+ * Test on boards with slow TRNG before reducing this number.
*/
-#define TRNG_EMPTY_COUNT 0x7ff
+#define TRNG_EMPTY_COUNT 0xfff
/**
* Number of attempts to reset TRNG after stall is detected.
*/
-#define TRNG_RESET_COUNT 16
+#define TRNG_RESET_COUNT 32
void fips_init_trng(void)
{
@@ -101,7 +100,7 @@ void fips_init_trng(void)
*/
reg_trng->allowed_values = 0x26;
- reg_trng->timeout_counter = 0x7ff;
+ reg_trng->timeout_counter = TRNG_EMPTY_COUNT;
reg_trng->timeout_max_try = 4;
reg_trng->power_down_b = 1;
reg_trng->go_event = 1;
@@ -110,7 +109,7 @@ void fips_init_trng(void)
uint64_t read_rand(void)
{
uint32_t empty_count = 0;
- uint32_t reset_count = 0;
+ uint8_t reset_count = 0;
#ifdef CRYPTO_TEST_SETUP
/* Do we need to simulate error? */
@@ -130,19 +129,15 @@ uint64_t read_rand(void)
empty_count = 0;
reset_count++;
reg_trng->go_event = 1;
-#ifdef CONFIG_FLASH_LOG
- /**
- * Log stall only first time. Placing it after TRNG
- * go_event increase a chance to get random in case
- * of slow TRNG.
- */
- if (reset_count == 1)
- fips_vtable->flash_log_add_event(
- FE_LOG_TRNG_STALL, 0, NULL);
-#endif
}
empty_count++;
}
+#ifdef CONFIG_FLASH_LOG
+ /* Log stall count if happened .*/
+ if (reset_count > 0)
+ fips_vtable->flash_log_add_event(
+ FE_LOG_TRNG_STALL, sizeof(reset_count), &reset_count);
+#endif
/**
* High 32-bits set to zero in case of error;
* otherwise value >> 32 == 1