开发环境:Ubuntu 22.04 desktop 虚拟机
1、环境需求
$ sudo dpkg --add-architecture i386 $ sudo apt-get update
$ sudo apt-get install android-tools-adb android-tools-fastboot autoconf automake bc bison build-essential ccache codespell cpio cscope curl device-tree-compiler expect flex ftp-upload gdisk iasl libattr1-dev libcap-dev libcap-ng-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-crypto python3-crypto python-pyelftools python3-pycryptodome python3-pyelftools rsync unzip uuid-dev xdg-utils xterm xz-utils zlib1g-dev
2、安装 repo
$ mkdir ~/bin
$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o ~/bin/repo
$ chmod a+x ~/bin/repo
$ export PATH=~/bin:$PATH
更改 repo 获取源,在 /etc/profile 文件最后添加如下内容,然后重启系统
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
3、获取 OP-TEE 代码
$ mkdir OP-TEE
$ cd OP-TEE/
$ repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml
$ repo sync -j4 --no-clone-bundle
备注1:提示 “Failed to connect to boringssl.googlesource.com port 443: Connection timed out” 错误是因为相关网址无法访问,可使用如下命令替换网址源:
$ git config --global url."https://github.com/google/boringssl.git".insteadOf "https://boringssl.googlesource.com/boringssl"
$ git config --global url."https://hub.fastgit.org/google/boringssl.git".insteadOf "https://boringssl.googlesource.com/boringssl"
备注2:sync 操作会因为 github 链接失败而报错,报错后重新执行即可。但 sync 每次都会更新所有库,只要有一个库链接失败都会报错,但可能这个库已经下载完成了。因此可以查看对应的 manifest 文件,检查是不是所有库都已经下载完成。如果都已经下载完成即可以进入到下一步骤。manifest.xml 文件在 .repo 目录下。
4、编译
$ cd ./build
$ make -j2 toolchains
$ make -j `nproc`
5、运行 qemu
依然在 build/ 目录下
$ make run
正确运行后会弹出两个虚拟的串口终端,其中端口号为 54320 的是非安全系统,端口号为 54321 的为安全系统:
进入 qemu 终端后输入 c 启动系统:
(qemu) c
非安全系统(Linux)可以通过 root 用户登录
安全系统:
备注1:运行过程中可能会报 python 命令找不到的错误,但是 ubuntu 下已经安装了 python。这是因为名称问题,安装的是 python2 和 python3,这里可以创建一条链接解决问题:
$ sudo ln -s /usr/bin/python3 /usr/bin/python
备注2:第一次执行 make run 会编译相关组件再运行 qemu,之后可以直接运行 make run-only 直接运行。
6、运行测试程序
使用 ps 命令检查 tee-supplicant 进程是否存在
运行 xtest 测试例程
$ xtest