feat (bootloader): added rng sampling

Set maximum RNG query frequency to save value known from tests
This commit is contained in:
Jakob Hasse
2021-10-25 19:13:42 +08:00
parent 5cc4bceb2a
commit 64a355eba8
5 changed files with 118 additions and 11 deletions

View File

@@ -18,6 +18,13 @@
}
#else
#if !defined CONFIG_IDF_TARGET_ESP32S3
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 32 * 2) /* extra factor of 2 is precautionary */
#else
#define RNG_CPU_WAIT_CYCLE_NUM (80 * 23) /* 45 KHz reading frequency is the maximum we have tested so far on S3 */
#endif
__attribute__((weak)) void bootloader_fill_random(void *buffer, size_t length)
{
uint8_t *buffer_bytes = (uint8_t *)buffer;
@@ -40,7 +47,7 @@
do {
random ^= REG_READ(WDEV_RND_REG);
now = cpu_hal_get_cycle_count();
} while (now - start < 80 * 32 * 2); /* extra factor of 2 is precautionary */
} while (now - start < RNG_CPU_WAIT_CYCLE_NUM);
}
buffer_bytes[i] = random >> ((i % 4) * 8);
}