Hikey960 OPTEE Linux 移植
参照 https://github.com/96boards-hikey/tools-images-hikey960/blob/master/build-from-source/README-ATF-UEFI-build-from-source.md
方案一:
sudo apt install uuid-dev python3-pycryptodome python3-pyelftools zip
cd hikey
git clone https://github.com/ARM-software/arm-trusted-firmware
git clone https://github.com/96boards-hikey/edk2 -b testing/hikey960_v2.5
git clone https://github.com/96boards-hikey/OpenPlatformPkg -b testing/hikey960_v1.3.4
git clone https://github.com/96boards-hikey/l-loader -b testing/hikey960_v1.2
cd edk2
ln -sf ../OpenPlatformPkg
git clone https://github.com/OP-TEE/optee_os.git
#下载工具链
wget http://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
wget http://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
#解压, 设置 PATH
....
cd l-loader
./build_uefi.sh
# 下载debian 镜像
wget http://snapshots.linaro.org/96boards/hikey/linaro/debian/latest/boot-linaro-stretch-developer-hikey-20200620-47.img.gz
wget http://snapshots.linaro.org/96boards/hikey/linaro/debian/latest/rootfs-linaro-stretch-developer-hikey-20200620-47.img.gz
# 解压 至 l-loader
#烧写, fastboot 模式 1-3 ON 2 OFF
sudo fastboot flash ptable prm_ptable.img
sudo fastboot flash fastboot l-loader.bin
sudo fastboot flash fip fip.bin
sudo fastboot reboot-bootloader
sudo fastboot flash boot boot-linaro-stretch-developer-hikey-*.img
sudo fastboot flash system rootfs-linaro-stretch-developer-hikey-*.img
# 网络 wl18-fw-4.bin
nmtui # activate connect
方案二
前置
sudo apt-get install android-tools-adb android-tools-fastboot autoconf \
automake bc bison build-essential cscope curl device-tree-compiler \
expect flex ftp-upload gdisk iasl 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
repo
mkdir ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
# .bashrc 中添加
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
source ~/.bashrc
源码下载
mkdir ~/optee_hikey960
cd ~/optee_hikey960
repo init -u https://github.com/OP-TEE/manifest.git -m hikey960.xml -b 3.9.0
repo sync
# 花费较长时间,几个小时,甚至中间会有断点,需手动重新执行续传
# buildroot 项目可能需手动git clone
git clone https://github.com/buildroot/buildroot.git buildroot
# 工具链可以手动下载,节约时间, 也可以 cd build & make toolchains
mkdir toolchains
cd toolchains
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz?revision=e09a1c45-0ed3-4a8e-b06b-db3978fd8d56&la=en&hash=93ED4444B8B3A812B893373B490B90BBB28FD2E3
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz?revision=2e88a73f-d233-4f96-b1f4-d8b36e9bb0b9&la=en&hash=167687FADA00B73D20EED2A67D0939A197504ACD
tar -xzf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C aarch32
tar -xzf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C aarch64
编译
# hikey960 v2版本为 4G DRAM,在build/hikey960.mk中相应修改为
OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey-hikey960 \
CFG_CONSOLE_UART=$(CFG_CONSOLE_UART) \
+ CFG_DRAM_SIZE_GB=4
make all
烧录
# 设置开关
Switch 1: On
2: Off
3: On
# 接通电源,Type-c线连接开发板与电脑,进入fastboot模式
cd build
sudo make flash
#烧录成功后
sudo fastboot reboot-bootloader //fastboot模式下,回车进入系统
# 设置开关
Switch 1: On
2: Off
3: Off
测试
optee_example_hello_world //可看到正常输出,说明optee可用
问题
现有系统的rootfs使用嵌入式buildroot, 系统重启后无法保存已修改的设置, 且无法使用apt 安装软件
解决
结合方案一, 首先在build/hikey960.mk中将 all中boot-img的依赖去掉,使得make过程中不编译linux, buildroot等, 最后 flash 时注释掉 fastboot flash boot boot-*这行
使用方案一中的 boot 与 rootfs 的img
# 修改hikey960.mk后, 正常编译及烧录
cd build
make all
sudo make flash
#使用方案一的 boot 及 rootfs
cd ..
wget http://snapshots.linaro.org/96boards/hikey/linaro/debian/latest/boot-linaro-stretch-developer-hikey-20200620-47.img.gz
wget http://snapshots.linaro.org/96boards/hikey/linaro/debian/latest/rootfs-linaro-stretch-developer-hikey-20200620-47.img.gz
# 解压 烧录
sudo fastboot flash boot boot-linaro-*.img
sudo fastboot flash system rootfs-linaro-*.img
可正常启动, 且重启后系统状态不会丢失
optee 环境测试: 将make all 过程中生成的 tee-supplicant, xtest, optee_example_*, 各种ta拷贝至开发板上
# 启用无线网络
nmtui // activate connection 选择 ssid, 输入密码
# 启用 ssh
vim /etc/ssh/sshd_config
#将 PermitRootLogin 一行 改为 PermitRootLogin yes
service sshd restart
passwd
# 接下来的步骤参考我的博客 远程vps环境配置 中 ssh 的配置
# optee 环境配置
# 动态链接库 拷贝
scp libteec.so* debianroot:/usr/lib
scp tee-supplicant debianroot:/usr/sbin
# 注意 tee-supplicant 需要 GLIBC_2.28 版本, 升级glibc
下载 libc6_2.28-0ubuntu1_arm64.deb, dpkg -i 安装
# 开发板上执行
mkdir /lib/optee_armtz
# 电脑上
scp optee_example_* debianroot:/usr/bin
scp *.ta debianroot:/lib/optee_armtz
# 开发板上测试
tee-supplicant &
optee_example_hello_world //成功执行
内核替换:
cd ~/optee_hikey960/linux
make ARCH=arm64 CROSS_COMPILE=../toolchains/aarch64/bin/aarch64-linux-gnu- bindeb-pkg
# 在 上层目录 中生成 linux-headers-*.deb 和 linux-image-*.deb
# 拷贝至开发板, dpkg -i 安装,则启动时UEFI 中有相应的选项