blob: 155c9f1bb732d43d643c2b5f88327980e7fc81e4 [file] [log] [blame]
Venkatesh Yadav Abbarapu9d1f19c2024-12-19 10:09:17 +05301// 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>
Tom Riniee8ed542025-05-14 16:46:00 -06009#include <linux/string.h>
Venkatesh Yadav Abbarapu9d1f19c2024-12-19 10:09:17 +053010
11#define TA_HELLO_WORLD_CMD_INC_VALUE 0
12/* This needs to match the UUID of the Hello World TA. */
13#define TA_HELLO_WORLD_UUID \
14 { 0x8aaaf200, 0x2450, 0x11e4, \
15 { 0xab, 0xe2, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b} }
16
17static int hello_world_ta(unsigned int value)
18{
19 const struct tee_optee_ta_uuid uuid = TA_HELLO_WORLD_UUID;
20 struct tee_open_session_arg session_arg;
21 struct udevice *tee = NULL;
22 struct tee_invoke_arg arg;
23 struct tee_param param[2];
24 int rc;
25
26 tee = tee_find_device(tee, NULL, NULL, NULL);
27 if (!tee)
28 return -ENODEV;
29
30 memset(&session_arg, 0, sizeof(session_arg));
31 tee_optee_ta_uuid_to_octets(session_arg.uuid, &uuid);
32 rc = tee_open_session(tee, &session_arg, 0, NULL);
33 if (rc) {
34 printf("tee_open_session(): failed(%d)\n", rc);
35 return rc;
36 }
37
38 arg.func = TA_HELLO_WORLD_CMD_INC_VALUE;
39 arg.session = session_arg.session;
40
41 param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INOUT;
42 param[0].u.value.a = value;
43
44 printf("Value before: 0x%x\n", (int)param[0].u.value.a);
45 printf("Calling TA\n");
46 tee_invoke_func(tee, &arg, 1, param);
47
48 printf("Value after: 0x%x\n", (int)param[0].u.value.a);
49 return tee_close_session(tee, session_arg.session);
50}
51
52static int do_optee_hello_world_ta(struct cmd_tbl *cmdtp, int flag, int argc,
53 char * const argv[])
54{
55 int ret, value = 0;
56
Vincent Stehlé8f3fccf2025-04-04 14:53:58 +020057 if (argc > 1)
Venkatesh Yadav Abbarapu9d1f19c2024-12-19 10:09:17 +053058 value = hextoul(argv[1], NULL);
59
60 ret = hello_world_ta(value);
61 if (ret)
62 return CMD_RET_FAILURE;
63
64 return CMD_RET_SUCCESS;
65}
66
67U_BOOT_LONGHELP(optee,
68 "hello [<value>] Invoke the OP-TEE 'Hello World' TA\n");
69
70U_BOOT_CMD_WITH_SUBCMDS(optee, "OP-TEE commands", optee_help_text,
71 U_BOOT_SUBCMD_MKENT(hello, 2, 1, do_optee_hello_world_ta));