apache / incubator-teaclave-trustzone-sdk

Teaclave TrustZone SDK enables safe, functional, and ergonomic development of trustlets.
https://teaclave.apache.org
Apache License 2.0
204 stars 58 forks source link

Could not find specification for target "aarch64-unknown-optee-trustzone" #55

Closed gaojunjie03 closed 2 years ago

gaojunjie03 commented 2 years ago

Could not find specification for target "aarch64-unknown-optee-trustzone"

image

DemesneGH commented 2 years ago

Hi @gaojunjie03 Have you followed the Getting Started documents? Or you can paste your operations here for reproducing the error.

Thanks! Yuan

gaojunjie03 commented 2 years ago

我是全程使用dockerfile文件进行编译此项目的 platform:aarch64 (1)basedockerfile: FROM ubuntu:20.04 MAINTAINER Teaclave Contributors dev@teaclave.apache.org ENV DEBIAN_FRONTEND=noninteractive

Install dependencies for building OP-TEE

RUN apt-get update && \ apt-get install -y \ git \ android-tools-adb \ android-tools-fastboot \ autoconf \ automake \ bc \ bison \ build-essential \ ccache \ cscope \ curl \ device-tree-compiler \ expect \ flex \ ftp-upload \ gdisk \ iasl \ libattr1-dev \ libcap-dev \ libfdt-dev \ libftdi-dev \ libglib2.0-dev \ libgmp-dev \ libhidapi-dev \ libmpc-dev \ libncurses5-dev \ libpixman-1-dev \ libssl-dev \ libtool \ make \ mtools \ netcat \ ninja-build \ python \ python-crypto \ python3-crypto \ python-pyelftools \ python3-pycryptodome \ python3-pyelftools \ python3-serial \ rsync \ unzip \ uuid-dev \ xdg-utils \ xterm \ xz-utils \ zlib1g-dev \ wget \ cpio \ libcap-ng-dev \ screen \ libvdeplug-dev \ libsdl2-dev \ pip \ ca-certificates

RUN pip install cryptography -i https://mirrors.aliyun.com/pypi/simple/ RUN apt-get install -y software-properties-common COPY lib/* /usr/lib/aarch64-linux-gnu/ RUN ls /usr/lib/aarch64-linux-gnu/

COPY libpng12-0_1.2.54-1ubuntu1_arm64.deb .

RUN dpkg -i libpng12-0_1.2.54-1ubuntu1_arm64.deb

RUN add-apt-repository ppa:linuxuprising/libpng12

RUN apt-get update

RUN apt-get install -y libpng12-0

Install Rust

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ . $HOME/.cargo/env && \ rustup default nightly-2021-09-20 && \ rustup component add rust-src && \ rustup target install aarch64-unknown-linux-gnu && \ rustup default 1.44.0 && cargo +1.44.0 install xargo && \ rustup default nightly-2021-09-20

ENV PATH="/root/.cargo/bin:$PATH"

(2)这个基础依赖镜像打包好镜像之后,就根据该基础镜像制作上层镜像就是这个操作 image 这里也制作了个镜像 (3)完了之后,根据(2)得到的镜像就开始git submodule update --init -- optee 然后make toolchains(这里我把make optee 拆成了make toolchains、make optee-os、make optee-client三步完成),然后在编译toolchains的时候,一直/optee目录下报找不到buildroot文件夹,后来我查询了optee的相关资料在/optee下克隆了buildroot(分支是2021.08,克隆深度为1的项目下来,跟build optee-os optee-client同级),这样之后就可以继续编译下去了。该步也同样制作一个镜像 (4)在(3)得到的镜像之后,就开始make optee-os,制作该层镜像 (5)在(4)之后,紧接着make optee-client,这里一开始报了找不到aarch64-linux-gnu-gcc、aarch64-linux-gnu-gcc.br_real等各种文件,我查看到/incubator-teaclave-trustzone-sdk/optee/toolchains/aarch64/bin文件夹是有aarch64-buildroot相关文件的,所以我拷贝了一份改名称aarch64-linux-gnu-gcc....等就可以继续编译,然后在make examples上,报了这个错“Provided allocation has wrong size for slot count 131072", "the compiler unexpectedly panicked. this is a bug”,查阅相关资料后执行该命令后可以继续下去 rustup override set nightly-2021-09-22,然后又报了这个错“/usr/bin/ld can not find -lteec”,我执行了这个:cp ./optee/optee_client/out/export/usr/lib/libteec.so /usr/lib/。 就可以了,最终就报了 Could not find specification for target "aarch64-unknown-optee-trustzone" 该错误

DemesneGH commented 2 years ago

Hi @gaojunjie03

完了之后,根据(2)得到的镜像就开始git submodule update --init -- optee 然后make toolchains(这里我把make optee 拆成了make toolchains、make optee-os、make optee-client三步完成)

$ git submodule update --init -- optee

之后,需要运行

$ source environment

然后再make toolchains make optee-osmake optee-client,以及make -C examples/hello_world-rs

gaojunjie03 commented 2 years ago

Hi @gaojunjie03

完了之后,根据(2)得到的镜像就开始git submodule update --init -- optee 然后make toolchains(这里我把make optee 拆成了make toolchains、make optee-os、make optee-client三步完成)

$ git submodule update --init -- optee

之后,需要运行

$ source environment

然后再make toolchains make optee-osmake optee-client,以及make -C examples/hello_world-rs

在每一步make之前都有执行这个source environment的

gaojunjie03 commented 2 years ago

我看到项目里面的.cargo文件夹下有关于aarch64-unknown-optee-trustzone的处理,这个要怎么处理?

DemesneGH commented 2 years ago

Hi @gaojunjie03

在每一步make之前都有执行这个source environment的

我用Dockerfile build的image里按步骤编译没有报错,或许重新run一个编译环境试试?

另外,optee/目录下是不需要有buildroot的,make toolchains也不需要buildroot。也可以把报错信息贴上来看一下。

我看到项目里面的.cargo文件夹下有关于aarch64-unknown-optee-trustzone的处理,这个要怎么处理?

target的specification是默认在当前目录或者$RUST_TARGET_PATH中找的,可以echo $RUST_TARGET_PATH看一下是不是sdk的路径。specification是sdk目录下的aarch64-unknown-optee-trustzone.json

gaojunjie03 commented 2 years ago

Hi @gaojunjie03

在每一步make之前都有执行这个source environment的

我用Dockerfile build的image里按步骤编译没有报错,或许重新run一个编译环境试试?

另外,optee/目录下是不需要有buildroot的,make toolchains也不需要buildroot。也可以把报错信息贴上来看一下。

我看到项目里面的.cargo文件夹下有关于aarch64-unknown-optee-trustzone的处理,这个要怎么处理?

target的specification是默认在当前目录或者$RUST_TARGET_PATH中找的,可以echo $RUST_TARGET_PATH看一下是不是sdk的路径。specification是sdk目录下的aarch64-unknown-optee-trustzone.json。 echo $RUST_TARGET_PATH为空,我设置了这个变量值为sdk目录,可以了,估计是我source environment没成功, 然后怎么运行案例?我make examples成功了,我进入其中一个案例,hello_world-rs/host/target/aarch64-unknown-linux-gnu/release 运行./hello_world-rs 报错了。Error: The requested data item is not found. (error code 0xffff0008)

gaojunjie03 commented 2 years ago

似乎所有案例都报这个错 Error: The requested data item is not found. (error code 0xffff0008)

DemesneGH commented 2 years ago

然后怎么运行案例?我make examples成功了,我进入其中一个案例,hello_world-rs/host/target/aarch64-unknown-linux-gnu/release 运行./hello_world-rs 报错了。

@gaojunjie03 CA和TA需要在arm64架构的物理机或虚拟机中运行,参考这个文档:https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/

似乎所有案例都报这个错 Error: The requested data item is not found. (error code 0xffff0008)

这个错有可能是TA没有放到/lib/optee_armtz/目录中。

gaojunjie03 commented 2 years ago

然后怎么运行案例?我make examples成功了,我进入其中一个案例,hello_world-rs/host/target/aarch64-unknown-linux-gnu/release 运行./hello_world-rs 报错了。

@gaojunjie03 CA和TA需要在arm64架构的物理机或虚拟机中运行,参考这个文档:https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/

似乎所有案例都报这个错 Error: The requested data item is not found. (error code 0xffff0008)

这个错有可能是TA没有放到/lib/optee_armtz/目录中。

我这台机是aarch64,应该也是arm64吧? 我全程都是在docker容器上运行,包括编译 make optee和最终的make examples 运行案例都是在docker上(方便后面迁移到其他机器上)。是否不能在docker上?

gaojunjie03 commented 2 years ago

/lib/optee_armtz/ 这个目录在哪?没看见...,我是完全按照 image 这里进行的,执行到最后的make examples,还得要按着https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/这份文档继续进行下去吗?

DemesneGH commented 2 years ago

@gaojunjie03

执行到最后的make examples

这篇文档写的是build examples的步骤。在QEMU上运行examples的步骤需要看https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/ 。 如果是运行在物理机,不需要安装QEMU,make examples后:

  1. 拷贝TA到/lib/optee_armtz/
  2. 拷贝optee_client/out下编译出的libteec.so.* 到系统lib目录,拷贝tee-supplicant
  3. $ tee-supplicant &
  4. $ ./hello_world-rs

是否不能在docker上

运行tee-supplicant需要root权限,并且需要访问host的/dev/tee0/dev/tee_priv0设备。建议先用QEMU或物理机跑通之后,再尝试在docker里跑。

/lib/optee_armtz/ 这个目录在哪?没看见...

/lib/optee_armtz/没有就自己建一个。

gaojunjie03 commented 2 years ago

嗯嗯 好的 我尝试下, 之前报的在make toolchains报的buildroot错是这样的: 5c35ba49f29f0d34b174fc3f35b0b0d 所以我手动克隆了buildroot到/optee目录下

DemesneGH commented 2 years ago

@gaojunjie03

之前报的在make toolchains报的buildroot错是这样的:

因为我们之前编译examples的host都是x86_64,在这种情况下make toolchains会下载prebuilt的toolchain。你的host架构是aarch64,会build toolchain,所以需要buildroot。

gaojunjie03 commented 2 years ago

运行 tee-supplicant 报错,运行的ubuntu版本是20.04 tee-supplicant: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./tee-supplicant) 但我看你们的dockerfile的ubuntu也是20.04版本的,不会报这个错?

DemesneGH commented 2 years ago

@gaojunjie03

我看你们的dockerfile的ubuntu也是20.04版本的,不会报这个错?

我们的dockerfile是用来编译的。运行是在QEMU里,用的是这个文档build的image:https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/

gaojunjie03 commented 2 years ago

@gaojunjie03

我看你们的dockerfile的ubuntu也是20.04版本的,不会报这个错?

我们的dockerfile是用来编译的。运行是在QEMU里,用的是这个文档build的image:https://teaclave.apache.org/trustzone-sdk-docs/getting-started-with-optee-for-qemu-armv8/

就是如果我要运行在qemu,还得要继续执行这些吗? image

DemesneGH commented 2 years ago

@gaojunjie03

如果我要运行在qemu,还得要继续执行这些吗?

需要。如果要在QEMU中运行,需要先clone OP-TEE repo,QEMU是在OP-TEE repo里build的。 整个流程是先在Teaclave TrustZone SDK中build examples,再运行OP-TEE的QEMU,拷贝examples到QEMU中执行。

此外,Teaclave TrustZone SDK已经集成到OP-TEE主分支,也可以按照这个文档下载和编译OP-TEE,编译完成的buildroot里自带Teaclave TrustZone SDK的examples: https://optee.readthedocs.io/en/latest/building/optee_with_rust.html

gaojunjie03 commented 2 years ago

我已经按照那篇文档安装好并启动了qemu了 在normal world上运行xtest也是输出了成功的信息,但是我该怎么运行rust的案例呢?我运行这个挂载命令报错了。 image

gaojunjie03 commented 2 years ago

不过在make run-only里面 执行c之后 报了这个错 pflash_write: Write to buffer emulation is flawed 会不会有影响,但是normalworld和secure world输出的似乎正常,normalworld 到了可以让我输入root或者test进行登录,我执行了xtest也是成功的

gaojunjie03 commented 2 years ago

我已经按照那篇文档安装好并启动了qemu了 在normal world上运行xtest也是输出了成功的信息,但是我该怎么运行rust的案例呢?我运行这个挂载命令报错了。 image

哦哦 不好意思是我搞错了 这个是要在normalworld上执行的是吧

gaojunjie03 commented 2 years ago

但似乎运行案例还是报错了。 image image

gaojunjie03 commented 2 years ago

optee的案例可以跑 rust的案例不行 image

DemesneGH commented 2 years ago

@gaojunjie03

optee的案例可以跑 rust的案例不行

找一下OP-TEE examples TA的位置,把Rust的TA也放在那个目录。OP-TEE examples TA的UUID: https://optee.readthedocs.io/en/latest/building/gits/optee_examples/optee_examples.html#example-applications

gaojunjie03 commented 2 years ago

@gaojunjie03

optee的案例可以跑 rust的案例不行

找一下OP-TEE examples TA的位置,把Rust的TA也放在那个目录。OP-TEE examples TA的UUID: https://optee.readthedocs.io/en/latest/building/gits/optee_examples/optee_examples.html#example-applications

可以了 所有的案例的ta都在/lib/optee_armtz/里,由rust编译出来的examples的ta需要授权才能用 chmod 655 /lib/optee_armtz/* 我这边都跑通了,全部都是在docker容器里面跑的 感谢解答!!