test_optee_os.py 3.0 KB

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