02. Writing Trusted Applications

In the second part of our lab, it's time to run some Trusted Applications (TAs)!

We will use the official optee_examples as starting point.

Two questions arise: how can one compile a TA? + how to test it on our board?

Step 5. Not so fast... we forgot about the kernel?

If we wish to communicate with OP-TEE from Linux, we need to configure its driver (don't worry, we don't need to recompile the kernel, it's included in defconfig').

Of course, the intended way to do that is by modifying the Linux Device Tree. Do it as documented here ;)

In case you need a little reminder, the device tree source code is inside linux's arch/arm64/.

We promised that you won't need to recompile the kernel, you just need to recompile its DTB ;) use:

make ARCH=... dtbs

Afterwards, you need to copy the new .dtb into your staging/ directory and re-build the Linux uImage (using the previously provided staging/Makefile).

As for the userspace (rootfs), there are two choices: either Debian or Buildroot (disable RAUC nevertheless and use the first version of mk-disk-image.sh to upload the rootfs when ready to test, towards the end of the task).

For Buildroot, you must use menuconfig and enable PACKAGE_OPTEE_CLIENT! Built it & unpack it to the secondary ext4 disk partition (just edit the mk-disk-image script).

For Debian, you can either cross compile the OP-TEE client or try out the optee-client package from APT (use a chroot to install from host).

Step 6. Building a TA

We can use our workstation / laptop to cross-compile a trusted application!

Read the official instructions here.

Build both the host app and the Trusted Application need to be compiled TOGETHER with the TEE Client Library, and the OPTEE OS exported SDK, respectively.

Make sure to read the examples documentation to see the make variables to set!

Special Instructions for Buildroot

Special Instructions for Buildroot

Note that, usually, you must build optee-client from source on the host machine the optee_client first. .

Since you're using Buildroot, you can find it already compiled for the target system at <buildroot-dir>/output/build/optee-client-<version>.

Touugh we need to give a TEEC_EXPORT install path when invoking the TA makefile… Use find for tee_client_api.h and see where it's found (hint: sysroot)!

Also note that for building Buildroot-targeted applications, your classic aarch64-none-gnu- toolchain won't work since Buildroot uses a custom LibC by default. But, fortunately, you may find the cross compilation prefix at <buildroot-dir>/output/host/bin/aarch64-buildroot-linux-gnu- (see the difference?)!

As for TA_DEV_KIT_DIR of a Trusted Application, it must point to an SDK generated inside BL32 (optee_os) source directory (something like export-ta…'.

Step 7. Signing the TA

Remember the secure boot process? The Secure OS (OP-TEE) will also verify each TA before being able to load it!

Fortunately, OP-TEE comes with a predefined key pair, used to facilitate development / testing (warning: highly insecure since anybody can retrieve that key from the source repository!).

Read on for the TA signing procedure!

Even better: the TA Makefile automatically signs the .ta using the development key. So we won't need to do anything more! Yay…

Step 8. Testing the TA

Our rootfs image already contains the OP-TEE client library.

You just need to copy to the cross-compiled binaries to your boot partition.

For this, put u-boot in USB Mass Storage mode:

u-boot=> ums mmc 0

Use lsblk to find out which is the second (ext4) partition, mount it and copy the TA files:

mount /dev/sda2 /mnt
ls -l /mnt
# copy them inside your home
cp $OPTEE_FILES /mnt/root/

After copying the files, boot Linux.

On buildroot, check if tee-supplicant is running… or start it:

ps aux | grep tee-supplicant
tee-supplicant -d

Then execute the trusted application ;)

Observe the error: OP-TEE cannot find the .ta file inside a trusted memory or REE.

For this, you will need to copy the signed <UUID>.ta file to /lib/optee_armtz/ (create it if it doesn't exist), as (very badly) documented.

ass/labs-2025/05/tasks/02.txt · Last modified: 2026/07/17 10:11 by florin.stancu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0