"Das U-Boot" Source Tree
at master 70 lines 1.8 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * (C) Copyright 2024, Advanced Micro Devices, Inc. 4 */ 5#include <command.h> 6#include <errno.h> 7#include <tee.h> 8#include <vsprintf.h> 9 10#define TA_HELLO_WORLD_CMD_INC_VALUE 0 11/* This needs to match the UUID of the Hello World TA. */ 12#define TA_HELLO_WORLD_UUID \ 13 { 0x8aaaf200, 0x2450, 0x11e4, \ 14 { 0xab, 0xe2, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b} } 15 16static int hello_world_ta(unsigned int value) 17{ 18 const struct tee_optee_ta_uuid uuid = TA_HELLO_WORLD_UUID; 19 struct tee_open_session_arg session_arg; 20 struct udevice *tee = NULL; 21 struct tee_invoke_arg arg; 22 struct tee_param param[2]; 23 int rc; 24 25 tee = tee_find_device(tee, NULL, NULL, NULL); 26 if (!tee) 27 return -ENODEV; 28 29 memset(&session_arg, 0, sizeof(session_arg)); 30 tee_optee_ta_uuid_to_octets(session_arg.uuid, &uuid); 31 rc = tee_open_session(tee, &session_arg, 0, NULL); 32 if (rc) { 33 printf("tee_open_session(): failed(%d)\n", rc); 34 return rc; 35 } 36 37 arg.func = TA_HELLO_WORLD_CMD_INC_VALUE; 38 arg.session = session_arg.session; 39 40 param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INOUT; 41 param[0].u.value.a = value; 42 43 printf("Value before: 0x%x\n", (int)param[0].u.value.a); 44 printf("Calling TA\n"); 45 tee_invoke_func(tee, &arg, 1, param); 46 47 printf("Value after: 0x%x\n", (int)param[0].u.value.a); 48 return tee_close_session(tee, session_arg.session); 49} 50 51static int do_optee_hello_world_ta(struct cmd_tbl *cmdtp, int flag, int argc, 52 char * const argv[]) 53{ 54 int ret, value = 0; 55 56 if (strcmp(argv[1], NULL)) 57 value = hextoul(argv[1], NULL); 58 59 ret = hello_world_ta(value); 60 if (ret) 61 return CMD_RET_FAILURE; 62 63 return CMD_RET_SUCCESS; 64} 65 66U_BOOT_LONGHELP(optee, 67 "hello [<value>] Invoke the OP-TEE 'Hello World' TA\n"); 68 69U_BOOT_CMD_WITH_SUBCMDS(optee, "OP-TEE commands", optee_help_text, 70 U_BOOT_SUBCMD_MKENT(hello, 2, 1, do_optee_hello_world_ta));