树莓派3B运行OP-TEE

需要设备
电脑一台(我的是ubuntu14.04)、
树莓派3B(op-tee支持的版本)包括电源、USB转串口模块(例CP2102模块)

一、在电脑上编译OP-TEE

安装需要的包:

$sudo apt-get install git android-tools-adb android-tools-fastboot autoconf automake bc bison build-essential cscope curl flex ftp-upload gdisk libattr1-dev libc6:i386 libcap-dev libfdt-dev libftdi-dev libglib2.0-dev libhidapi-dev libncurses5-dev libpixman-1-dev libssl-dev libstdc++6:i386 libtool libz1:i386 make mtools netcat python-crypto python-serial python-wand unzip uuid-dev xdg-utils xterm xz-utils zlib1g-dev 

$sudo apt-get install ccache minicom

我们安装ccache原因如下:
ccache isfaqa tool that caches build object-files etc locally on the disc and can speed up build time significantly in subsequent builds. On Debian-based systems (Ubuntu, Mint etc) you simply install it by running:
$ sudo apt-get install ccache
The makefiles in build.git are configured to automatically find and use ccache if ccache is installed on your system, so other than having it installed you don’t have to think about anything.
我们下面用minicom来进行串口通信
安装repo:

$mkdir ~/bin
$PATH=~/bin:$PATH
$curl https://storage.googleapis.com/git-repo-downloads/repo > $~/bin/repo
$chmod a+x ~/bin/repo

git需要指定你的用户名和邮箱:


$git config --global user.name "yourname"
$git config --global user.email "youremail"

下载op-tee源码,repo sync执行时间会比较长

$mkdir -p $HOME/devel/optee
$cd $HOME/devel/optee
$repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b master
$repo sync

下载交叉编译器,一共有三个,时间会比较长,因为很大:
gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu.tar.xz :94M
gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz : 88M
gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux.tar.xz : 45M

$cd build
$make toolchains

以上参考:
https://github.com/OP-TEE/build
下面参考:
https://github.com/OP-TEE/optee_os/blob/15fba47dc88c0698c7882852c275b6b26f1778c2/documentation/rpi3.md


$make all run
$make update_rootfs

下面是把OS和文件系统下载到SD卡,把SD卡插入电脑先运行

$sudo fdisk -l

查看SD卡位置,我的是sdb1与sdb2,df -hl 查看下sdb1,sdb2是否已经自动挂载了,我的Ubuntu就是自动挂载了,所以先umount 一下。
然后运行:


$make img-help
 会出现:
run the following as root
   $ mkfs.vfat -F16 -n BOOT /dev/sdx1
   $ mkdir -p /media/boot
   $ mount /dev/sdx1 /media/boot
   $ cd /media
   $ gunzip -cd /home/ck/devel/optee/build/../gen_rootfs/filesystem.cpio.gz | sudo cpio -idmv "boot/*"
   $ umount boot

run the following as root
   $ mkfs.ext4 -L rootfs /dev/sdx2
   $ mkdir -p /media/rootfs
   $ mount /dev/sdx2 /media/rootfs
   $ cd rootfs
   $ gunzip -cd /home/ck/devel/optee/build/../gen_rootfs/filesystem.cpio.gz | sudo cpio -idmv
   $ rm -rf /media/rootfs/boot/*
   $ cd .. && umount rootfs

按照要求运行上面命令就OK了,注意是在root命令下。到此烧写完成。

二、树莓派连接电脑

连接3个GPIO接口,TXD、RXD、GND(注意:串口模块的TXD连接板子GPIO的RXD,模块的RXD连接树莓派GPIO的TXD,GND连接GND,不用连接电源接口,意思是不用串口供电,而是用树莓派上的microUSB供电),然后把串口模块USB那端插入电脑。
我们用minicom调试板子:

$sudo minicom -s

我们选择第三个 Serial port setup,enter键进入,按键盘a,选择第一项,修改为:/dev/ttyUSB0,按键盘f,修改为NO。然后选择save setup as dfl。然后选择Exit退出.
然后我们给树莓派加电,从minicom控制台就可以看到系统启动信息,按enter键进入shell.

三、运行xtest

驱动是直接加好的,我们直接运行命令:

xtext 1001

我们再运行helloworld

 hello_world

打印信息如下:

root@RPi3:/ hello_world                                                         
DEBUG:   [0x0] TEE-CORE:tee_ta_init_pseudo_ta_session:227:    Lookup for pseudob
DEBUG:   [0x0] TEE-CORE:init_session_with_signed_ta:679:    Load dynamic TA     
DEBUG:   [0x0] TEE-CORE:ta_load:460: ELF load address 0x40001000                
DEBUG:   [0x0] TEE-CORE:init_session_with_signed_ta:685:       dyn TA : 8aaaf20b
DEBUG:   USER-TA:TA_CreateEntryPoint:41: has been called                        
FLOW:    USER-TA: tee_user_mem_alloc:343: Allocate: link:[0x400130a0], buf:[0x4]
DEBUG:   USER-TA:TA_OpenSessionEntryPoint:79: Hello World!                      
Invoking TA to increment 42                                                     
DEBUG:   USER-TA:inc_value:103: has been called                                 
DEBUG:   USER-TA:inc_value:107: Got value: 42 from NW                           
DEBUG:   USER-TA:inc_value:109: Increase value to: 43                           
TA incremented value to 43                                                      
DEBUG:   [0x0] TEE-CORE:tee_ta_close_session:318: tee_ta_close_session(0x847bea)
DEBUG:   [0x0] TEE-CORE:tee_ta_close_session:337:    ... Destroy session        
DEBUG:   USER-TA:TA_CloseSessionEntryPoint:92: Goodbye!                         
FLOW:    USER-TA: tee_user_mem_free:442: Free: link:[0x400130a0], buf:[0x400130]
DEBUG:   USER-TA:TA_DestroyEntryPoint:51: has been called                       
DEBUG:   [0x0] TEE-CORE:tee_ta_close_session:361:    ... Destroy TA ctx

OPTEE运行成功!!

你可能感兴趣的:(trustzone)