Skip to content

Commit 01b6d7c

Browse files
committed
2 parents 60916b7 + a19aeef commit 01b6d7c

19 files changed

+660
-21
lines changed

examples/optee/optee_main.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@
3939
* Pre-processor definitions
4040
****************************************************************************/
4141

42+
#undef USE_ALLOC_IOC
43+
44+
#ifdef USE_ALLOC_IOC
45+
# define tee_shm_alloc tee_shm_mmap
46+
# define tee_shm_free_buf(p, s) munmap(p, s)
47+
#else
48+
# define tee_shm_alloc tee_shm_malloc
49+
# define tee_shm_free_buf(p, s) ((void)s, free(p))
50+
#endif
51+
4252
#define OPTEE_DEV "/dev/tee0"
4353

4454
#define PTA_DEVICE_ENUM { 0x7011a688, 0xddde, 0x4053, \
@@ -183,17 +193,16 @@ static int tee_shm_register(int fd, tee_shm_t *shm)
183193
return -EINVAL;
184194
}
185195

186-
shm->id = (int32_t)(uintptr_t)shm->ptr;
187-
188196
ioc_reg.addr = (uintptr_t)shm->ptr;
189197
ioc_reg.length = shm->size;
190-
ioc_reg.flags = TEE_SHM_REGISTER | TEE_SHM_SEC_REGISTER;
191-
ioc_reg.id = shm->id;
192198

193-
return ioctl(fd, TEE_IOC_SHM_REGISTER, (unsigned long)&ioc_reg);
199+
shm->fd = ioctl(fd, TEE_IOC_SHM_REGISTER, (unsigned long)&ioc_reg);
200+
shm->id = ioc_reg.id;
201+
202+
return shm->fd < 0 ? shm->fd : 0;
194203
}
195204

196-
#if 0 /* Not used */
205+
#ifdef USE_ALLOC_IOC
197206
static int tee_shm_mmap(int fd, tee_shm_t *shm, bool reg)
198207
{
199208
struct tee_ioctl_shm_alloc_data ioc_alloc;
@@ -235,9 +244,9 @@ static int tee_shm_mmap(int fd, tee_shm_t *shm, bool reg)
235244

236245
return ret;
237246
}
238-
#endif
239247

240-
static int tee_shm_alloc(int fd, tee_shm_t *shm, bool reg)
248+
#else /* !USE_ALLOC_IOC */
249+
static int tee_shm_malloc(int fd, tee_shm_t *shm, bool reg)
241250
{
242251
int ret = 0;
243252

@@ -265,6 +274,7 @@ static int tee_shm_alloc(int fd, tee_shm_t *shm, bool reg)
265274

266275
return ret;
267276
}
277+
#endif /* !USE_ALLOC_IOC */
268278

269279
static void tee_shm_free(tee_shm_t *shm)
270280
{
@@ -273,18 +283,11 @@ static void tee_shm_free(tee_shm_t *shm)
273283
return;
274284
}
275285

276-
if (shm->fd > 0)
277-
{
278-
/* Allocated via tee_shm_mmap() */
286+
tee_shm_free_buf(shm->ptr, shm->size);
279287

280-
munmap(shm->ptr, shm->size);
281-
close(shm->fd);
282-
}
283-
else
288+
if (shm->fd >= 0)
284289
{
285-
/* Allocated via tee_shm_alloc() */
286-
287-
free(shm->ptr);
290+
close(shm->fd);
288291
}
289292

290293
shm->ptr = NULL;
@@ -350,6 +353,7 @@ int main(int argc, FAR char *argv[])
350353
}
351354

352355
par0.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT;
356+
par0.c = TEE_MEMREF_NULL;
353357

354358
ret = tee_invoke(fd, session, PTA_CMD_GET_DEVICES, &par0, 1);
355359
if (ret < 0)
@@ -372,7 +376,7 @@ int main(int argc, FAR char *argv[])
372376
par0.attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT;
373377
par0.a = 0;
374378
par0.b = shm.size;
375-
par0.c = (uintptr_t)shm.ptr;
379+
par0.c = shm.id;
376380

377381
ret = tee_invoke(fd, session, PTA_CMD_GET_DEVICES, &par0, 1);
378382
if (ret < 0)

examples/optee_gp/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ##############################################################################
2+
# apps/examples/optee_gp/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_EXAMPLES_OPTEE_GP)
24+
nuttx_add_application(
25+
NAME
26+
${CONFIG_EXAMPLES_OPTEE_GP_PROGNAME}
27+
SRCS
28+
optee_gp_main.c
29+
STACKSIZE
30+
${CONFIG_EXAMPLES_OPTEE_GP_STACKSIZE}
31+
PRIORITY
32+
${CONFIG_EXAMPLES_OPTEE_GP_PRIORITY})
33+
endif()

examples/optee_gp/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config EXAMPLES_OPTEE_GP
7+
tristate "OP-TEE GP API client example"
8+
depends on LIBTEEC
9+
default n
10+
---help---
11+
Enable the OP-TEE GP API client example which uses libteec
12+
13+
if EXAMPLES_OPTEE
14+
15+
config EXAMPLES_OPTEE_GP_PROGNAME
16+
string "Program name"
17+
default "optee_gp"
18+
---help---
19+
This is the name of the program that will be used when the NSH ELF
20+
program is installed.
21+
22+
config EXAMPLES_OPTEE_GP_PRIORITY
23+
int "OP-TEE GP task priority"
24+
default 100
25+
26+
config EXAMPLES_OPTEE_GP_STACKSIZE
27+
int "OP-TEE GP stack size"
28+
default DEFAULT_TASK_STACKSIZE
29+
30+
endif

examples/optee_gp/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/examples/optee_gp/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_EXAMPLES_OPTEE_GP),)
24+
CONFIGURED_APPS += $(APPDIR)/examples/optee_gp
25+
endif

examples/optee_gp/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
############################################################################
2+
# apps/examples/optee_gp/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
# OP-TEE GP API client built-in application info
26+
27+
PROGNAME = $(CONFIG_EXAMPLES_OPTEE_GP_PROGNAME)
28+
PRIORITY = $(CONFIG_EXAMPLES_OPTEE_GP_PRIORITY)
29+
STACKSIZE = $(CONFIG_EXAMPLES_OPTEE_GP_STACKSIZE)
30+
MODULE = $(CONFIG_EXAMPLES_OPTEE_GP)
31+
32+
MAINSRC = optee_gp_main.c
33+
34+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)