由于网络原因, 你可能遇到库无法下载的情况, 特别准备了一个完整的包, 大约12GB:
链接:https://pan.baidu.com/s/1AAMwNn2sl20EtTEqwzyIHg
提取码:skq8
说明: 使用上面这个包的话, 则不需要make -f toolchain.mk toolschains这个步骤啦~ 否则会等很久很久很久...
我使用的是Ubuntu 18.04.3的系统, 系统信息:
cat /proc/version
Linux version 5.0.0-37-generic (buildd@lcy01-amd64-023) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019
主要参考资料: https://optee.readthedocs.io/en/latest/
[有可能]需要对libuuid1进行降级:
sudo apt install libuuid1=2.31.1-0.4ubuntu3
安装可能需要的工具:
sudo apt install android-tools-adb android-tools-fastboot autoconf automake bc bison build-essential cscope curl device-tree-compiler expect flex ftp-upload gdisk libattr1-dev libcap-dev libfdt-dev libftdi-dev libglib2.0-dev libhidapi-dev libncurses5-dev libpixman-1-dev libssl-dev libtool make mtools netcat python-crypto python-serial python-wand unzip uuid-dev xdg-utils xterm xz-utils zlib1g-dev iasl python3-pycryptodome python3-pyelftools libstdc++6:i386 libc6:i386 libz1:i386
初始化库:
mkdir open-tee
cd open-tee/
repo init -u https://github.com/OP-TEE/manifest.git -m default.xml -b 3.8.0
强烈建议使用3.8.0的分支, 有些资料(比如图书会建议使用2.6.0, 但: OP-TEE的build/目录没有与2.6.0的代码同步, 所以会无法处理2.6.0的repo对应的目录结构.
如果使用最新的版本, 也会遇到很多的编译问题, 例如在编译buildroot时ld无法正常处理-loptee_test参数, 不清楚具体的原因.
[必要时]为了防止报错:
sed -i "s/\.git//g" .repo/manifests/default.xml
cd .repo/manifests/
git add .
git commit -sm "delete .git for repo sync."
repo同步:
repo sync
Tips: 对于sync, 如果想使用代理, 可以尝试:
export HTTP_PROXY="http://<IP>:<Port>"
编译工具链:
make -f toolchain.mk toolchains
编译qemu.mk
make -f qemu.mk all
Tips: 对于buildroot的下载缓慢的问题, 如果想使用代理, 可以尝试:
export http_proxy="http://<IP>:<Port>"
执行如下命令启动qemu:
make -f qemu.mk run-only
pushd /opt/work/open-tee/build/../out/bin
/opt/work/open-tee/build/../qemu/arm-softmmu/qemu-system-arm \
-nographic \
-serial tcp:localhost:54320 -serial tcp:localhost:54321 \
-smp 2 \
-s -S -machine virt,secure=on -cpu cortex-a15 \
-d unimp -semihosting-config enable,target=native \
-m 1057 \
-bios bl1.bin \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-rng-pci,rng=rng0,max-bytes=1024,period=1000 \
-netdev user,id=vmnic \
-device virtio-net-device,netdev=vmnic
QEMU 3.0.93 monitor - type 'help' for more information
(qemu) c <- 输入'c'以继续
此时在新终端(两个, 一个是Linux输出CA的log, 一个是OP-TEE输出TA的log)下可以看到系统成功启动, 启动后, 使用root登录到buildroot, 密码: root
然后执行xtest命令进行测试:
# xtest
... ...
+-----------------------------------------------------
24537 subtests of which 0 failed
96 test cases of which 0 failed
0 test cases were skipped
TEE test application done!
按后也可以CA的demo:
# optee_example_hello_world
Invoking TA to increment 42
TA incremented value to 43
此时TA的输出:
D/TC:? 0 tee_ta_init_pseudo_ta_session:280 Lookup pseudo TA 8aaaf200-2450-11e4-abe2-0002a5d5c51b
D/TC:? 0 load_ldelf:704 ldelf load address 0x104000
D/LD: ldelf:134 Loading TA 8aaaf200-2450-11e4-abe2-0002a5d5c51b
D/TC:? 0 tee_ta_init_session_with_context:573 Re-open TA 3a2f8978-5dc0-11e8-9c2d-fa7ae01bbebc
D/TC:? 0 system_open_ta_binary:250 Lookup user TA ELF 8aaaf200-2450-11e4-abe2-0002a5d5c51b (Secure Storage TA)
D/TC:? 0 system_open_ta_binary:253 res=0xffff0008
D/TC:? 0 system_open_ta_binary:250 Lookup user TA ELF 8aaaf200-2450-11e4-abe2-0002a5d5c51b (REE)
D/TC:? 0 system_open_ta_binary:253 res=0x0
D/LD: ldelf:169 ELF (8aaaf200-2450-11e4-abe2-0002a5d5c51b) at 0x16f000
D/TC:? 0 tee_ta_close_session:499 csess 0xe185e08 id 1
D/TC:? 0 tee_ta_close_session:518 Destroy session
D/TC:? 0 tee_ta_close_session:499 csess 0xe186210 id 11
D/TC:? 0 tee_ta_close_session:518 Destroy session
D/TC:? 0 destroy_context:298 Destroy TA ctx (0xe1861d0)
如果遇到错误, 请参考下文的解决办法:
[可能]遇到错误:
make[1]: Leaving directory '/opt/work/open-tee/linux'
mkdir -p /opt/work/open-tee/build/../out/bin
ln -sf /opt/work/open-tee/build/../linux/arch/arm/boot/zImage /opt/work/open-tee/build/../out/bin
cd /opt/work/open-tee/build/../qemu; ./configure --target-list=arm-softmmu\
--cc=" gcc" --extra-cflags="-Wno-error"
ERROR: glib-2.40 gthread-2.0 is required to compile QEMU
Makefile:81: recipe for target 'qemu' failed
make: *** [qemu] Error 1
这是由于pkg-config的--atleast-version无法正确处理glib-2.0.pc中的Version, 解决:
diff --git a/configure b/configure
index 0a3c6a7..daf3497 100755
--- a/configure
+++ b/configure
@@ -3471,7 +3471,8 @@ if test "$static" = yes -a "$mingw32" = yes; then
fi
for i in $glib_modules; do
- if $pkg_config --atleast-version=$glib_req_ver $i; then
+ # if $pkg_config --atleast-version=$glib_req_ver $i; then
+ if $pkg_config --cflags $i; then
glib_cflags=$($pkg_config --cflags $i)
glib_libs=$($pkg_config --libs $i)
QEMU_CFLAGS="$glib_cflags $QEMU_CFLAGS"
以下确实库导致的编译错误已经附在上问的安装参考.
[可能]遇到报错:
***
Can't find elftools module. Probably it is not installed on your system.
You can install this module with
$ apt install python3-pyelftools
if you are using Ubuntu. Or try to search for "pyelftools" or "elftools" in
your package manager if you are using some other distribution.
***
这是因为系统缺失pyelftools库, 解决:
sudo apt install python3-pyelftools
[可能]遇到报错:
Traceback (most recent call last):
File "out/arm/export-ta_arm32/scripts/sign_encrypt.py", line 258, in <module>
main()
File "out/arm/export-ta_arm32/scripts/sign_encrypt.py", line 131, in main
from Cryptodome.Signature import pss
ModuleNotFoundError: No module named 'Cryptodome'
缺失pycryptodome库, 解决:
sudo apt install python3-pycryptodome
来源:CSDN
作者:liyangzmx
链接:https://blog.csdn.net/liyangzmx/article/details/104680632