1import os 2 3import infra.basetest 4 5 6class TestOptee(infra.basetest.BRTest): 7 # A custom configuration is needed to enable OP-TEE support in the 8 # Kernel. This config is inspired from: 9 # configs/qemu_arm_vexpress_tz_defconfig 10 uboot_fragment = \ 11 infra.filepath("tests/boot/test_optee_os/u-boot.fragment") 12 config = \ 13 f""" 14 BR2_arm=y 15 BR2_cortex_a15=y 16 BR2_ARM_FPU_VFPV3D16=y 17 BR2_TOOLCHAIN_EXTERNAL=y 18 BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" 19 BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/arm-vexpress-tz/post-build.sh" 20 BR2_LINUX_KERNEL=y 21 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 22 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.73" 23 BR2_LINUX_KERNEL_DEFCONFIG="vexpress" 24 BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/qemu/arm-vexpress-tz/linux.fragment" 25 BR2_PACKAGE_OPTEE_EXAMPLES=y 26 BR2_TARGET_ROOTFS_CPIO=y 27 BR2_TARGET_ROOTFS_CPIO_GZIP=y 28 BR2_TARGET_ROOTFS_CPIO_UIMAGE=y 29 # BR2_TARGET_ROOTFS_TAR is not set 30 BR2_TARGET_ARM_TRUSTED_FIRMWARE=y 31 BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION=y 32 BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION_VALUE="v2.9" 33 BR2_TARGET_ARM_TRUSTED_FIRMWARE_PLATFORM="qemu" 34 BR2_TARGET_ARM_TRUSTED_FIRMWARE_FIP=y 35 BR2_TARGET_ARM_TRUSTED_FIRMWARE_BL32_OPTEE=y 36 BR2_TARGET_ARM_TRUSTED_FIRMWARE_UBOOT_AS_BL33=y 37 BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="BL32_RAM_LOCATION=tdram" 38 BR2_TARGET_OPTEE_OS=y 39 BR2_TARGET_OPTEE_OS_NEEDS_DTC=y 40 BR2_TARGET_OPTEE_OS_PLATFORM="vexpress-qemu_virt" 41 BR2_TARGET_UBOOT=y 42 BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y 43 BR2_TARGET_UBOOT_CUSTOM_VERSION=y 44 BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2022.04" 45 BR2_TARGET_UBOOT_BOARD_DEFCONFIG="qemu_arm" 46 BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="{uboot_fragment}" 47 """ 48 49 def test_run(self): 50 # There is no Kernel nor rootfs image here. They will be 51 # loaded by TFTP through the emulated network interface in 52 # u-boot. 53 bios = os.path.join(self.builddir, "images", "flash.bin") 54 tftp_dir = os.path.join(self.builddir, "images") 55 self.emulator.boot(arch="arm", 56 options=["-M", "virt,secure=on", 57 "-d", "unimp", 58 "-cpu", "cortex-a15", 59 "-m", "1024M", 60 "-netdev", f"user,id=vmnic,tftp={tftp_dir}", 61 "-device", "virtio-net-device,netdev=vmnic", 62 "-bios", bios]) 63 self.emulator.login() 64 65 # Check the Kernel has OP-TEE messages 66 self.assertRunOk("dmesg | grep -F optee:") 67 68 # Check we have OP-TEE devices 69 self.assertRunOk("ls -al /dev/tee*") 70 71 # Run some OP-TEE examples 72 examples = ["aes", "hello_world", "hotp", "random", "secure_storage"] 73 for ex in examples: 74 self.assertRunOk(f"optee_example_{ex}") 75