# hello_world_ta **Repository Path**: xsyin/hello_world_ta ## Basic Information - **Project Name**: hello_world_ta - **Description**: 运行在optee中的示例ta - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-28 - **Last Updated**: 2024-03-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hello_world TA > 本项目运行于iMX8mqevk 开发板中(Ps: 运行环境关系不大), 编译及项目实现过程在ubuntu 宿主机中,编译过程尽量不依赖于optee os项目源码,运行环境版本:optee os v3.2.0, optee_example v3.2.0 项目的目录结构如下: ![hello_world_ta_1](hello_world_ta_1.png) ![hello_world_ta_2](hello_world_ta_2.png) ## 源码下载 1. 工具链(toolchains目录) TA最终运行在arm环境中,需要在宿主机上对TA源码进行交叉编译,从ARM官网下载编译[工具链](https://developer.arm.com/downloads/-/gnu-a) ,本项目使用版本为gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu 2. 示例源码(aes, hello_world目录) 代码来自于 [optee_example仓库](https://github.com/linaro-swg/optee_examples.git) ``` git clone https://github.com/linaro-swg/optee_examples.git git checkout 3.2.0 ``` 3. teec_export目录 teec_export目录为编译所需的头文件(例如 tee_client_api.h)和 库文件(例如 libteec.so.1.0),从[optee_client仓库](https://github.com/OP-TEE/optee_client)编译得到。 4. ta_dev_kit目录 TA编译所需的编译文件,从[optee_os仓库](https://github.com/OP-TEE/optee_os)编译得到,路径optee-os/out/arm-plat-imx/export-ta_arm64下的内容。 ## 编译 执行`./build.sh`命令编译,build.sh的内容如下: ```shell #!/bin/bash CURDIR=$(pwd) export CROSS_COMPILE=$CURDIR/../toolchains/aarch64/bin/aarch64-linux-gnu- export TA_DEV_KIT_DIR=$CURDIR/../ta_dev_kit export TEEC_EXPORT=$CURDIR/../teec_export // 编译ta 与 ca make all // ta目录下得到hello_world的ta执行文件: 8aaaf200-2450-11e4-abe2-0002a5d5c51b.ta // host目录下得到hello_world的ca执行文件:optee_example_hello_world // 将编译好的ta和ca文件拷贝到开发板中 scp ta/*.ta root@10.42.0.199:/lib/optee_armtz scp host/optee_example_hello_world root@10.42.0.199:/ ``` ## 运行 1. 检查optee是否存在: ` ls /dev/tee*` 应存在tee0和teepriv0设备。 2. 将运行所需的库文件(teec_export目录下的3个库文件libteec.so.1.0.0)拷贝至开发板 /usr/lib目录下,拷贝守护进程tee-supplicant至开发板执行路径下(例如 /usr/bin) 3. 运行optee在普通世界的守护进程`tee-supplicant`: ``` sudo tee-supplicant & ``` 4. 开发板/lib/optee_armtz路径下已存在目标TA 5. 执行hello_world ca: ` ./optee_example_hello_world` 执行结果如下: ``` root@ubuntu-imx:/# ./optee_example_hello_world D/TC:0 tee_ta_init_pseudo_ta_session:274 Lookup pseudo TA 8aaaf200-2450-11e4-abe 2-0002a5d5c51b D/TC:0 load_elf:842 Lookup user TA ELF 8aaaf200-2450-11e4-abe2-0002a5d5c51b (Sec ure Storage TA) F/TC:0 plat_prng_add_jitter_entropy:74 plat_prng_add_jitter_entropy: 0x22 F/TC:0 plat_prng_add_jitter_entropy:74 plat_prng_add_jitter_entropy: 0xC0 F/TC:0 plat_prng_add_jitter_entropy:74 plat_prng_add_jitter_entropy: 0xBC D/TC:0 load_elf:842 Lookup user TA ELF 8aaaf200-2450-11e4-abe2-0002a5d5c51b (REE ) F/TC:0 plat_prng_add_jitter_entropy:74 plat_prng_add_jitter_entropy: 0x0A D/TC:0 load_elf_from_store:810 ELF load address 0x40005000 D/TC:0 tee_ta_init_user_ta_session:1019 Processing relocations in 8aaaf200-2450- 11e4-abe2-0002a5d5c51b F/TC:0 trace_syscall:128 syscall #1 (syscall_log) D/TA: TA_CreateEntryPoint:39 has been called F/TC:0 trace_syscall:128 syscall #1 (syscall_log) D/TA: TA_OpenSessionEntryPoint:68 has been called F/TC:0 trace_syscall:128 syscall #1 (syscall_log) I/TA: Hello World! F/TC:0 trace_syscall:128 syscall #1 (syscall_log) D/TA: inc_value:105 has been called F/TC:0 trace_syscall:128 syscall #1 (syscall_log) I/TA: Got value: 42 from NW F/TC:0 trace_syscall:128 syscall #1 (syscall_log) I/TA: Increase value to: 43 D/TC:0 tee_ta_close_session:380 tee_ta_close_session(0xfe070a00) D/TC:0 tee_ta_close_session:399 Destroy session F/TC:0 trace_syscall:128 syscall #1 (syscall_log) I/TA: Goodbye! F/TC:0 trace_syscall:128 syscall #1 (syscall_log) D/TA: TA_DestroyEntryPoint:50 has been called D/TC:0 tee_ta_close_session:425 Destroy TA ctx Invoking TA to increment 42 TA incremented value to 43 ``` 终端打印出执行日志,值42在安全世界中被加1。