optee/ti-optee-client.git
23 months agoCleanup some local variable initialization master ti_optee_client ti2019.01 ti2019.01-rc2 ti2019.01-rc3 ti2019.01-rc4 ti2019.01-rc5 ti2019.02 ti2019.02-rc1 ti2019.02-rc2 ti2019.02-rc3 ti2019.02-rc4 ti2019.03 ti2019.03-rc1 ti2019.03-rc2 ti2019.03-rc3 ti2019.03-rc4 ti2019.04 ti2019.04-rc1 ti2019.04-rc2 ti2019.04-rc3 ti2019.04-rc4 ti2019.04-rc5
Etienne Carriere [Thu, 4 Apr 2019 19:00:25 +0000 (21:00 +0200)]
Cleanup some local variable initialization

This change removes few useless memset() and replace few memset() with
an initialized structure where possible.

This change fixes some TEEC_Result variables initialization
using a valid enumerated ID.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Joakim Bech <joakim.bech@linaro.org>
2 years agolibteec: fix clang build errors
Victor Chong [Fri, 22 Mar 2019 06:37:13 +0000 (06:37 +0000)]
libteec: fix clang build errors

external/optee_client/libteec/src/tee_client_api.c:488:11: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
                uint8_t data[sizeof(struct tee_ioctl_open_session_arg) + p_sz];
                        ^
external/optee_client/libteec/src/tee_client_api.c:566:11: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
                uint8_t data[sizeof(struct tee_ioctl_invoke_arg) + p_sz];
                        ^

Fixes: 9dbc61b3 ("libteec: fix build warnings")
Fixes: https://github.com/OP-TEE/optee_client/issues/152

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoExplicitly initialize local variables
Etienne Carriere [Thu, 21 Mar 2019 08:43:35 +0000 (09:43 +0100)]
Explicitly initialize local variables

This change initializes all local variables to prevent build issues
(warnings and/or errors) in OP-TEE client package.

Use memset() to initialize structured and typed variables. This change
changes ordering in the local variable definition block at function
head. Structured variables are defined below, right above the memset()
call block for their initialization, when possible.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agolibteec: fix build warnings
Etienne Carriere [Wed, 20 Mar 2019 09:01:23 +0000 (10:01 +0100)]
libteec: fix build warnings

Fix build warnings reported by the Buildroot team [1]:

/home/thomas/projets/outputs/armv5-ctng-linux-gnueabi/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function 'TEEC_InitializeContext':
/home/thomas/projets/outputs/armv5-ctng-linux-gnueabi/build/optee-client-3.4.0/libteec/src/tee_client_api.c:149:28: error: 'gen_caps' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    ctx->reg_mem = gen_caps & TEE_GEN_CAP_REG_MEM;
                            ^
/home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function ‘TEEC_OpenSession’:
/home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c:507:8: error: cast increases required alignment of target type [-Werror=cast-align]
  arg = (struct tee_ioctl_open_session_arg *)buf;
        ^
/home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function ‘TEEC_InvokeCommand’:
/home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c:581:8: error: cast increases required alignment of target type [-Werror=cast-align]
  arg = (struct tee_ioctl_invoke_arg *)buf;
        ^

[1] http://lists.busybox.net/pipermail/buildroot/2019-February/243437.html

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960 32, 64)
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agocmake: support BUILD_STATIC_LIBS/BUILD_SHARED_LIBS
Etienne Carriere [Wed, 6 Mar 2019 10:46:07 +0000 (11:46 +0100)]
cmake: support BUILD_STATIC_LIBS/BUILD_SHARED_LIBS

CMake variables BUILD_STATIC_LIBS and BUILD_SHARED_LIBS
set constraints on libraries and executable linkage.

With this change OP-TEE client CMake script builds and installs the
embedded files with the expected linkage configuration.

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
2 years agodocs: Remove current docs and link to the new location
Joakim Bech [Fri, 22 Feb 2019 09:49:06 +0000 (10:49 +0100)]
docs: Remove current docs and link to the new location

All current documentation has been transferred to a new git called
optee_docs [1]. The output from optee_docs will be rendered using Sphinx
and hosted at optee.readthedocs.io [2]. The new documentation git will
also be part of the regular OP-TEE releases. For completeness, it will
also be included in our manifests making up a full OP-TEE developer
setup.

[1] https://github.com/OP-TEE/optee_docs
[2] https://optee.readthedocs.io

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
2 years agoMakefile: default install client libs and headers in /usr
Etienne Carriere [Thu, 7 Feb 2019 09:44:28 +0000 (10:44 +0100)]
Makefile: default install client libs and headers in /usr

Change default install path for the libraries and their header files
to locate them in /usr/lib and /usr/include which are more generic
than /lib and /include as used prior this change.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoMakefile: install tee-supplicant in /usr/sbin by default
Etienne Carriere [Thu, 7 Feb 2019 09:43:36 +0000 (10:43 +0100)]
Makefile: install tee-supplicant in /usr/sbin by default

Change GNU makefile to default install tee-supplicant in target
directory /usr/sbin instead of /bin. This change aligns the GNU
makefile install sequence with the CMake install sequence.

Build environment can override embedded sbin path from environment
variable SBINDIR whereas prior this change tee-supplicant install
directory path was defined from BINDIR.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoflags: add -D_FILE_OFFSET_BITS=64 to support large files ti2019.00 ti2019.00-rc1 ti2019.00-rc2 ti2019.00-rc3 ti2019.00-rc4 ti2019.00-rc5 ti2019.01-rc1
Rouven Czerwinski [Tue, 22 Jan 2019 14:19:57 +0000 (15:19 +0100)]
flags: add -D_FILE_OFFSET_BITS=64 to support large files

The tee client library does not need to provide compatibility for the old file
system interface.

The sources in [0] and [1] explain that _FILE_OFFSET_BITS=64 support has been
added to the Android NDK only recently, adding the flags now could break existing
applications. Thus _FILE_OFFSET_BITS=64 is left out for the android make flags.

[0]: https://android-developers.googleblog.com/2017/09/introducing-android-native-development.html
[1]: https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md

Fixes: https://github.com/OP-TEE/optee_client/issues/140
Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
[jf: use URL in Fixes: tag]
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
2 years agolibteec: Makefile: Generate .so files the same way as CMake
Fabian Hofmann [Sun, 21 Oct 2018 16:42:19 +0000 (18:42 +0200)]
libteec: Makefile: Generate .so files the same way as CMake

Update the Makefile so that the generated libteec.so file and the
corresponding symlinks match those generated by the CMake script.

Specifically, before this commit the Makefile generated the following
files:
  symlink: libteec.so -> libteec.so.1
  symlink: libteec.so.1 -> libteec.so.1.0
  file: libteec.so.1.0 (SONAME libteec.so.1.0)

With this commit the generated files are:
  symlink: libteec.so -> libteec.so.1
  symlink: libteec.so.1 -> libteec.so.1.0.0
  symlink: libteec.so.1.0 -> libteec.so.1.0.0
  file: libteec.so.1.0.0 (SONAME libteec.so.1)

The symlink "libteec.so.1.0" is kept for compatibility with existing
installations. Note that "libteec.so.1.0" is not generated by the CMake
script.

Signed-off-by: Fabian Hofmann <fabian.hofmann@fau.de>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
2 years agotee_supplicant: gprof: fix compile error
Jerome Forissier [Thu, 15 Nov 2018 16:06:42 +0000 (17:06 +0100)]
tee_supplicant: gprof: fix compile error

Avoids a compile error with using GCC 8.x with CFG_TA_GPROF_SUPPORT=y:

 src/gprof.c: In function ‘gprof_process’:
 src/gprof.c:97:35: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 4 [-Werror=format-truncation=]
     snprintf(vers, sizeof(vers), ".%d", id - 1);
                                    ^~
 src/gprof.c:97:33: note: directive argument in the range [1, 2147483646]
     snprintf(vers, sizeof(vers), ".%d", id - 1);
                                  ^~~~~
 src/gprof.c:97:4: note: ‘snprintf’ output between 3 and 12 bytes into a destination of size 5
     snprintf(vers, sizeof(vers), ".%d", id - 1);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 cc1: all warnings being treated as errors

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2 years agotee-supplicant: cmake: enable RPMB emulation by default
Jens Wiklander [Fri, 7 Sep 2018 13:08:30 +0000 (15:08 +0200)]
tee-supplicant: cmake: enable RPMB emulation by default

Enables RPMB emulation by default also when compiling with cmake.

Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoMakefile and config.mk: remove export in config.mk
Yongqin Liu [Fri, 17 Aug 2018 04:19:38 +0000 (12:19 +0800)]
Makefile and config.mk: remove export in config.mk

to workaorund export restriction when building for android platform
because of the deprecation described here:
https://android.googlesource.com/platform/build/+/master/Changes.md#export_keyword

with export used in make files, the aosp build will report error like here:
https://ci.linaro.org/job/android-lcr-reference-hikey-master/95/console

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU)
Tested-by: Yongqin Liu <yongqin.liu@linaro.org> (AOSP master)
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2 years agotee-supplicant: add daemon mode (-d)
Jerome Forissier [Fri, 17 Aug 2018 09:34:19 +0000 (11:34 +0200)]
tee-supplicant: add daemon mode (-d)

Add the missing code to make tee-supplicant a proper daemon when invoked
with -d.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoDo not set -Werror by default
Jerome Forissier [Fri, 6 Jul 2018 08:32:53 +0000 (10:32 +0200)]
Do not set -Werror by default

Do not use -Werror unless explicitly asked via "make CFG_WERROR=y".

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
2 years agotee-supplicant: rpmb.c: add __attribute__((fallthrough))
Jerome Forissier [Thu, 5 Jul 2018 15:13:15 +0000 (17:13 +0200)]
tee-supplicant: rpmb.c: add __attribute__((fallthrough))

Fix the following error reported by GCC 8.1:

src/rpmb.c: In function ‘rpmb_data_req’:
src/rpmb.c:683:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
   if (rsp_nfrm != 1) {
      ^
src/rpmb.c:689:2: note: here
  case RPMB_MSG_TYPE_REQ_AUTH_DATA_READ:
  ^~~~

I could not silence this warning using any of the special comments
documented on the GCC Warning Options page [1]. It is weird, because we
use -Wextra which is supposed to enable -Wimplicit-fallthrough=3, which is
supposed to recognize the comment we had already (/* Fall through */).

Link: [1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
2 years agolibteec: refactor _dprintf()
Jerome Forissier [Thu, 5 Jul 2018 13:15:31 +0000 (15:15 +0200)]
libteec: refactor _dprintf()

GCC8.1 gives an error when compiling _dprintf():

src/teec_trace.c: In function ‘_dprintf’:
src/teec_trace.c:110:5: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 246 [-Werror=format-truncation=]
     "%s [%d] %s:%s:%d: %s",
     ^~~~~~~~~~~~~~~~~~~~~~
src/teec_trace.c:112:11:
     line, raw);
           ~~~
src/teec_trace.c:109:3: note: ‘snprintf’ output 11 or more bytes (assuming 266) into a destination of size 256
   snprintf(prefixed, MAX_PRINT_SIZE,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     "%s [%d] %s:%s:%d: %s",
     ~~~~~~~~~~~~~~~~~~~~~~~
     trace_level_strings[level], thread_id, prefix, func,
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     line, raw);
     ~~~~~~~~~~

Fix this error by using a single output buffer, printing the prefix first
then the other arguments with the supplied format.

In addition, further simplify the function by getting rid of things that
do not make much sense:
- Remove the 'flen' parameter, which is only ever set to zero or
  strlen(__func__).
- Remove the TRACE_FUNC_LENGTH_CST macro which is not set by default and
  does not seem very useful.
- Change the return type to void because callers do not care about success
  or failure.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
2 years agobenchmark: fix computation of page address
Jerome Forissier [Mon, 6 Aug 2018 13:18:59 +0000 (15:18 +0200)]
benchmark: fix computation of page address

Subtracting the size *in bytes* from a (intptr_t *) is incorrect, since it
will subtract n * sizeof(intptr_t).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agoAndroid related files: changes to work with Treble enabled build
Yongqin Liu [Thu, 21 Jun 2018 14:21:09 +0000 (22:21 +0800)]
Android related files: changes to work with Treble enabled build

1. change to make libteec and tee-supplicant installed in the vendor partition
2. use /data/vendor/tee instead of /data/tee as the workspace for tee
3. local ta files from /vendor/lib

Acked-by: Victor Chong <victor.chong@linaro.org>
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2 years agoAndroid.mk & config.mk: move teec.log/teesupp.log under /data/tee
Yongqin Liu [Thu, 29 Mar 2018 08:00:11 +0000 (16:00 +0800)]
Android.mk & config.mk: move teec.log/teesupp.log under /data/tee

for Android platform, otherwise there will be SELinux problem
reported

Acked-by: Victor Chong <victor.chong@linaro.org>
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
2 years agobenchmark: fix compilation issues ti2018.03-rc3 ti2018.05 ti2018.05-rc1 ti2018.05-rc2 ti2018.05-rc3 ti2018.05-rc4 ti2018.05-rc5
Igor Opaniuk [Wed, 27 Jun 2018 11:35:04 +0000 (14:35 +0300)]
benchmark: fix compilation issues

This fixes "cast from pointer to integer of different" warning, when
CFG_TEE_BENCHMARK is enabled.

src/teec_benchmark.c: In function 'mmap_paddr':
src/teec_benchmark.c:128:11: error: cast from pointer to integer of different
size [-Werror=pointer-to-int-cast]
  offset = (off_t)hw_addr % getpagesize();
           ^
src/teec_benchmark.c:129:14: error: cast from pointer to integer of different
size [-Werror=pointer-to-int-cast]
  page_addr = (off_t)(hw_addr - offset);

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
2 years agoDo not export CMakeLists.txt when running install 3.2.0 3.2.0-rc1
Joakim Bech [Wed, 30 May 2018 10:20:54 +0000 (12:20 +0200)]
Do not export CMakeLists.txt when running install

Fixes: https://github.com/OP-TEE/optee_client/issues/122
Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Tested-by: Joakim Bech <joakim.bech@linaro.org>
Suggested-by: Tomáš Chvátal <tomas.chvatal@gmail.com>
Reported-by: Tomáš Chvátal <tomas.chvatal@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2 years agolibteec: Fix incorrect SOVERSION number
Joakim Bech [Tue, 29 May 2018 12:12:26 +0000 (14:12 +0200)]
libteec: Fix incorrect SOVERSION number

Fixes: https://github.com/OP-TEE/optee_client/issues/123
Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Tested-by: Joakim Bech <joakim.bech@linaro.org>
Suggested-by: Tomáš Chvátal <tomas.chvatal@gmail.com>
Reported-by: Tomáš Chvátal <tomas.chvatal@gmail.com>
3 years agotee-supplicant: cast sizeof(x) to socklen_t 3.1.0 3.1.0-rc1
Jerome Forissier [Thu, 15 Feb 2018 07:21:42 +0000 (08:21 +0100)]
tee-supplicant: cast sizeof(x) to socklen_t

Fixes compilation warnings on Android:

 optee_client/tee-supplicant/src/tee_socket.c:551:12: error: comparison of integers of different signs: 'socklen_t' (aka 'int') and 'unsigned int' [-Werror,-Wsign-compare]
                 if (slen < sizeof(*sain))
                     ~~~~ ^ ~~~~~~~~~~~~~
 optee_client/tee-supplicant/src/tee_socket.c:561:12: error: comparison of integers of different signs: 'socklen_t' (aka 'int') and 'unsigned int' [-Werror,-Wsign-compare]
                 if (slen < sizeof(*sain6))
                     ~~~~ ^ ~~~~~~~~~~~~~~
 optee_client/tee-supplicant/src/tee_socket.c:577:12: error: comparison of integers of different signs: 'socklen_t' (aka 'int') and 'unsigned int' [-Werror,-Wsign-compare]
                 if (slen < sizeof(*sain))
                     ~~~~ ^ ~~~~~~~~~~~~~
 optee_client/tee-supplicant/src/tee_socket.c:587:12: error: comparison of integers of different signs: 'socklen_t' (aka 'int') and 'unsigned int' [-Werror,-Wsign-compare]
                 if (slen < sizeof(*sain6))
                     ~~~~ ^ ~~~~~~~~~~~~~~

socklen_t may be signed or unsigned, depending on which standard is
implemented. For instance, the Single UNIX Specification V2 [1] defines
it as unsigned, while the more recent Open Group Base Specifications
Issue 7 [2] does not mention signedness.

Therefore, cast sizeof(x) to socklen_t to avoid any sign mismatch.

Link: [1] http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html
Link: [2] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reported-by: Angela Stegmaier <angelabaker@ti.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agotee-supplicant: fix gcc warning
Jens Wiklander [Mon, 18 Dec 2017 23:43:12 +0000 (00:43 +0100)]
tee-supplicant: fix gcc warning

Fixes gcc warning:
src/tee_socket.c: In function 'poll_with_timeout.constprop':
src/tee_socket.c:361:28: error: 'until.tv_nsec' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  diff.tv_nsec = a->tv_nsec - b->tv_nsec;
                 ~~~~~~~~~~~^~~~~~~~~~~~
src/tee_socket.c:382:18: note: 'until.tv_nsec' was declared here
  struct timespec until;
                  ^~~~~
src/tee_socket.c:360:26: error: 'until.tv_sec' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  diff.tv_sec = a->tv_sec - b->tv_sec;
                ~~~~~~~~~~^~~~~~~~~~~
src/tee_socket.c:382:18: note: 'until.tv_sec' was declared here
  struct timespec until;
                  ^~~~~
cc1: all warnings being treated as errors

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agocmake: Initial CMake support
Joakim Bech [Tue, 19 Apr 2016 11:25:08 +0000 (13:25 +0200)]
cmake: Initial CMake support

This introduces support for building optee_client (libteec,
tee-supplicant and the public header files) using CMake.

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agotee-supplicant: fix use of mem after it's freed
Igor Opaniuk [Sat, 27 Jan 2018 15:15:35 +0000 (17:15 +0200)]
tee-supplicant: fix use of mem after it's freed

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
3 years agolibteec/tee-supplicant: respect LDFLAGS set from distribution toolchain 3.0.0 3.0.0-rc1 ti2018.00 ti2018.00-rc1 ti2018.00-rc2 ti2018.00-rc3 ti2018.00-rc4 ti2018.00-rc5 ti2018.01 ti2018.01-rc1 ti2018.01-rc2 ti2018.01-rc3 ti2018.01-rc4 ti2018.02-rc1 ti2018.02-rc2 ti2018.02-rc3
Martin Jansa [Fri, 16 Jun 2017 00:20:35 +0000 (17:20 -0700)]
libteec/tee-supplicant: respect LDFLAGS set from distribution toolchain

Unify LFLAGS/LDFLAGS variable.

For example, on OpenEmbedded, it fixes the following QA error:
QA Issue:
No GNU_HASH in the elf binary: optee-client/usr/bin/tee-supplicant'
No GNU_HASH in the elf binary: optee-client/usr/lib/libteec.so.1.0' [ldflags]

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agolibteec/Makefile: generate static library (libteec.a)
Jerome Forissier [Mon, 13 Nov 2017 08:32:07 +0000 (09:32 +0100)]
libteec/Makefile: generate static library (libteec.a)

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
3 years agotee-supplicant: REE fs open file with O_SYNC flag 2.6.0 2.6.0-rc1 ti2017.05 ti2017.05-rc4 ti2017.06 ti2017.06-rc1 ti2017.06-rc2 ti2017.06-rc3 ti2017.06-rc4
l00176142 [Mon, 16 Oct 2017 09:05:45 +0000 (17:05 +0800)]
tee-supplicant: REE fs open file with O_SYNC flag

CFG_RPMB_FS=y and RPMB_EMU=0(use EMMC RPMB device). Power down when
writing file without the O_SYNC flag, dirf.db was cached by kernel,
some very old (more than two generations) version was in the file
system. If dirf.db and dirfile.db.hash (residing in RPMB) differ by
two versions, it will cause TEE_ERROR_SECURITY, and the file data
will lost.

Add O_SYNC flag in open file to fix this issue.
(fixed by Jens Wiklander)

Signed-off-by: Jianhui Li <airbak.li@hisilicon.com>
Tested-by: Jianhui Li <airbak.li@hisilicon.com> (Hisilicon)
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agotee_supplicant: add register memory feature
Volodymyr Babchuk [Mon, 6 Mar 2017 19:58:03 +0000 (21:58 +0200)]
tee_supplicant: add register memory feature

If OP-TEE and kernel support registereted shared memory,
then supplicant will use this feature instead of using
shared memory pool.

Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
3 years agotee_client_api: register user memory
Jens Wiklander [Fri, 21 Oct 2016 07:23:24 +0000 (09:23 +0200)]
tee_client_api: register user memory

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Igor Opaniuk <igor.opaniuk@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agotee-supplicant: move TEEC_LOAD_PATH to Makefile ti2017.05-rc1 ti2017.05-rc2 ti2017.05-rc3
l00176142 [Mon, 28 Aug 2017 11:37:09 +0000 (19:37 +0800)]
tee-supplicant: move TEEC_LOAD_PATH to Makefile

TEEC_LOAD_PATH default value is "/lib", it could be changed by
CFG_TEE_CLIENT_LOAD_PATH in tee_supplicant_android.mk.
As "/lib" could not meet all the scenes, it should be able to be
changed in Makefile for Linux.

* Add -DTEEC_LOAD_PATH in Makefile
* Remove the #ifndef TEEC_LOAD_PATH block in teec_ta_load.c
* Set CFG_TEE_CLIENT_LOAD_PATH ?= /lib in config.mk
  (instead of /system/lib)
* In Android.mk, set CFG_TEE_CLIENT_LOAD_PATH ?= /system/lib
  before config.mk is included

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU)
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Yongqin Liu yongqin.liu@linaro.org
Tested-by: Yongqin Liu yongqin.liu@linaro.org (Hikey with AOSP master)
Signed-off-by: Jianhui Li <airbak.li@hisilicon.com>
3 years agotee_client_api: support calling libteec from cplusplus
Zeng Tao [Mon, 28 Aug 2017 08:55:25 +0000 (16:55 +0800)]
tee_client_api: support calling libteec from cplusplus

The tee client api has got no restriction for cplusplus program,
simplely add extern "c" in this patch to support this feature.

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Zeng Tao <prime.zeng@hisilicon.com>
3 years agorpi3: fix unsupported exclusive access issue
Igor Opaniuk [Fri, 14 Jul 2017 14:09:33 +0000 (17:09 +0300)]
rpi3: fix unsupported exclusive access issue

Fix unsupported exclusive issue , which occurs when using gcc builtin
atomic
__sync_fetch_and_add();, which is unfolded into LDXR/STLXR pair
(aarch64).

Currently, __sync_fetch_and_add() is used in bm_timestamp() for updating
head/tail
of timestamp per-cpu ringbuffers.

Fixes: https://github.com/OP-TEE/optee_client/issues/99
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
3 years agolibteec/Makefile: create relative links to shared library instead of absolute ones 2.5.0 2.5.0-rc2 ti2017.03 ti2017.03-rc1 ti2017.03-rc2 ti2017.03-rc3 ti2017.03-rc4 ti2017.04 ti2017.04-rc1 ti2017.04-rc2 ti2017.04-rc3 ti2017.04-rc4
Marc Kleine-Budde [Mon, 12 Jun 2017 15:55:32 +0000 (17:55 +0200)]
libteec/Makefile: create relative links to shared library instead of absolute ones

Absolute paths in link targets are ugly and there is always a risk that
they may be packaged incorrectly. Further the *.so* files are always
expected to reside in the same directory. This patch fixes this problem.

Suggested-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agoMakefile: preserve links to libraries during make copy_export
Marc Kleine-Budde [Mon, 12 Jun 2017 14:54:50 +0000 (16:54 +0200)]
Makefile: preserve links to libraries during make copy_export

During "make copy_export" and "make install" the shared library is
copied into the LIBDIR. However "cp" is used, thus the links to the
shared library are not preserved. This patch fixes the problem by using
"cp -a" instead.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agolibteec: benchmark cleanup 2.5.0-rc1
Jerome Forissier [Thu, 1 Jun 2017 12:53:52 +0000 (14:53 +0200)]
libteec: benchmark cleanup

Some cleanup which should also fix a build error on Android:

external/optee_client/libteec/src/tee_client_api.c:556: error: undefined reference to 'bm_timestamp'
external/optee_client/libteec/src/tee_client_api.c:592: error: undefined reference to 'bm_timestamp'
clang.real: error: linker command failed with exit code 1 (use -v to see invocation)

- Move include/linux/teec_benchmark.h up one level, because this file
is not related to the Linux TEE driver
- Make bm_timestamp() a no-op static inline if CFG_TEE_BENCHMARK != y
- Remove conditional compilation in teec_benchmark.c, instead, add the
file to the build only when CFG_TEE_BENCHMARK = y
- Declare benchmark_check_mode() static in teec_benchmark.c, since it
is not used anywhere else

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Igor Opaniuk <igor.opaniuk@linaro.org>
3 years agotee-supplicant: Report error on short buffer when loading TA
Yves Lefloch [Wed, 22 Mar 2017 16:14:07 +0000 (17:14 +0100)]
tee-supplicant: Report error on short buffer when loading TA

Signed-off-by: Yves Lefloch <YvesMarie_Lefloch@sigmadesigns.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agoFix incorrect share memory size
James Kung [Tue, 16 May 2017 07:27:01 +0000 (15:27 +0800)]
Fix incorrect share memory size

Accroding to TEE Client API Spec section 4.3.8 TEEC_RegisteredMemoryReference,
when handling a TEEC_RegisteredMemoryReference parameter of TEEC_MEMREF_WHOLE
type, the memory region size should read from its parent TEEC_SharedMemory
structure instead of the size described in TEEC_RegisteredMemoryReference
structure.

Signed-off-by: James Kung <kong1191@gmail.com>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (QEMUs, GP)
3 years agoStorage: Added CFG_TEE_FS_PARENT_PATH config option
Ruslan Piasetskyi [Thu, 1 Jun 2017 06:36:21 +0000 (09:36 +0300)]
Storage: Added CFG_TEE_FS_PARENT_PATH config option

tee-supplicant needs to create folder which will contain secure files.
In case folder can not be created, tee-supplicant exits.

Sometimes developers have to change this location to another.
For example, Android OS can not use /data folder, because tee-supplicant
is needed for decrypt userdata.img (which is mounted in /data folder).

* Add CFG_TEE_FS_PARENT_PATH config option
* Cleanup secure storage init logic

Signed-off-by: Ruslan Piasetskyi <ruslan.piasetskyi@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
[jf: fix typo in commit message]
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agoReplace file permission symbolic values by octal numbers
Jerome Forissier [Tue, 23 May 2017 06:38:07 +0000 (08:38 +0200)]
Replace file permission symbolic values by octal numbers

Octal numbers are prefered over symbolic values for file access modes.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agoOP-TEE Benchmark
Igor Opaniuk [Wed, 9 Nov 2016 14:06:09 +0000 (14:06 +0000)]
OP-TEE Benchmark

OP-TEE Benchmark feature provides timestamp data for the roundtrip time
from libteec to OP-TEE OS core.

Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
3 years agotee-supplicant: FS: remove unused legacy RPC functions
Jerome Forissier [Tue, 30 May 2017 08:17:16 +0000 (10:17 +0200)]
tee-supplicant: FS: remove unused legacy RPC functions

Since commit 129360332591 ("core: FS: remove unused legacy RPC
functions"), OP-TEE OS does not use a number of filesystem-related
commands anymore. Remove them from tee-supplicant.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agoRemove leftovers of SQL FS
Jerome Forissier [Tue, 30 May 2017 08:22:48 +0000 (10:22 +0200)]
Remove leftovers of SQL FS

Fixes: 403c9a175794 ("Remove SQL-FS")
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agosupplicant: use public rpc command ids
Etienne Carriere [Tue, 23 May 2017 09:26:13 +0000 (11:26 +0200)]
supplicant: use public rpc command ids

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agosupplicant: define/describe reserved Ids for supplicant commands
Etienne Carriere [Tue, 23 May 2017 09:25:55 +0000 (11:25 +0200)]
supplicant: define/describe reserved Ids for supplicant commands

Add missing macros OPTEE_MSG_RPC_CMD_SHM_ALLOC/_SHM_FREE/_GPROF.
Move OPTEE_MSG_RPC_CMD_SQL_FS_RESERVED to a better place.
Remove deprecated reference to optee_msg.h.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
3 years agoclient api: fix ULONG_MAX dependency
Etienne Carriere [Mon, 22 May 2017 12:53:48 +0000 (14:53 +0200)]
client api: fix ULONG_MAX dependency

ULONG_MAX depends on limits.h.

Fixes: 9faeb1b6b023 ("tee_client_api: Correct max shared memory size define")
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agotee_client_api: Correct max shared memory size define
Lukasz Kostyra [Tue, 16 May 2017 09:37:05 +0000 (11:37 +0200)]
tee_client_api: Correct max shared memory size define

Signed-off-by: Lukasz Kostyra <l.kostyra@samsung.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agotee-supplicant: correct block device path for android
Zhizhou Zhang [Thu, 9 Mar 2017 10:49:27 +0000 (18:49 +0800)]
tee-supplicant: correct block device path for android

ueventd create block devices under /dev/block/.

Signed-off-by: Zhizhou Zhang <zhizhouzhang@asrmicro.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
3 years agoRemove SQL-FS
Jens Wiklander [Wed, 19 Apr 2017 11:38:26 +0000 (13:38 +0200)]
Remove SQL-FS

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoAndroid.mk: fix CFG_TEE_CLIENT_LOG_FILE checking ti2017.01 ti2017.01-rc1 ti2017.01-rc2 ti2017.01-rc3 ti2017.01-rc4 ti2017.02 ti2017.02-rc1 ti2017.02-rc2 ti2017.02-rc3 ti2017.02-rc4 ti2017.02-rc5 ti2017.02-rc6
Ruslan Piasetskyi [Thu, 23 Mar 2017 18:56:09 +0000 (20:56 +0200)]
Android.mk: fix CFG_TEE_CLIENT_LOG_FILE checking

CFG_TEE_CLIENT_LOG_FILE variable contains the client library log file
path. The correct way to check if the variable is not empty is using
ifneq operator.

Signed-off-by: Ruslan Piasetskyi <ruslan.piasetskyi@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoree_fs_new_opendir(): ignore empty directory 2.4.0
Jerome Forissier [Thu, 23 Mar 2017 10:30:08 +0000 (11:30 +0100)]
ree_fs_new_opendir(): ignore empty directory

The behavior of ree_fs_new_opendir() should be the same when a TA
directory does not exist, or when it is empty: return
TEEC_ERROR_ITEM_NOT_FOUND in both cases.

Currently, ree_fs_new_opendir() returns TEE_SUCCESS when the TA
directory exists.  This causes an issue with REE FS, when the data
directory is mounted over NFS. "xtest 6009 6010" fails with
TEE_StartPersistentObjectEnumerator() returning TEE_SUCCESS instead of
TEE_ERROR_ITEM_NOT_FOUND.

This is because test 6009 does not properly clean up. The test creates
persistent objects, closes them, opens them again with the meta accesss
flag and deletes them by calling TEE_CloseAndDeletePersistentObject1().
It turns out that tee-supplicant *does* attempt to remove the directory
but receives error ENOTEMPTY when the filesystem is NFS-mounted. The
reason is that when it removes the file, as a consequence of
syscall_storage_obj_del() calling o->pobj->fops->remove(o->pobj),
tee-supplicant still has an open file descriptor to the object. This
causes the NFS server to keep a hidden file (.nfsXXX) in the directory,
causing the subsequent rmdir() to fail. Then, when
syscall_storage_obj_del() calls tee_obj_close(), the fd is closed and
the .nfsXXX file disappears. We're left with an empty TA directory, and
when TEE_StartPersistentObjectEnumerator() invokes ree_fs_new_opendir()
it ends up with TEE_SUCCESS instead of TEE_ERROR_ITEM_NOT_FOUND.

One option to fix the issue is to fix the directory cleanup sequence,
i.e., make sure that the file descriptor is closed before the file is
unlinked and the directory removed. But we choose to adjust
ree_fs_new_opendir() instead, because it is less intrusive in OP-TEE OS
and also because the secure storage code is being reworked anyway for
other reasons.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee_supplicant_android.mk: Add missing configs for sockets ti2017.00 ti2017.00-c4 ti2017.00-rc3 ti2017.00-rc4 ti2017.00-rc5 ti2017.00-rc6
Victor Chong [Wed, 1 Mar 2017 04:58:34 +0000 (04:58 +0000)]
tee_supplicant_android.mk: Add missing configs for sockets

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
4 years agotee-supplicant: fix variable is used unitialized error
Victor Chong [Wed, 1 Mar 2017 04:52:06 +0000 (04:52 +0000)]
tee-supplicant: fix variable is used unitialized error

Fixes build error below:
tee_socket.c:393:7: error: variable 'to' is used uninitialized whenever
'if' condition is false [-Werror,-Wsometimes-uninitialized]

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
4 years agoUse the mode also in open_wrapper
Joakim Bech [Wed, 1 Mar 2017 11:21:34 +0000 (12:21 +0100)]
Use the mode also in open_wrapper

When source code is built with FORTIFY, it will give an error if you're
doing an open syscall without specifing the mode parameter.

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: Add support for TCP/UDP iSocket interface
Jens Wiklander [Tue, 13 Dec 2016 19:47:01 +0000 (20:47 +0100)]
tee-supplicant: Add support for TCP/UDP iSocket interface

Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (b2260)
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: spawn threads as needed
Jens Wiklander [Tue, 13 Dec 2016 10:20:31 +0000 (11:20 +0100)]
tee-supplicant: spawn threads as needed

* Spawns threads as needed, but only if the kernel supports asynchronous
  supplicant requests.
* Adds mutex protecting RPMB
* Adds mutex protecting SQL_FS

Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: support asynchronous supplicant requests
Jens Wiklander [Mon, 12 Dec 2016 11:38:28 +0000 (12:38 +0100)]
tee-supplicant: support asynchronous supplicant requests

Adds support for asynchronous supplicant requests, meaning that the
supplicant can process several requests in parallel or block in a
request for some time. This is not yet taken advantage of.

Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: Update TEEC_TEST_LOAD_PATH for Android ti2017.00-rc1 ti2017.00-rc2
Victor Chong [Fri, 3 Feb 2017 12:35:25 +0000 (12:35 +0000)]
tee-supplicant: Update TEEC_TEST_LOAD_PATH for Android

Match TA_TEST_DIR in optee_test/blob/master/host/xtest/xtest_1000.c

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
4 years agoree fs rpc: open with best-effort allowing RO data fs
Andy Green [Tue, 31 Jan 2017 01:35:52 +0000 (09:35 +0800)]
ree fs rpc: open with best-effort allowing RO data fs

The REE handler for open always uses flags O_RDWR at the moment.

This breaks the possibility to use read-only operations on a
read-only mounted filesystem at /data.

Change it to try to open with O_RDWR, if not possible fall back
to O_RDONLY and only fail if that isn't workable either.

If O_RDONLY isn't enough, then the TA should use another means
to get the fs mounted rw for the duration of his write activity.
He will get failures on the write action if not, but that is
fair enough.

Signed-off-by: Andy Green <andy@warmcat.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
4 years agoAdd support for TA profiling (gprof)
Jerome Forissier [Fri, 21 Oct 2016 14:07:32 +0000 (16:07 +0200)]
Add support for TA profiling (gprof)

Enable with: CFG_TA_GPROF_SUPPORT=y.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoRename optee_msg_fs.h to optee_msg_supplicant.h
Jerome Forissier [Wed, 26 Oct 2016 11:45:45 +0000 (13:45 +0200)]
Rename optee_msg_fs.h to optee_msg_supplicant.h

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: disable warnings only for sql_fs.c
Jerome Forissier [Mon, 23 Jan 2017 14:52:17 +0000 (15:52 +0100)]
tee-supplicant: disable warnings only for sql_fs.c

sql_fs.c includes an API header (sqlfs.h in libsqlfs) which generates
warnings when built with our default flags. Silence them only for this
particular file, so that we won't miss potential issues in new code.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoAdd backward compatibility with older TA UUID format 2.3.0
Jerome Forissier [Wed, 4 Jan 2017 10:39:14 +0000 (11:39 +0100)]
Add backward compatibility with older TA UUID format

Fixes: ce5fefe6cba ("Format UUID strings correctly")
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoAllow O to be an absolute path
Jerome Forissier [Fri, 25 Nov 2016 14:07:01 +0000 (15:07 +0100)]
Allow O to be an absolute path

Update so that absolute as well as relative paths are accepted by the
Makefile.

Tested with:
  $ export CFG_WITH_SQLFS=y
  $ make
  $ make O=build
  $ make O=/tmp/build
  $ make O=~/build

Note that tilde expansion is supposed to be done by the calling shell.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Suggested-by: Zeng Tao <prime.zeng@hisilicon.com>
Acked-by: Zeng Tao <prime.zeng@hisilicon.com>
4 years agoFormat UUID strings correctly ti2016.06 ti2016.06-rc1 ti2016.06-rc2 ti2016.06-rc3 ti2016.06-rc4
Jens Wiklander [Thu, 8 Dec 2016 15:43:27 +0000 (16:43 +0100)]
Format UUID strings correctly

Prior to this patch although GlobalPlatform specifies that TAs and such
are identified with UUIDs, we don't format them quite right when turning
them into strings. Per https://www.ietf.org/rfc/rfc4122.txt, there
should be another hyphen after the first two bytes of clockSeqAndNode.

Unfortunately, fixing this breaks compatibility between how TAs are
built, and when the OS loads them.

With this patch UUID string are formated with the additional hyphen as
for instance: f81d4fae-7dec-11d0-a765-00a0c91e6bf6

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Fixes: https://github.com/OP-TEE/optee_os/issues/857
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoEncode UUID big endian
Jens Wiklander [Thu, 8 Dec 2016 14:14:16 +0000 (15:14 +0100)]
Encode UUID big endian

When encoding a UUID as a sequence of bytes, the spec
(https://www.ietf.org/rfc/rfc4122.txt) says that the u32, and two u16s
should be represented big endian.

Before this patch OPTEE always treated them natively. With this patch
UUIDs are always converted to/from big endian when communicating with
the kernel.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Fixes: https://github.com/OP-TEE/optee_os/issues/858
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agotee-supplicant: add missing unistd.h in tee_fs.h
Zoltan Kuscsik [Fri, 2 Dec 2016 11:52:38 +0000 (12:52 +0100)]
tee-supplicant: add missing unistd.h  in tee_fs.h

R_OK, W_OK are defined by uninstd.h. This change ensures
the project can be compiled with Android Bionic

Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
[Rebase on top of master]
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
4 years agoREADME: Replace toolchain URL with reference to toolchain.mk
Victor Chong [Tue, 6 Dec 2016 05:47:19 +0000 (05:47 +0000)]
README: Replace toolchain URL with reference to toolchain.mk

This is to avoid hard coding toolchain URL which tends to change and
require constant updates.

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
4 years agoUpdate clean rules
Jerome Forissier [Mon, 28 Nov 2016 09:27:56 +0000 (10:27 +0100)]
Update clean rules

Do not use rm -rf, it's unsafe. Instead, remove only the files created
by the build and the output directories if they're empty. This allows
to specify the source directory as an output location:

  $ make O=.
  $ make O=. clean

Without this fix the clean step would remove the source files too.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoIntroduce BINDIR, LIBDIR, INCLUDEDIR and DESTDIR
Jerome Forissier [Wed, 23 Nov 2016 14:12:17 +0000 (15:12 +0100)]
Introduce BINDIR, LIBDIR, INCLUDEDIR and DESTDIR

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Tested-by: Joakim Bech <joakim.bech@linaro.org> (RPi3)
4 years agolibteec: sync tee.h with the linux kernel header file
Etienne Carriere [Tue, 8 Nov 2016 10:47:13 +0000 (11:47 +0100)]
libteec: sync tee.h with the linux kernel header file

This changes is about cleanup. No functional change.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agolibteec extension: TEEC_RegisterSharedMemoryFileDescriptor()
Etienne Carriere [Tue, 8 Nov 2016 10:46:44 +0000 (11:46 +0100)]
libteec extension: TEEC_RegisterSharedMemoryFileDescriptor()

Create a shared memory object in system out of a file descriptor.
libteec relays the request to the tee driver and returns a shared
memory structure referring to the shared memory object.

Driver provides a file descriptor for the newly created tee_shm object.
TEE Client API library closes this fd when the shared memory object
is released from API TEEC_ReleaseSharedMemory().

None of the APIs TEEC_RegisterSharedMemoryFromFileDescriptor() and
TEEC_ReleaseSharedMemory() do close the initial file descriptor that
gets registered. It remains the responsibility of the called to
handle its file descriptor.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoAdd new RPC FS functions with useful error codes
Jens Wiklander [Fri, 9 Sep 2016 08:41:15 +0000 (10:41 +0200)]
Add new RPC FS functions with useful error codes

As the interface is changed to use proper error codes, the way
parameters are passed is also updated.

Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey)
Tested-by: Jens Wiklander <jens.wiklander@linaro.org> (QEMU)
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agobuild: print 'LINK' rather than 'LD' when $(LD) is not used directly 2.2.0
Jerome Forissier [Mon, 18 Jul 2016 16:09:43 +0000 (18:09 +0200)]
build: print 'LINK' rather than 'LD' when $(LD) is not used directly

When $(CC) is called to link object files, it makes little sense to
print 'LD <executable>'. Reserve this for when $(LD) is called
directly. Using 'CC <executable>' on the other hand would make it hard
to distinguish compile from link steps. So, print 'LINK <executable>'
instead. This is similar to what the Linux kernel build system does.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoTravis: unset CC
Jerome Forissier [Mon, 18 Jul 2016 15:38:00 +0000 (17:38 +0200)]
Travis: unset CC

The CC environment variable must not be set, otherwise our Makefiles
will use it instead of $(CROSS_COMPILE)gcc.
What it means is: we have been compiling for x86_64 until now.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agotee-supplicant: link with -lpthread
Jerome Forissier [Mon, 18 Jul 2016 14:51:32 +0000 (16:51 +0200)]
tee-supplicant: link with -lpthread

tee-supplicant uses pthread functions so it should link with -lpthread
(except for Android which provides the pthread functions a part of the
C library).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoTravis: build with CFG_SQL_FS=y
Jerome Forissier [Mon, 18 Jul 2016 13:03:29 +0000 (15:03 +0200)]
Travis: build with CFG_SQL_FS=y

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoAdd Android build for SQL FS
Jerome Forissier [Tue, 10 May 2016 08:30:31 +0000 (10:30 +0200)]
Add Android build for SQL FS

Compile-tested with:
  $ ../toolchains/android-ndk-r10e/ndk-build -j NDK_PROJECT_PATH=. \
    APP_BUILD_SCRIPT=Android.mk APP_ABI=arm64-v8a CFG_SQL_FS=y

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agotee-supplicant: implement SQL FS file operations
Jerome Forissier [Tue, 3 May 2016 15:30:43 +0000 (17:30 +0200)]
tee-supplicant: implement SQL FS file operations

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agotee-supplicant: add missing flags in conversion function
Jerome Forissier [Wed, 4 May 2016 08:00:01 +0000 (10:00 +0200)]
tee-supplicant: add missing flags in conversion function

Adding TEE_FS_O_TRUNC and TEE_FS_S_IXUSR.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agotee-supplicant: move file operations and flags to their own header
Jerome Forissier [Tue, 3 May 2016 11:48:05 +0000 (13:48 +0200)]
tee-supplicant: move file operations and flags to their own header

The flags and conversion functions will be re-used by the SQL
filesystem, so move them to a common header: tee_fs.h.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agolibsqlfs: fix sqlfs_proc_read()
Jerome Forissier [Fri, 13 May 2016 12:50:39 +0000 (14:50 +0200)]
libsqlfs: fix sqlfs_proc_read()

sqlfs_proc_read() should return 0 when reading an empty file or past
EOF. Upstream: https://github.com/guardianproject/libsqlfs/pull/10.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoImport libsqlfs
Jerome Forissier [Tue, 3 May 2016 09:03:25 +0000 (11:03 +0200)]
Import libsqlfs

Import libsqlfs from //github.com/guardianproject/libsqlfs.git commit
effc5bc58161 ("Fix parallel build errors...").

From http://www.nongnu.org/libsqlfs/:
"The libsqlfs library implements a POSIX style file system on top of an
SQLite database. It allows applications to have access to a full
read/write file system in a single file, complete with its own file
hierarchy and name space. [...] This brings the benefits of a real
database, such as transactions and concurrency control"

Note that libsqlfs is distributed under the GNU LGPL version 2 or later,
which has its own implications on how the library may be used in this
project. In short: do not link statically and do not break the
interface.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoImport SQLite
Jerome Forissier [Tue, 3 May 2016 07:52:26 +0000 (09:52 +0200)]
Import SQLite

Import https://www.sqlite.org/2016/sqlite-amalgamation-3110100.zip.
This is the first of a series of commits enabling support for a
filesystem based on a SQLite database. Hence, this code is enabled
with CFG_SQL_FS=y.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
4 years agoAdd the missed login method
prime-zeng [Thu, 11 Aug 2016 03:57:26 +0000 (11:57 +0800)]
Add the missed login method

Reviewed-by: David Brown <david.brown@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Zeng Tao <prime.zeng@huawei.com>
4 years agoRemove the connection_method limit
prime-zeng [Thu, 11 Aug 2016 03:28:31 +0000 (11:28 +0800)]
Remove the connection_method limit

Since we have to add support for login method other than TEE_LOGIN_PUBLIC
in the future, remove the limit now.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: David Brown <david.brown@linaro.org>
Signed-off-by: Zeng Tao <prime.zeng@huawei.com>
4 years agoUse "make V=1" for verbose build 20160825-for-lmg
Jerome Forissier [Wed, 17 Aug 2016 07:04:37 +0000 (09:04 +0200)]
Use "make V=1" for verbose build

Replace 'VERBOSE_BUILD' with 'V' for simplicity and consistency with
other projects.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
4 years agoTry loading TAs from another writable path
David Brown [Tue, 2 Aug 2016 17:51:32 +0000 (11:51 -0600)]
Try loading TAs from another writable path

To allow testing of corrupt TA loading on systems where the TA
directory is read-only, try loading TAs first from an alternate
`TEEC_TEST_LOAD_PATH` before the regular path.  This allows the test
to override the TA with one for testing purposes.

Although useful for testing, this should not be enabled for a
production system, since it facilitates replacing a TA with a corrupt
image.  CFG_TA_TEST_PATH can be turned off in the `config.mk`.

Signed-off-by: David Brown <david.brown@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
4 years agoAdjust error codes for TEEC_OpenSession() and TEEC_InvokeCommand()
Jerome Forissier [Wed, 27 Jul 2016 13:43:00 +0000 (15:43 +0200)]
Adjust error codes for TEEC_OpenSession() and TEEC_InvokeCommand()

When the ioctl() call inside TEEC_OpenSession() or TEEC_InvokeCommand()
fails, TEEC_ERROR_BAD_STATE is returned. Update the error path to
return more descriptive codes:
- TEEC_ERROR_OUT_OF_MEMORY if ioctl() has set errno to ENOMEM (with the
current driver, this can occur when the driver's private memory pool is
full).
- TEEC_ERROR_GENERIC otherwise.

This commit also removes <err.h> which is not needed and may cause a
compile warning ("declaration of ‘err’ shadows a global declaration").

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: David Brown <david.brown@linaro.org>
4 years agoCheck flags before allocating shared memory. 2.1.0
Kris [Sun, 5 Jun 2016 21:17:58 +0000 (23:17 +0200)]
Check flags before allocating shared memory.

In TEEC_AllocateSharedMemory check if TEEC_MEM_INPUT, TEEC_MEM_OUTPUT
or both values are set in shm->flags before allocating shared memory.

Signed-off-by: Krzysztof Kwiatkowski <kris@amongbytes.com>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Joakim Bech <joakim.bech@linaro.org> (QEMU)
5 years agoFix compiler missing-field-initializers warnings
Zoltan Kuscsik [Fri, 1 Apr 2016 11:50:56 +0000 (13:50 +0200)]
Fix compiler missing-field-initializers warnings

Tested on AOSP 5.0

Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Change-Id: I0817e4b7c772a25c0d7fe89e2e5c8bd891696fa7
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoFix return-type warnings with CLang
Zoltan Kuscsik [Fri, 1 Apr 2016 11:52:25 +0000 (13:52 +0200)]
Fix return-type warnings with CLang

Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Change-Id: I322603a6857e27ebd4cc63abe0f00a1a3e7e6471
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoAndroid: fix makefile compatibility
Zoltan Kuscsik [Thu, 31 Mar 2016 12:17:51 +0000 (14:17 +0200)]
Android: fix makefile compatibility

Android always adds the gen/SHARED_LIBRARIES folder
from the product output folder to the include dirs, however,
this directory may be non-existing.

The target binary name tee-supplicant conflicts
with the source subfolder name tee-supplicant.

Android stores the build object files in a temporary
directory structure matching the tree structure of
the source folders.

Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Change-Id: I9b24e61ccd757dedbfd4584ffa6fc9c09daeaccd
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoAndroid: export public include dir
Zoltan Kuscsik [Thu, 31 Mar 2016 11:54:39 +0000 (13:54 +0200)]
Android: export public include dir

We make sure that applications linking to libteec
are always pointed to the right include dir.
This is achieved by using:

LOCAL_EXPORT_C_INCLUDE_DIRS

Change-Id: I8170ed008da81bcbecbe7a00533932ca79ace8f1
Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoAndroid.mk cleanup
Zoltan Kuscsik [Thu, 31 Mar 2016 11:52:37 +0000 (13:52 +0200)]
Android.mk cleanup

Change-Id: Ic5d86d39a7858b5da672f4108e01cc96239a6654

Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoUse Android way for detecting Android builds
Zoltan Kuscsik [Thu, 31 Mar 2016 11:44:38 +0000 (13:44 +0200)]
Use Android way for detecting Android builds

AOSP build system defines the __ANDROID__
constant. No need for another one.

Change-Id: I2ff302e902386d1894441f4a4fa3bc5304320e05
Signed-off-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Zoltan Kuscsik <zoltan.kuscsik@linaro.org>
5 years agoSupport OP-TEE in generic TEE subsystem 2.0.0
Jens Wiklander [Thu, 26 Mar 2015 09:57:50 +0000 (10:57 +0100)]
Support OP-TEE in generic TEE subsystem

Replaces support for for the old OP-TEE driver with support for OP-TEE
in the generic TEE subsystem.

Uses id instead of fd to identify shared memory objects to let
tee-supplicant manage allocation and freeing of its memory shared with
secure world.

This change depends on corresponding abi change in the kernel.

Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
5 years agotee-supplicant: add TEE_RPC_LOAD_TA2
Jens Wiklander [Fri, 25 Dec 2015 17:06:43 +0000 (18:06 +0100)]
tee-supplicant: add TEE_RPC_LOAD_TA2

Adds new RPC function TEE_RPC_LOAD_TA2 which doesn't allocate a buffer
for the TA to load, instead secure world is responsible to allocate the
buffer when doing this RPC.

Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey)
Tested-by: Jens Wiklander <jens.wiklander@linaro.org> (QEMU)
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>