Commit 174551d5 authored by Madhukar Pappireddy's avatar Madhukar Pappireddy Committed by TrustedFirmware Code Review
Browse files

Merge changes from topic "trng-svc" into integration

* changes:
  plat/arm: juno: Use TRNG entropy source for SMCCC TRNG interface
  plat/arm: juno: Condition Juno entropy source with CRC instructions
parents 0aa70f4c cb5f0faa
/*
* Copyright (c) 2021 ARM Limited
*
* SPDX-License-Identifier: BSD-3-Clause
*
* The definitions below are a subset of what we would normally get by using
* the compiler's version of arm_acle.h. We can't use that directly because
* we specify -nostdinc in the Makefiles.
*
* We just define the functions we need so far.
*/
#ifndef ARM_ACLE_H
#define ARM_ACLE_H
#if !defined(__aarch64__) || defined(__clang__)
# define __crc32w __builtin_arm_crc32w
#else
# define __crc32w __builtin_aarch64_crc32w
#endif
#endif /* ARM_ACLE_H */
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef JUNO_DECL_H
#define JUNO_DECL_H
bool juno_getentropy(uint64_t *buf);
#endif /* JUNO_DECL_H */
...@@ -7,15 +7,14 @@ ...@@ -7,15 +7,14 @@
#include <arch_helpers.h> #include <arch_helpers.h>
#include <common/debug.h> #include <common/debug.h>
#include <lib/utils.h> #include <lib/utils.h>
#include <plat/common/plat_trng.h>
#include <platform_def.h> #include <platform_def.h>
#include "juno_decl.h"
u_register_t plat_get_stack_protector_canary(void) u_register_t plat_get_stack_protector_canary(void)
{ {
uint64_t entropy; uint64_t entropy;
if (!juno_getentropy(&entropy)) { if (!plat_get_entropy(&entropy)) {
ERROR("Not enough entropy to initialize canary value\n"); ERROR("Not enough entropy to initialize canary value\n");
panic(); panic();
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#include <arm_acle.h>
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
...@@ -13,7 +14,11 @@ ...@@ -13,7 +14,11 @@
#include <lib/utils_def.h> #include <lib/utils_def.h>
#include <platform_def.h> #include <platform_def.h>
#include "juno_decl.h" #include <lib/smccc.h>
#include <services/trng_svc.h>
#include <smccc_helpers.h>
#include <plat/common/platform.h>
#define NSAMPLE_CLOCKS 1 /* min 1 cycle, max 231 cycles */ #define NSAMPLE_CLOCKS 1 /* min 1 cycle, max 231 cycles */
#define NRETRIES 5 #define NRETRIES 5
...@@ -35,18 +40,24 @@ static bool output_valid(void) ...@@ -35,18 +40,24 @@ static bool output_valid(void)
return false; /* No output data available. */ return false; /* No output data available. */
} }
DEFINE_SVC_UUID2(_plat_trng_uuid,
0x23523c58, 0x7448, 0x4083, 0x9d, 0x16,
0xe3, 0xfa, 0xb9, 0xf1, 0x73, 0xbc
);
uuid_t plat_trng_uuid;
static uint32_t crc_value = ~0U;
/* /*
* This function fills `buf` with 8 bytes of entropy. * Uses the Trusted Entropy Source peripheral on Juno to return 8 bytes of
* It uses the Trusted Entropy Source peripheral on Juno. * entropy. Returns 'true' when done successfully, 'false' otherwise.
* Returns 'true' when the buffer has been filled with entropy
* successfully, or 'false' otherwise.
*/ */
bool juno_getentropy(uint64_t *buf) bool plat_get_entropy(uint64_t *out)
{ {
uint64_t ret; uint64_t ret;
assert(buf); assert(out);
assert(!check_uptr_overflow((uintptr_t)buf, sizeof(*buf))); assert(!check_uptr_overflow((uintptr_t)out, sizeof(*out)));
if (!juno_trng_initialized) { if (!juno_trng_initialized) {
/* Disable interrupt mode. */ /* Disable interrupt mode. */
...@@ -69,14 +80,14 @@ bool juno_getentropy(uint64_t *buf) ...@@ -69,14 +80,14 @@ bool juno_getentropy(uint64_t *buf)
return false; return false;
} }
/* XOR each two 32-bit registers together, combine the pairs */ /* CRC each two 32-bit registers together, combine the pairs */
ret = mmio_read_32(TRNG_BASE + 0); crc_value = __crc32w(crc_value, mmio_read_32(TRNG_BASE + 0));
ret ^= mmio_read_32(TRNG_BASE + 4); crc_value = __crc32w(crc_value, mmio_read_32(TRNG_BASE + 4));
ret <<= 32; ret = (uint64_t)crc_value << 32;
ret |= mmio_read_32(TRNG_BASE + 8); crc_value = __crc32w(crc_value, mmio_read_32(TRNG_BASE + 8));
ret ^= mmio_read_32(TRNG_BASE + 12); crc_value = __crc32w(crc_value, mmio_read_32(TRNG_BASE + 12));
*buf = ret; *out = ret | crc_value;
/* Acknowledge current cycle, clear output registers. */ /* Acknowledge current cycle, clear output registers. */
mmio_write_32(TRNG_BASE + TRNG_STATUS, 1); mmio_write_32(TRNG_BASE + TRNG_STATUS, 1);
...@@ -85,3 +96,13 @@ bool juno_getentropy(uint64_t *buf) ...@@ -85,3 +96,13 @@ bool juno_getentropy(uint64_t *buf)
return true; return true;
} }
void plat_entropy_setup(void)
{
uint64_t dummy;
plat_trng_uuid = _plat_trng_uuid;
/* Initialise the entropy source and trigger RNG generation */
plat_get_entropy(&dummy);
}
...@@ -44,6 +44,8 @@ ifeq (${JUNO_TZMP1}, 1) ...@@ -44,6 +44,8 @@ ifeq (${JUNO_TZMP1}, 1)
$(eval $(call add_define,JUNO_TZMP1)) $(eval $(call add_define,JUNO_TZMP1))
endif endif
TRNG_SUPPORT := 1
ifeq (${JUNO_AARCH32_EL3_RUNTIME}, 1) ifeq (${JUNO_AARCH32_EL3_RUNTIME}, 1)
# Include BL32 in FIP # Include BL32 in FIP
NEED_BL32 := yes NEED_BL32 := yes
...@@ -164,6 +166,12 @@ ifeq (${ALLOW_RO_XLAT_TABLES}, 1) ...@@ -164,6 +166,12 @@ ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
endif endif
endif endif
BL1_CPPFLAGS += -march=armv8-a+crc
BL2_CPPFLAGS += -march=armv8-a+crc
BL2U_CPPFLAGS += -march=armv8-a+crc
BL31_CPPFLAGS += -march=armv8-a+crc
BL32_CPPFLAGS += -march=armv8-a+crc
# Add the FDT_SOURCES and options for Dynamic Config # Add the FDT_SOURCES and options for Dynamic Config
FDT_SOURCES += plat/arm/board/juno/fdts/${PLAT}_fw_config.dts \ FDT_SOURCES += plat/arm/board/juno/fdts/${PLAT}_fw_config.dts \
plat/arm/board/juno/fdts/${PLAT}_tb_fw_config.dts plat/arm/board/juno/fdts/${PLAT}_tb_fw_config.dts
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment