├── ta
├── Android.mk
├── sub.mk
├── Makefile
├── include
│ └── hello_world_ta.h
├── user_ta_header_defines.h
└── hello_world_ta.c
├── .gitignore
├── Makefile
├── doc
├── Makefile
├── close_session_and_finalize_context.msc
├── invoke_command.msc
└── open_session.msc
├── host
├── Makefile
└── main.c
├── Android.mk
└── README.md
/ta/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | local_module := 8aaaf200-2450-11e4-abe2-0002a5d5c51b.ta
4 | include $(BUILD_OPTEE_MK)
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | host/hello_world
2 | GPATH
3 | GRTAGS
4 | GSYMS
5 | GTAGS
6 | *.cmd
7 | *.d
8 | *.dmp
9 | *.elf
10 | *.lds
11 | *.map
12 | *.o
13 | *.png
14 | *.swp
15 | *.ta
16 | cscope.*
17 |
--------------------------------------------------------------------------------
/ta/sub.mk:
--------------------------------------------------------------------------------
1 | global-incdirs-y += include
2 | #global-incdirs-y += ../host/include
3 | srcs-y += hello_world_ta.c
4 |
5 | # To remove a certain compiler flag, add a line like this
6 | #cflags-template_ta.c-y += -Wno-strict-prototypes
7 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 |
2 | export V?=0
3 |
4 | .PHONY: all
5 | all:
6 | $(MAKE) -C host CROSS_COMPILE="$(HOST_CROSS_COMPILE)"
7 | $(MAKE) -C ta CROSS_COMPILE="$(TA_CROSS_COMPILE)"
8 |
9 | .PHONY: clean
10 | clean:
11 | $(MAKE) -C host clean
12 | $(MAKE) -C ta clean
13 |
--------------------------------------------------------------------------------
/doc/Makefile:
--------------------------------------------------------------------------------
1 |
2 | .PHONY: all
3 | all:
4 |
5 | MSC_SRCS = open_session.msc invoke_command.msc \
6 | close_session_and_finalize_context.msc
7 |
8 | PNGS += $(MSC_SRCS:.msc=.png)
9 |
10 | # Disable all builtin rules
11 | .SUFFIXES:
12 | .SUFFIXES: .png .msc
13 |
14 | all: $(PNGS)
15 |
16 | %.png : %.msc
17 | mscgen -T png $<
18 |
19 | .PHONY: clean
20 | clean:
21 | rm -f $(PNGS)
22 |
--------------------------------------------------------------------------------
/ta/Makefile:
--------------------------------------------------------------------------------
1 | CFG_TEE_TA_LOG_LEVEL ?= 4
2 | CPPFLAGS += -DCFG_TEE_TA_LOG_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
3 |
4 | # The UUID for the Trusted Application
5 | BINARY=8aaaf200-2450-11e4-abe2-0002a5d5c51b
6 |
7 | -include $(TA_DEV_KIT_DIR)/mk/ta_dev_kit.mk
8 |
9 | ifeq ($(wildcard $(TA_DEV_KIT_DIR)/mk/ta_dev_kit.mk), )
10 | clean:
11 | @echo 'Note: $$(TA_DEV_KIT_DIR)/mk/ta_dev_kit.mk not found, cannot clean TA'
12 | @echo 'Note: TA_DEV_KIT_DIR=$(TA_DEV_KIT_DIR)'
13 | endif
14 |
--------------------------------------------------------------------------------
/doc/close_session_and_finalize_context.msc:
--------------------------------------------------------------------------------
1 | msc {
2 | hscale = "0.9", wordwraparcs = on;
3 |
4 | a [label="hello_world\nuser space"],
5 | b [label="hello world\nTEE Driver"],
6 | f [label="TEE Core"],
7 | g [label="TA"];
8 |
9 | ||| ;
10 | a=>b [ label = "Close\nSession" ];
11 | b=>f [ label = "Close\nSession" ];
12 | f=>g [ label = "TA_CloseSessionEntryPoint" ];
13 | g>>f ;
14 | f>>b ;
15 | b>>a ;
16 | a=>b [ label = "Finalize\nContext" ];
17 | b>>a ;
18 | }
19 |
--------------------------------------------------------------------------------
/doc/invoke_command.msc:
--------------------------------------------------------------------------------
1 | msc {
2 | hscale = "0.9", wordwraparcs = on;
3 |
4 | a [label="hello_world\nuser space"],
5 | b [label="hello world\nTEE Driver"],
6 | f [label="TEE Core"],
7 | g [label="TA"];
8 |
9 | ||| ;
10 | a=>b [ label = "Invoke\nCommand" ];
11 | b=>f [ label = "Invoke\nCommand" ];
12 | f=>g [ label = "TA_InvokeCommandEntryPoint" ];
13 | g>>f [ label = "ret: result" ];
14 | f>>b [ label = "ret: result" ];
15 | b>>a [ label = "ret: result" ];
16 | }
17 |
--------------------------------------------------------------------------------
/host/Makefile:
--------------------------------------------------------------------------------
1 | CC = $(CROSS_COMPILE)gcc
2 | LD = $(CROSS_COMPILE)ld
3 | AR = $(CROSS_COMPILE)ar
4 | NM = $(CROSS_COMPILE)nm
5 | OBJCOPY = $(CROSS_COMPILE)objcopy
6 | OBJDUMP = $(CROSS_COMPILE)objdump
7 | READELF = $(CROSS_COMPILE)readelf
8 |
9 | OBJS = main.o
10 |
11 | CFLAGS += -Wall -I../ta/include -I$(TEEC_EXPORT)/include -I./include
12 | #Add/link other required libraries here
13 | LDADD += -lteec -L$(TEEC_EXPORT)/lib
14 |
15 | BINARY=hello_world
16 |
17 | .PHONY: all
18 | all: $(BINARY)
19 |
20 | $(BINARY): $(OBJS)
21 | $(CC) -o $@ $< $(LDADD)
22 |
23 | .PHONY: clean
24 | clean:
25 | rm -f $(OBJS) $(BINARY)
26 |
--------------------------------------------------------------------------------
/doc/open_session.msc:
--------------------------------------------------------------------------------
1 | msc {
2 | hscale = "0.9", wordwraparcs = on;
3 |
4 | a [label="hello_world\nuser space"],
5 | b [label="hello world\nTEE Driver"],
6 | c [label="tee-supplicant"],
7 | f [label="TEE Core"],
8 | g [label="TA"];
9 |
10 | ||| ;
11 | a=>b [ label = "Open\nSession" ];
12 | b=>f [ label = "Open\nSession" ];
13 | f=>f [ label = "Looking for TA" ];
14 | f=>c [ label = "Load TA" ];
15 | c=>c [ label = "Loading TA" ];
16 | c>>f [ label = "Load TA" ];
17 | f=>f [ label = "Load TA" ];
18 | f=>g [ label = "TA_OpenSessionEntryPoint" ];
19 | g>>f ;
20 | f>>b [ label = "ret: session" ];
21 | b>>a [ label = "ret: session" ];
22 | }
23 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Android optee-hello-world makefile #
3 | ################################################################################
4 | LOCAL_PATH := $(call my-dir)
5 |
6 | CFG_TEEC_PUBLIC_INCLUDE = $(LOCAL_PATH)/../optee_client/public
7 |
8 | ################################################################################
9 | # Build hello world #
10 | ################################################################################
11 | include $(CLEAR_VARS)
12 | LOCAL_CFLAGS += -DANDROID_BUILD
13 | LOCAL_CFLAGS += -Wall
14 |
15 | LOCAL_SRC_FILES += host/main.c
16 |
17 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/ta/include \
18 | $(CFG_TEEC_PUBLIC_INCLUDE) \
19 |
20 | LOCAL_SHARED_LIBRARIES := libteec
21 | LOCAL_MODULE := tee_helloworld
22 | LOCAL_MODULE_TAGS := optional
23 | include $(BUILD_EXECUTABLE)
24 |
25 | include $(LOCAL_PATH)/ta/Android.mk
26 |
--------------------------------------------------------------------------------
/ta/include/hello_world_ta.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Linaro Limited
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * 2. Redistributions in binary form must reproduce the above copyright notice,
12 | * this list of conditions and the following disclaimer in the documentation
13 | * and/or other materials provided with the distribution.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 | * POSSIBILITY OF SUCH DAMAGE.
26 | */
27 | #ifndef TA_HELLO_WORLD_H
28 | #define TA_HELLO_WORLD_H
29 |
30 | /* This UUID is generated with uuidgen
31 | the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */
32 | #define TA_HELLO_WORLD_UUID { 0x8aaaf200, 0x2450, 0x11e4, \
33 | { 0xab, 0xe2, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b} }
34 |
35 | /* The Trusted Application Function ID(s) implemented in this TA */
36 | #define TA_HELLO_WORLD_CMD_INC_VALUE 0
37 |
38 | #endif /*TA_HELLO_WORLD_H*/
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hello World - \*\*DEPRECATED\*\*
2 |
3 | # 2018-01-01: This standalone Hello World TA has been deprecated
4 | We have just recently created another git called [optee_examples](https://github.com/linaro-swg/optee_examples). The code from this Hello World application has been moved into that optee_examples git, so Hello World resides there as one standalone example together with a few other standalone example host/ta pairs. We will keep this git here as a reference in case someone needs it for historical reasons (links pointing here etc).
5 |
6 | Description
7 | ------------
8 | This is a reference template to start writing a Trusted Application
9 |
10 | Presentation
11 | ------------
12 |
13 | This example has been presented at the Linaro Connect USA 2014.
14 | The slides are available [here](http://www.slideshare.net/linaroorg/lcu14103-how-to-create-and-run-trusted-applications-on-optee).
15 |
16 | Manual Build Instructions
17 | -------------------------
18 |
19 | 1. Setup the OP-TEE software stack by following: https://github.com/OP-TEE/optee_os#5-repo-manifests
20 |
21 | 2. Clone this repository into `$HOME/devel/optee`
22 |
23 | ```
24 | git clone https://github.com/linaro-swg/hello_world.git
25 | cd hello_world
26 | ```
27 |
28 | 3. Define the toolchains and environment variables:
29 |
30 | ```
31 | export TEEC_EXPORT=$PWD/../optee_client/out/export
32 | ```
33 |
34 | If normal world user space is 64-bit:
35 | ```
36 | export HOST_CROSS_COMPILE=$PWD/../toolchains/aarch64/bin/aarch64-linux-gnu-
37 | ```
38 |
39 | If normal world user space is 32-bit:
40 | ```
41 | export HOST_CROSS_COMPILE=$PWD/../toolchains/aarch32/bin/arm-linux-gnueabihf-
42 | ```
43 |
44 | If secure world user space is 64-bit:
45 | ```
46 | export TA_CROSS_COMPILE=$PWD/../toolchains/aarch64/bin/aarch64-linux-gnu-
47 | export TA_DEV_KIT_DIR=$PWD/../optee_os/out/arm/export-ta_arm64
48 | ```
49 |
50 | If secure world user space is 32-bit:
51 | ```
52 | export TA_CROSS_COMPILE=$PWD/../toolchains/aarch32/bin/arm-linux-gnueabihf-
53 | export TA_DEV_KIT_DIR=$PWD/../optee_os/out/arm/export-ta_arm32
54 | ```
55 |
56 | 4. Build it!
57 |
58 | make
59 |
60 |
--------------------------------------------------------------------------------
/ta/user_ta_header_defines.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Linaro Limited
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * 2. Redistributions in binary form must reproduce the above copyright notice,
12 | * this list of conditions and the following disclaimer in the documentation
13 | * and/or other materials provided with the distribution.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 | * POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | /*
29 | * The name of this file must not be modified
30 | */
31 |
32 | #ifndef USER_TA_HEADER_DEFINES_H
33 | #define USER_TA_HEADER_DEFINES_H
34 |
35 | #include /* To get the TA_HELLO_WORLD_UUID define */
36 |
37 | #define TA_UUID TA_HELLO_WORLD_UUID
38 |
39 | #define TA_FLAGS (TA_FLAG_MULTI_SESSION | TA_FLAG_EXEC_DDR)
40 | #define TA_STACK_SIZE (2 * 1024)
41 | #define TA_DATA_SIZE (32 * 1024)
42 |
43 | #define TA_CURRENT_TA_EXT_PROPERTIES \
44 | { "gp.ta.description", USER_TA_PROP_TYPE_STRING, \
45 | "Hello World TA" }, \
46 | { "gp.ta.version", USER_TA_PROP_TYPE_U32, &(const uint32_t){ 0x0010 } }
47 |
48 | #endif /*USER_TA_HEADER_DEFINES_H*/
49 |
--------------------------------------------------------------------------------
/host/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Linaro Limited
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * 2. Redistributions in binary form must reproduce the above copyright notice,
12 | * this list of conditions and the following disclaimer in the documentation
13 | * and/or other materials provided with the distribution.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 | * POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #include
29 | #include
30 | #include
31 |
32 | /* OP-TEE TEE client API (built by optee_client) */
33 | #include
34 |
35 | /* To the the UUID (found the the TA's h-file(s)) */
36 | #include
37 |
38 | int main(int argc, char *argv[])
39 | {
40 | TEEC_Result res;
41 | TEEC_Context ctx;
42 | TEEC_Session sess;
43 | TEEC_Operation op;
44 | TEEC_UUID uuid = TA_HELLO_WORLD_UUID;
45 | uint32_t err_origin;
46 |
47 | /* Initialize a context connecting us to the TEE */
48 | res = TEEC_InitializeContext(NULL, &ctx);
49 | if (res != TEEC_SUCCESS)
50 | errx(1, "TEEC_InitializeContext failed with code 0x%x", res);
51 |
52 | /*
53 | * Open a session to the "hello world" TA, the TA will print "hello
54 | * world!" in the log when the session is created.
55 | */
56 | res = TEEC_OpenSession(&ctx, &sess, &uuid,
57 | TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
58 | if (res != TEEC_SUCCESS)
59 | errx(1, "TEEC_Opensession failed with code 0x%x origin 0x%x",
60 | res, err_origin);
61 |
62 | /*
63 | * Execute a function in the TA by invoking it, in this case
64 | * we're incrementing a number.
65 | *
66 | * The value of command ID part and how the parameters are
67 | * interpreted is part of the interface provided by the TA.
68 | */
69 |
70 | /* Clear the TEEC_Operation struct */
71 | memset(&op, 0, sizeof(op));
72 |
73 | /*
74 | * Prepare the argument. Pass a value in the first parameter,
75 | * the remaining three parameters are unused.
76 | */
77 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE,
78 | TEEC_NONE, TEEC_NONE);
79 | op.params[0].value.a = 42;
80 |
81 | /*
82 | * TA_HELLO_WORLD_CMD_INC_VALUE is the actual function in the TA to be
83 | * called.
84 | */
85 | printf("Invoking TA to increment %d\n", op.params[0].value.a);
86 | res = TEEC_InvokeCommand(&sess, TA_HELLO_WORLD_CMD_INC_VALUE, &op,
87 | &err_origin);
88 | if (res != TEEC_SUCCESS)
89 | errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x",
90 | res, err_origin);
91 | printf("TA incremented value to %d\n", op.params[0].value.a);
92 |
93 | /*
94 | * We're done with the TA, close the session and
95 | * destroy the context.
96 | *
97 | * The TA will print "Goodbye!" in the log when the
98 | * session is closed.
99 | */
100 |
101 | TEEC_CloseSession(&sess);
102 |
103 | TEEC_FinalizeContext(&ctx);
104 |
105 | return 0;
106 | }
107 |
--------------------------------------------------------------------------------
/ta/hello_world_ta.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Linaro Limited
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | *
11 | * 2. Redistributions in binary form must reproduce the above copyright notice,
12 | * this list of conditions and the following disclaimer in the documentation
13 | * and/or other materials provided with the distribution.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 | * POSSIBILITY OF SUCH DAMAGE.
26 | */
27 |
28 | #define STR_TRACE_USER_TA "HELLO_WORLD"
29 |
30 | #include
31 | #include
32 |
33 | #include "hello_world_ta.h"
34 |
35 | /*
36 | * Called when the instance of the TA is created. This is the first call in
37 | * the TA.
38 | */
39 | TEE_Result TA_CreateEntryPoint(void)
40 | {
41 | DMSG("has been called");
42 | return TEE_SUCCESS;
43 | }
44 |
45 | /*
46 | * Called when the instance of the TA is destroyed if the TA has not
47 | * crashed or panicked. This is the last call in the TA.
48 | */
49 | void TA_DestroyEntryPoint(void)
50 | {
51 | DMSG("has been called");
52 | }
53 |
54 | /*
55 | * Called when a new session is opened to the TA. *sess_ctx can be updated
56 | * with a value to be able to identify this session in subsequent calls to the
57 | * TA. In this function you will normally do the global initialization for the
58 | * TA.
59 | */
60 | TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types,
61 | TEE_Param __maybe_unused params[4],
62 | void __maybe_unused **sess_ctx)
63 | {
64 | uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE,
65 | TEE_PARAM_TYPE_NONE,
66 | TEE_PARAM_TYPE_NONE,
67 | TEE_PARAM_TYPE_NONE);
68 | if (param_types != exp_param_types)
69 | return TEE_ERROR_BAD_PARAMETERS;
70 |
71 | /* Unused parameters */
72 | (void)¶ms;
73 | (void)&sess_ctx;
74 |
75 | /*
76 | * The DMSG() macro is non-standard, TEE Internal API doesn't
77 | * specify any means to logging from a TA.
78 | */
79 | DMSG("Hello World!\n");
80 |
81 | /* If return value != TEE_SUCCESS the session will not be created. */
82 | return TEE_SUCCESS;
83 | }
84 |
85 | /*
86 | * Called when a session is closed, sess_ctx hold the value that was
87 | * assigned by TA_OpenSessionEntryPoint().
88 | */
89 | void TA_CloseSessionEntryPoint(void __maybe_unused *sess_ctx)
90 | {
91 | (void)&sess_ctx; /* Unused parameter */
92 | DMSG("Goodbye!\n");
93 | }
94 |
95 | static TEE_Result inc_value(uint32_t param_types,
96 | TEE_Param params[4])
97 | {
98 | uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT,
99 | TEE_PARAM_TYPE_NONE,
100 | TEE_PARAM_TYPE_NONE,
101 | TEE_PARAM_TYPE_NONE);
102 |
103 | DMSG("has been called");
104 | if (param_types != exp_param_types)
105 | return TEE_ERROR_BAD_PARAMETERS;
106 |
107 | DMSG("Got value: %u from NW", params[0].value.a);
108 | params[0].value.a++;
109 | DMSG("Increase value to: %u", params[0].value.a);
110 | return TEE_SUCCESS;
111 | }
112 |
113 | /*
114 | * Called when a TA is invoked. sess_ctx hold that value that was
115 | * assigned by TA_OpenSessionEntryPoint(). The rest of the paramters
116 | * comes from normal world.
117 | */
118 | TEE_Result TA_InvokeCommandEntryPoint(void __maybe_unused *sess_ctx,
119 | uint32_t cmd_id,
120 | uint32_t param_types, TEE_Param params[4])
121 | {
122 | (void)&sess_ctx; /* Unused parameter */
123 |
124 | switch (cmd_id) {
125 | case TA_HELLO_WORLD_CMD_INC_VALUE:
126 | return inc_value(param_types, params);
127 | #if 0
128 | case TA_HELLO_WORLD_CMD_XXX:
129 | return ...
130 | break;
131 | case TA_HELLO_WORLD_CMD_YYY:
132 | return ...
133 | break;
134 | case TA_HELLO_WORLD_CMD_ZZZ:
135 | return ...
136 | break;
137 | ...
138 | #endif
139 | default:
140 | return TEE_ERROR_BAD_PARAMETERS;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------