Skip to content

Commit 304aee5

Browse files
twcook86danielinux
authored andcommitted
Add support for hardware rng
1 parent c48016f commit 304aee5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

arch.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,12 @@ ifeq ($(TARGET),lpc55s69)
11991199
-I$(MCUXPRESSO)/drivers/iap1 \
12001200
-I$(MCUXPRESSO)/drivers/lpc_gpio \
12011201
-I$(MCUXPRESSO)/drivers/lpc_iocon \
1202+
-I$(MCUXPRESSO)/drivers/rng_1 \
12021203
-I$(MCUXPRESSO_CMSIS)/Include \
12031204
-I$(MCUXPRESSO_CMSIS)/Core/Include
12041205
CFLAGS+=-DCPU_$(MCUXPRESSO_CPU)
1206+
CFLAGS+=-DFSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL=1
1207+
CFLAGS+=-DFSL_SDK_DISABLE_DRIVER_RESET_CONTROL=1
12051208
CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33 -U__ARM_FEATURE_DSP
12061209
LDFLAGS+=-mcpu=cortex-m33 -Wl,--no-warn-rwx-segments
12071210
OBJS+=\
@@ -1211,6 +1214,9 @@ ifeq ($(TARGET),lpc55s69)
12111214
$(MCUXPRESSO)/drivers/common/fsl_common_arm.o \
12121215
$(MCUXPRESSO)/drivers/iap1/fsl_iap.o \
12131216
$(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o
1217+
ifeq ($(WOLFCRYPT_TZ),1)
1218+
OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o
1219+
endif
12141220
ifeq ($(DEBUG_UART),1)
12151221
OBJS+=\
12161222
$(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
@@ -659,6 +659,9 @@ ifeq ($(TARGET),lpc55s69)
659659
$(MCUXPRESSO)/drivers/flexcomm/usart/fsl_usart.o \
660660
$(MCUXPRESSO)/drivers/iap1/fsl_iap.o \
661661
$(MCUXPRESSO)/drivers/lpc_gpio/fsl_gpio.o
662+
ifeq ($(WOLFCRYPT_TZ),1)
663+
APP_OBJS+=$(MCUXPRESSO)/drivers/rng_1/fsl_rng.o
664+
endif
662665
ifeq (,$(findstring nosys.specs,$(LDFLAGS)))
663666
LDFLAGS+=--specs=nosys.specs
664667
endif

0 commit comments

Comments
 (0)