From f704fbb5ecd719f23ec4fe5e9fea0d14a46d42e9 Mon Sep 17 00:00:00 2001 From: hongshuqing Date: Fri, 26 Jun 2026 19:08:10 +0800 Subject: [PATCH] update bootloader_random_enable and disbale api --- .../src/bootloader_random_esp32h21.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/components/bootloader_support/src/bootloader_random_esp32h21.c b/components/bootloader_support/src/bootloader_random_esp32h21.c index 071ea905cfc..01612120702 100644 --- a/components/bootloader_support/src/bootloader_random_esp32h21.c +++ b/components/bootloader_support/src/bootloader_random_esp32h21.c @@ -5,14 +5,36 @@ */ #include "sdkconfig.h" #include "bootloader_random.h" +#include "soc/lpperi_reg.h" +#include "rom/ets_sys.h" +#include "rom/uart.h" void bootloader_random_enable(void) { + // Disable rtc_timer update for rng + SET_PERI_REG_BITS(LPPERI_RNG_CFG_REG, LPPERI_RTC_TIMER_EN, 0, LPPERI_RTC_TIMER_EN_S); + // Enable entropy source of ring + SET_PERI_REG_MASK(LPPERI_RNG_CFG_REG, LPPERI_RNG_SAMPLE_ENABLE); + //For dieharder test + ets_printf("H21: Random bytes (%s) follow:\n", "test"); + while (1) { + uint32_t w = READ_PERI_REG(LPPERI_RNG_DATA_SYNC_REG); + ets_printf("rng_data:%d\n", w); + uart_tx_wait_idle(0); + + // uart_tx_one_char(w >> 24); + // uart_tx_one_char(w >> 16); + // uart_tx_one_char(w >> 8); + // uart_tx_one_char(w); + } } void bootloader_random_disable(void) { - + // Disable rtc_timer update for rng + SET_PERI_REG_BITS(LPPERI_RNG_CFG_REG, LPPERI_RTC_TIMER_EN, 0, LPPERI_RTC_TIMER_EN_S); + // Disable entropy source of ring + CLEAR_PERI_REG_MASK(LPPERI_RNG_CFG_REG, LPPERI_RNG_SAMPLE_ENABLE); }