@@ -20,6 +20,7 @@
#include <Library/DxeServicesLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OpteeLib.h>
+#include <Library/TimerLib.h>
#include <Platform/VarStore.h>
STATIC
@@ -109,6 +110,53 @@ DtPlatformLoadDtb (
EnableDtNode (CopyDtb, "/firmware/optee");
}
+/* This UUID is generated with uuidgen
+ the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */
+#define TA_TS_UUID { 0xab, 0x7a, 0x61, 0x7c, 0xb8, 0xe7, 0x4d, 0x8f, \
+ 0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64 }
+
+/* The Trusted Application Function ID(s) invoked to get random numbers */
+#define TA_CMD_GET_RNG 0
+
+ OpteeInit ();
+
+#if 1
+ OPTEE_OPEN_SESSION_ARG OpenSessionArg = { 0 };
+ OPTEE_INVOKE_FUNC_ARG InvokeFuncArg = { 0 };
+ UINT8 TaUuid[] = TA_TS_UUID;
+ UINT64 RngData = 0;
+
+ memcpy (OpenSessionArg.Uuid, TaUuid, OPTEE_UUID_LEN);
+ OpteeOpenSession (&OpenSessionArg);
+ DEBUG ((EFI_D_WARN, "OP-TEE Session: 0x%X, Ret: 0x%X, RetOrigin: 0x%X\n", OpenSessionArg.Session, OpenSessionArg.Ret, OpenSessionArg.RetOrigin));
+
+ InvokeFuncArg.Func = TA_CMD_GET_RNG;
+ InvokeFuncArg.Session = OpenSessionArg.Session;
+
+ InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT;
+ InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData;
+ InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64);
+
+ Status = OpteeInvokeFunc (&InvokeFuncArg);
+ DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin));
+
+ MicroSecondDelay(16000);
+
+ memset(&InvokeFuncArg, 0, sizeof (OPTEE_INVOKE_FUNC_ARG));
+
+ InvokeFuncArg.Func = TA_CMD_GET_RNG;
+ InvokeFuncArg.Session = OpenSessionArg.Session;
+
+ InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT;
+ InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData;
+ InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64);
+
+ Status = OpteeInvokeFunc (&InvokeFuncArg);
+ DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin));
+
+ OpteeCloseSession (OpenSessionArg.Session);
+#endif
+
*Dtb = CopyDtb;
*DtbSize = CopyDtbSize;
@@ -36,6 +36,7 @@ [LibraryClasses]
FdtLib
MemoryAllocationLib
OpteeLib
+ TimerLib
[Pcd]
gSynQuacerTokenSpaceGuid.PcdPcieEnableMask