Skip to content

Commit f3dc217

Browse files
gpouliosxiaoxiang781216
authored andcommitted
tee/optee_client: Consolidate libteec and optee_supplicant
Merges build file structure so that both libteec and optee_supplicant are under the same nuttx-app directory. This better reflects external source repo structrure (optee_client containing both libteec and tee-supplicant) and avoids a case where build of supplicant was attempted before libteec, leading to a missing .zip file (zip file was only downloaded by libteec, but order of builds was not enforced). Signed-off-by: George Poulios <gpoulios@census-labs.com>
1 parent 099c8ff commit f3dc217

File tree

12 files changed

+175
-345
lines changed

12 files changed

+175
-345
lines changed

tee/libteec/Makefile

Lines changed: 0 additions & 53 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

tee/libteec/CMakeLists.txt renamed to tee/optee_client/CMakeLists.txt

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ if(CONFIG_LIBTEEC)
2626
if(NOT EXISTS ${OPTEE_CLIENT_DIR})
2727
set(OPTEE_CLIENT_URL
2828
https://github.com/OP-TEE/optee_client/archive/refs/tags)
29-
set(OPTEE_CLIENT_VER ${CONFIG_LIBTEEC_VERSION})
29+
set(OPTEE_CLIENT_VER ${CONFIG_OPTEE_CLIENT_VERSION})
3030
FetchContent_Declare(
3131
optee_client_fetch
3232
URL ${OPTEE_CLIENT_URL}/${OPTEE_CLIENT_VER}.zip SOURCE_DIR
3333
${OPTEE_CLIENT_DIR} BINARY_DIR
34-
${CMAKE_BINARY_DIR}/tee/libteec/optee_client
35-
PATCH_COMMAND patch -p1 -d ${OPTEE_CLIENT_DIR} <
36-
${CMAKE_CURRENT_LIST_DIR}/0001-libteec-NuttX.patch
34+
${CMAKE_BINARY_DIR}/tee/optee_client/optee_client
35+
PATCH_COMMAND
36+
patch -p1 -d ${OPTEE_CLIENT_DIR} <
37+
${CMAKE_CURRENT_LIST_DIR}/0001-libteec-NuttX.patch && patch -p1 -d
38+
${OPTEE_CLIENT_DIR} <
39+
${CMAKE_CURRENT_LIST_DIR}/0002-tee-supplicant-port-to-nuttx.patch
3740
DOWNLOAD_NO_PROGRESS true
3841
TIMEOUT 30)
3942

@@ -53,8 +56,7 @@ if(CONFIG_LIBTEEC)
5356

5457
target_sources(libteec PRIVATE optee_client/libteec/src/tee_client_api.c
5558
optee_client/libteec/src/teec_trace.c)
56-
target_include_directories(libteec
57-
PRIVATE ${OPTEE_CLIENT_DIR}/libteec/include)
59+
target_include_directories(libteec PUBLIC ${OPTEE_CLIENT_DIR}/libteec/include)
5860
target_compile_definitions(libteec PUBLIC BINARY_PREFIX=\"TEEC\")
5961

6062
if(CONFIG_DEBUG_INFO)
@@ -68,4 +70,46 @@ if(CONFIG_LIBTEEC)
6870
target_compile_definitions(libteec PUBLIC DEBUGLEVEL=1)
6971
endif()
7072

71-
endif()
73+
if(CONFIG_OPTEE_SUPPLICANT)
74+
75+
# Source files for supplicant
76+
set(SUPPLICANT_SRCS
77+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/tee_supplicant.c
78+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/handle.c
79+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/hmac_sha2.c
80+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/sha2.c
81+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/sd_notify.c
82+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/teec_ta_load.c
83+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/tee_supp_fs.c
84+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/rpmb.c)
85+
86+
set(SUPPLICANT_DEFS
87+
TEEC_LOAD_PATH=\"/bin\" TEE_FS_PARENT_PATH=\"/data/tee\"
88+
DEBUGLEVEL_${CONFIG_OPTEE_SUPPLICANT_LOG_LEVEL})
89+
90+
if(CONFIG_OPTEE_GP_SOCKETS)
91+
list(APPEND SUPPLICANT_SRCS
92+
${OPTEE_CLIENT_DIR}/tee-supplicant/src/tee_socket.c)
93+
list(APPEND SUPPLICANT_DEFS CFG_GP_SOCKETS=1)
94+
endif()
95+
96+
# Add the application
97+
nuttx_add_application(
98+
NAME
99+
${CONFIG_OPTEE_SUPPLICANT_PROGNAME}
100+
SRCS
101+
${SUPPLICANT_SRCS}
102+
INCLUDE_DIRECTORIES
103+
${OPTEE_CLIENT_DIR}/tee-supplicant/src
104+
DEFINITIONS
105+
${SUPPLICANT_DEFS}
106+
STACKSIZE
107+
${CONFIG_OPTEE_SUPPLICANT_STACKSIZE}
108+
PRIORITY
109+
${CONFIG_OPTEE_SUPPLICANT_PRIORITY}
110+
DEPENDS
111+
libteec)
112+
113+
endif() # CONFIG_OPTEE_SUPPLICANT
114+
115+
endif() # CONFIG_LIBTEEC

tee/libteec/Kconfig renamed to tee/optee_client/Kconfig

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
############################################################################
2-
# apps/tee/libteec/Kconfig
2+
# apps/tee/optee_client/Kconfig
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
@@ -38,8 +38,39 @@ config LIBTEEC
3838

3939
if LIBTEEC
4040

41-
config LIBTEEC_VERSION
41+
config OPTEE_CLIENT_VERSION
4242
string "optee_client version (4.6.0)"
4343
default "4.6.0"
4444

4545
endif # LIBTEEC
46+
47+
config OPTEE_SUPPLICANT
48+
bool "OP-TEE supplicant"
49+
depends on LIBTEEC
50+
default n
51+
---help---
52+
Enable OP-TEE supplicant from https://github.com/OP-TEE/optee_client.
53+
54+
if OPTEE_SUPPLICANT
55+
56+
config OPTEE_SUPPLICANT_PROGNAME
57+
string "Program name"
58+
default "optee_supplicant"
59+
---help---
60+
This is the name of the program that will be used when the NSH ELF
61+
program is installed.
62+
63+
config OPTEE_SUPPLICANT_PRIORITY
64+
int "OP-TEE supplicant task priority"
65+
default 100
66+
67+
config OPTEE_SUPPLICANT_STACKSIZE
68+
int "OP-TEE supplicant stack size"
69+
default DEFAULT_TASK_STACKSIZE
70+
71+
config OPTEE_SUPPLICANT_LOG_LEVEL
72+
int "Log level for the supplicant (0‑4)"
73+
range 0 4
74+
default 0
75+
76+
endif # OPTEE_SUPPLICANT

tee/libteec/Make.defs renamed to tee/optee_client/Make.defs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
############################################################################
2-
# apps/tee/libteec/Make.defs
2+
# apps/tee/optee_client/Make.defs
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
# Copyright (C) 2023 Xiaomi Corporation
7-
#
86
# Licensed under the Apache License, Version 2.0 (the "License");
97
# you may not use this file except in compliance with the License.
108
# You may obtain a copy of the License at
@@ -20,9 +18,9 @@
2018
############################################################################
2119

2220
ifneq ($(CONFIG_LIBTEEC),)
23-
CONFIGURED_APPS += $(APPDIR)/tee/libteec
21+
CONFIGURED_APPS += $(APPDIR)/tee/optee_client
2422

25-
FLAGS += ${INCDIR_PREFIX}$(APPDIR)/tee/libteec/optee_client/libteec/include
23+
FLAGS += ${INCDIR_PREFIX}$(APPDIR)/tee/optee_client/optee_client/libteec/include
2624
FLAGS += ${DEFINE_PREFIX}BINARY_PREFIX="\"TEEC\""
2725

2826
ifneq ($(CONFIG_DEBUG_INFO),)
@@ -40,7 +38,4 @@ AFLAGS += $(FLAGS)
4038
CFLAGS += $(FLAGS)
4139
CXXFLAGS += $(FLAGS)
4240

43-
DEPPATH += --dep-path libteec
44-
VPATH += :libteec
45-
4641
endif

tee/optee_client/Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
############################################################################
2+
# apps/tee/optee_client/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
############################################################################
19+
20+
include $(APPDIR)/Make.defs
21+
22+
OPTEE_CLIENT_VERSION = $(patsubst "%",%,$(strip $(CONFIG_OPTEE_CLIENT_VERSION)))
23+
OPTEE_CLIENT_URL ?= "https://github.com/OP-TEE/optee_client/archive/refs/tags"
24+
OPTEE_CLIENT_ZIP = $(OPTEE_CLIENT_VERSION).zip
25+
OPTEE_CLIENT_UNPACKNAME = optee_client
26+
UNPACK ?= unzip -q -o
27+
28+
DEPPATH += --dep-path $(OPTEE_CLIENT_UNPACKNAME)/libteec/src
29+
VPATH += $(OPTEE_CLIENT_UNPACKNAME)/libteec/src
30+
31+
CSRCS += tee_client_api.c
32+
CSRCS += teec_trace.c
33+
34+
ifneq ($(CONFIG_OPTEE_SUPPLICANT),)
35+
DEPPATH += --dep-path $(OPTEE_CLIENT_UNPACKNAME)/tee-supplicant/src
36+
VPATH += $(OPTEE_CLIENT_UNPACKNAME)/tee-supplicant/src
37+
38+
PROGNAME += ${CONFIG_OPTEE_SUPPLICANT_PROGNAME}
39+
PRIORITY += $(CONFIG_OPTEE_SUPPLICANT_PRIORITY)
40+
STACKSIZE += $(CONFIG_OPTEE_SUPPLICANT_STACKSIZE)
41+
MODULE += $(CONFIG_OPTEE_SUPPLICANT)
42+
MAINSRC += tee_supplicant.c
43+
44+
CSRCS += handle.c
45+
CSRCS += hmac_sha2.c
46+
CSRCS += sha2.c
47+
CSRCS += sd_notify.c
48+
CSRCS += teec_ta_load.c
49+
CSRCS += tee_supp_fs.c
50+
CSRCS += rpmb.c
51+
52+
ifeq ($(CONFIG_GP_SOCKETS),1)
53+
CSRCS += tee_socket.c
54+
FLAGS += ${DEFINE_PREFIX}CFG_GP_SOCKETS=1
55+
endif
56+
57+
FLAGS += ${INCDIR_PREFIX}optee_client/tee-supplicant/src
58+
FLAGS += ${DEFINE_PREFIX}TEEC_LOAD_PATH=\"/bin\"
59+
FLAGS += ${DEFINE_PREFIX}TEE_FS_PARENT_PATH=\"/data/tee\"
60+
FLAGS += ${DEFINE_PREFIX}DEBUGLEVEL_$(CONFIG_OPTEE_SUPPLICANT_LOG_LEVEL)
61+
endif
62+
63+
AFLAGS += $(FLAGS)
64+
CFLAGS += $(FLAGS)
65+
CXXFLAGS += $(FLAGS)
66+
67+
$(OPTEE_CLIENT_ZIP):
68+
@echo "Downloading: $(OPTEE_CLIENT_URL)/$(OPTEE_CLIENT_ZIP)"
69+
$(Q) $(call DOWNLOAD,$(OPTEE_CLIENT_URL),$(OPTEE_CLIENT_ZIP))
70+
71+
$(OPTEE_CLIENT_UNPACKNAME): $(OPTEE_CLIENT_ZIP)
72+
@echo "Unpacking: $(OPTEE_CLIENT_ZIP) -> $(OPTEE_CLIENT_UNPACKNAME)"
73+
$(Q) $(UNPACK) $(OPTEE_CLIENT_ZIP)
74+
$(Q) mv $(OPTEE_CLIENT_UNPACKNAME)-$(OPTEE_CLIENT_VERSION) $(OPTEE_CLIENT_UNPACKNAME)
75+
$(Q) echo "Patching $(OPTEE_CLIENT_UNPACKNAME)"
76+
$(Q) patch -p1 -d $(OPTEE_CLIENT_UNPACKNAME) < 0001-libteec-NuttX.patch
77+
$(Q) patch -p1 -d $(OPTEE_CLIENT_UNPACKNAME) < 0002-tee-supplicant-port-to-nuttx.patch
78+
$(Q) touch $(OPTEE_CLIENT_UNPACKNAME)
79+
80+
ifeq ($(wildcard $(OPTEE_CLIENT_UNPACKNAME)/.git),)
81+
context:: $(OPTEE_CLIENT_UNPACKNAME)
82+
83+
distclean::
84+
$(call DELDIR, $(OPTEE_CLIENT_UNPACKNAME))
85+
$(call DELFILE, $(OPTEE_CLIENT_ZIP))
86+
endif
87+
88+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)