[Buildroot] [PATCH v3] support/testing/tests/boot/test_atf.py: test BL33

Jakob Kastelic kastelic.jakob at gmail.com
Thu Feb 5 04:50:29 UTC 2026


This commit adds a new runtime test, in which TF-A loads Linux directly
(as BL33) under Qemu. This test is used to test the new TF-A flag,
BR2_TARGET_ARM_TRUSTED_FIRMWARE_LINUX_AS_BL33.

Signed-off-by: Jakob Kastelic <kastelic.jakob at gmail.com>

---
Changes v2 -> v3:
  - reformat defconfig as runtime test
  - mount real rootfs from storage instead of using an initrd
  - run OP-TEE runtime tests
---
 DEVELOPERS                             |  3 +
 support/testing/tests/boot/test_atf.py | 95 ++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)

diff --git a/DEVELOPERS b/DEVELOPERS
index 225d1ac917..aca03b2d67 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1510,6 +1510,9 @@ F:	package/python-scipy/
 F:	support/testing/tests/package/sample_python_scipy.py
 F:	support/testing/tests/package/test_python_scipy.py
 
+N:	Jakob Kastelic <kastelic.jakob at gmail.com>
+F:	support/testing/tests/boot/test_atf.py
+
 N:	James Hilliard <james.hilliard1 at gmail.com>
 F:	package/apcupsd/
 F:	package/bpftool/
diff --git a/support/testing/tests/boot/test_atf.py b/support/testing/tests/boot/test_atf.py
index b822b9d357..a54c6a7629 100644
--- a/support/testing/tests/boot/test_atf.py
+++ b/support/testing/tests/boot/test_atf.py
@@ -1,3 +1,6 @@
+import os
+import subprocess
+
 import infra.basetest
 
 
@@ -30,3 +33,95 @@ class TestATFAllwinner(infra.basetest.BRTest):
 
     def test_run(self):
         pass
+
+
+class TestATFNoUBoot(infra.basetest.BRTest):
+    config = \
+        """
+        BR2_arm=y
+        BR2_cortex_a15=y
+        BR2_ARM_FPU_VFPV3D16=y
+        BR2_TOOLCHAIN_BUILDROOT_CXX=y
+        BR2_TARGET_ROOTFS_EXT2=y
+        BR2_TARGET_ROOTFS_EXT2_4=y
+        BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_18=y
+        BR2_GLOBAL_PATCH_DIR="board/qemu/patches"
+        BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
+        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+        BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/arm-vexpress-tz/post-build.sh"
+        BR2_ROOTFS_POST_IMAGE_SCRIPT="board/qemu/post-image.sh"
+        BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_DEFCONFIG)"
+        BR2_LINUX_KERNEL=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.18.7"
+        BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
+        BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/qemu/arm-vexpress-tz/linux.fragment"
+        BR2_PACKAGE_OPENSSL=y
+        BR2_PACKAGE_OPTEE_EXAMPLES=y
+        BR2_PACKAGE_OPTEE_TEST=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_VERSION_VALUE="v2.7"
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_PLATFORM="qemu"
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_FIP=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_BL32_OPTEE=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_LINUX_AS_BL33=y
+        BR2_TARGET_ARM_TRUSTED_FIRMWARE_ADDITIONAL_VARIABLES="BL32_RAM_LOCATION=tdram"
+        BR2_TARGET_OPTEE_OS=y
+        BR2_TARGET_OPTEE_OS_NEEDS_DTC=y
+        BR2_TARGET_OPTEE_OS_PLATFORM="vexpress-qemu_virt"
+        BR2_PACKAGE_HOST_QEMU=y
+        BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
+        """
+
+    def patch_dts(self):
+        """
+        Place the rootfs into the kernel command line via the DTB.
+
+        In qemu-system-arm, -append is only allowed with -kernel option. Since
+        we are using the -bios option to load TF-A (which in turn loads the
+        kernel), we have to manually patch the DTB to add the root option.
+        """
+        dtb = os.path.join(self.builddir, "images", "qemu.dtb")
+        rootfs = os.path.join(self.builddir, "images", "rootfs.ext4")
+        flash = os.path.join(self.builddir, "images", "flash.bin")
+        qemu = os.path.join(self.builddir, "host", "bin", "qemu-system-arm")
+        fdtput = os.path.join(self.builddir, "host", "bin", "fdtput")
+
+        # get the DTB from Qemu
+        subprocess.run([
+            qemu, "-machine", f"virt,dumpdtb={dtb}", "-machine",
+            "secure=on", "-cpu", "cortex-a15"
+            ], check=True)
+
+        # insert kernel command line argument into DTB
+        subprocess.run([fdtput, "-t", "s", f"{dtb}", "/chosen", "bootargs",
+            "root=/dev/vda" ], check=True)
+
+        return dtb, rootfs, flash
+
+    def test_run(self):
+        dtb, rootfs, flash = self.patch_dts()
+
+        self.emulator.boot(arch="arm", options=[
+            "-machine", f"virt", "-machine",
+            "secure=on", "-cpu", "cortex-a15", "-dtb", dtb, "-smp", "1",
+            "-s", "-m", "1024", "-d", "unimp", "-netdev", "user,id=vmnic",
+            "-device", "virtio-net-device,netdev=vmnic", "-semihosting-config",
+            "enable=on,target=native", "-bios", flash,
+            "-drive", f"file={rootfs},if=none,format=raw,id=hd0", "-device",
+            "virtio-blk-device,drive=hd0"
+            ])
+
+        self.emulator.login()
+
+        # Check the Kernel has OP-TEE messages
+        self.assertRunOk("dmesg | grep -F optee:")
+
+        # Check we have OP-TEE devices
+        self.assertRunOk("ls -al /dev/tee*")
+
+        # Run some OP-TEE examples
+        examples = ["aes", "hello_world", "hotp", "random", "secure_storage"]
+        for ex in examples:
+            self.assertRunOk(f"optee_example_{ex}")
-- 
2.47.3



More information about the buildroot mailing list