Skip to content

Commit c9fcfb1

Browse files
meremSTPatrice Chotard
authored andcommitted
rng: stm32: update default RNG configuration for STM32MP25
Use the configuration used for the NIST certification. Signed-off-by: Maxime Méré <maxime.mere@foss.st.com> Change-Id: I482523d3074ee99816b6ecadbfe38495db9f3c65 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/453705 Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com> ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com> Domain-Review: Yann GAUTIER <yann.gautier@foss.st.com> ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
1 parent c2671a2 commit c9fcfb1

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

drivers/rng/stm32_rng.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
#define RNG_CR_CLKDIV GENMASK(19, 16)
2929
#define RNG_CR_CONFIG1 GENMASK(25, 20)
3030
#define RNG_CR_CONDRST BIT(30)
31-
#define RNG_CR_ENTROPY_SRC_MASK (RNG_CR_CONFIG3 | RNG_CR_NISTC | RNG_CR_CONFIG2 | RNG_CR_CONFIG1)
32-
#define RNG_CR_CONFIG_MASK (RNG_CR_ENTROPY_SRC_MASK | RNG_CR_CED | RNG_CR_CLKDIV)
31+
#define RNG_CR_CONFIG_MASK (RNG_CR_CED | RNG_CR_CLKDIV)
3332

3433
#define RNG_SR 0x04
3534
#define RNG_SR_SEIS BIT(6)
@@ -60,6 +59,7 @@
6059
struct stm32_rng_data {
6160
uint max_clock_rate;
6261
uint nb_clock;
62+
u32 cr_config1_mask;
6363
u32 cr;
6464
u32 nscr;
6565
u32 htcr;
@@ -75,6 +75,12 @@ struct stm32_rng_plat {
7575
bool ced;
7676
};
7777

78+
static uint32_t stm32_rng_get_entropy_mask(struct stm32_rng_plat *pdata)
79+
{
80+
return (RNG_CR_CONFIG3 | RNG_CR_NISTC |
81+
RNG_CR_CONFIG2 | pdata->data->cr_config1_mask);
82+
}
83+
7884
/*
7985
* Extracts from the STM32 RNG specification when RNG supports CONDRST.
8086
*
@@ -278,9 +284,10 @@ static int stm32_rng_init(struct stm32_rng_plat *pdata)
278284
*/
279285
if (pdata->data->has_cond_reset && pdata->data->cr) {
280286
uint clock_div = stm32_rng_clock_freq_restrain(pdata);
287+
u32 entropy_mask = stm32_rng_get_entropy_mask(pdata);
281288

282-
cr &= ~RNG_CR_CONFIG_MASK;
283-
cr |= RNG_CR_CONDRST | (pdata->data->cr & RNG_CR_ENTROPY_SRC_MASK) |
289+
cr &= ~(RNG_CR_CONFIG_MASK | entropy_mask);
290+
cr |= RNG_CR_CONDRST | (pdata->data->cr & entropy_mask) |
284291
(clock_div << RNG_CR_CLKDIV_SHIFT);
285292
if (pdata->ced)
286293
cr &= ~RNG_CR_CED;
@@ -406,9 +413,10 @@ static const struct stm32_rng_data stm32mp25_rng_data = {
406413
.has_cond_reset = true,
407414
.max_clock_rate = 48000000,
408415
.nb_clock = 2,
409-
.htcr = 0x969D,
410-
.nscr = 0x2B5BB,
411-
.cr = 0xF00D00,
416+
.htcr = 0x6688,
417+
.nscr = 0x2E649,
418+
.cr = 0x08F01E00,
419+
.cr_config1_mask = GENMASK(27, 20),
412420
};
413421

414422
static const struct stm32_rng_data stm32mp21_rng_data = {
@@ -418,6 +426,7 @@ static const struct stm32_rng_data stm32mp21_rng_data = {
418426
.htcr = 0xAAC7,
419427
.nscr = 0x01FF,
420428
.cr = 0x00800D00,
429+
.cr_config1_mask = GENMASK(27, 20),
421430
};
422431

423432
static const struct stm32_rng_data stm32mp13_rng_data = {
@@ -427,6 +436,7 @@ static const struct stm32_rng_data stm32mp13_rng_data = {
427436
.htcr = 0x969D,
428437
.nscr = 0x2B5BB,
429438
.cr = 0xF00D00,
439+
.cr_config1_mask = GENMASK(25, 20),
430440
};
431441

432442
static const struct stm32_rng_data stm32_rng_data = {

0 commit comments

Comments
 (0)