Skip to content

Commit 1bfd5b1

Browse files
committed
Add support for hardware rng
1 parent 9376718 commit 1bfd5b1

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

arch.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,12 @@ ifeq ($(TARGET),lpc55s69)
11281128
-I$(MCUXPRESSO)/drivers/iap1 \
11291129
-I$(MCUXPRESSO)/drivers/lpc_gpio \
11301130
-I$(MCUXPRESSO)/drivers/lpc_iocon \
1131+
-I$(MCUXPRESSO)/drivers/rng_1 \
11311132
-I$(MCUXPRESSO_CMSIS)/Include \
11321133
-I$(MCUXPRESSO_CMSIS)/Core/Include
11331134
CFLAGS+=-DCPU_$(MCUXPRESSO_CPU)
1135+
CFLAGS+=-DFSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL=1
1136+
CFLAGS+=-DFSL_SDK_DISABLE_DRIVER_RESET_CONTROL=1
11341137
CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33 -U__ARM_FEATURE_DSP
11351138
LDFLAGS+=-mcpu=cortex-m33 -Wl,--no-warn-rwx-segments
11361139
OBJS+=\
@@ -1140,6 +1143,9 @@ ifeq ($(TARGET),lpc55s69)
11401143
$(MCUXPRESSO)/drivers/common/fsl_common_arm.o \
11411144
$(MCUXPRESSO)/drivers/iap1/fsl_iap.o \
11421145
$(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o
1146+
ifeq ($(WOLFCRYPT_TZ),1)
1147+
OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o
1148+
endif
11431149
ifeq ($(DEBUG_UART),1)
11441150
OBJS+=\
11451151
$(MCUXPRESSO_DRIVERS)/drivers/fsl_reset.o \

hal/lpc55s69.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "fsl_iap.h"
3131
#include "fsl_iocon.h"
3232
#include "fsl_reset.h"
33+
#include "fsl_rng.h"
3334
#include "fsl_usart.h"
3435
#include "loader.h"
3536

@@ -166,6 +167,11 @@ int RAMFUNCTION hal_flash_is_erased_at(uint32_t address)
166167
#ifdef WOLFCRYPT_SECURE_MODE
167168
void hal_trng_init(void)
168169
{
170+
#ifdef __WOLFBOOT
171+
CLOCK_EnableClock(kCLOCK_Rng);
172+
RESET_PeripheralReset(kRNG_RST_SHIFT_RSTn);
173+
#endif
174+
RNG_Init(RNG);
169175
}
170176

171177
void hal_trng_fini(void)
@@ -174,8 +180,9 @@ void hal_trng_fini(void)
174180

175181
int hal_trng_get_entropy(unsigned char *out, unsigned int len)
176182
{
177-
(void)out;
178-
(void)len;
183+
if (RNG_GetRandomData(RNG, out, len) == kStatus_Success)
184+
return 0;
185+
179186
return -1;
180187
}
181188
#endif
@@ -222,6 +229,7 @@ void uart_init(void)
222229

223230
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
224231
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
232+
CLOCK_EnableClock(kCLOCK_FlexComm0);
225233
RESET_ClearPeripheralReset(kFC0_RST_SHIFT_RSTn);
226234

227235
usart_config_t config;

test-app/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ ifeq ($(TARGET),lpc55s69)
582582
$(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \
583583
$(MCUXPRESSO)/drivers/iap1/fsl_iap.o \
584584
$(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o
585+
ifeq ($(WOLFCRYPT_TZ),1)
586+
APP_OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o
587+
endif
585588
ifeq (,$(findstring nosys.specs,$(LDFLAGS)))
586589
LDFLAGS+=--specs=nosys.specs
587590
endif

0 commit comments

Comments
 (0)