Hello_world TA

Hello_world TA

本项目运行于iMX8mqevk 开发板中(Ps: 运行环境关系不大), 编译及项目实现过程在ubuntu 宿主机中,编译过程尽量不依赖于optee os项目源码,运行环境版本:optee os v3.2.0, optee_example v3.2.0,项目源码:https://gitee.com/xsyin/hello_world_ta

项目的目录结构如下:

在这里插入图片描述
在这里插入图片描述

源码下载

  1. 工具链(toolchains目录)

TA最终运行在arm环境中,需要在宿主机上对TA源码进行交叉编译,从ARM官网下载编译工具链 ,本项目使用版本为gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu

  1. 示例源码(aes, hello_world目录)

代码来自于 optee_example仓库

git clone https://github.com/linaro-swg/optee_examples.git
git checkout 3.2.0
  1. teec_export目录

teec_export目录为编译所需的头文件(例如 tee_client_api.h)和 库文件(例如 libteec.so.1.0),从optee_client仓库编译得到。

  1. ta_dev_kit目录

TA编译所需的编译文件,从optee_os仓库编译得到,路径optee-os/out/arm-plat-imx/export-ta_arm64下的内容。

编译

执行./build.sh命令编译,build.sh的内容如下:

#!/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 &
  1. 开发板/lib/optee_armtz路径下已存在目标TA

  2. 执行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。

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值