[Concept,05/13] ulib: x86: Add Rust demo for qemu-x86_64_nospl

Message ID 20260220001926.2366140-6-sjg@u-boot.org
State New
Headers
Series ulib: Enable the Rust demo on more architectures |

Commit Message

Simon Glass Feb. 20, 2026, 12:19 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Define the x86_64-unknown-none Rust target and enable
CONFIG_RUST_EXAMPLES in the qemu-x86_64_nospl defconfig. Add the DTS
node for the Rust demo binary and a QEMU boot test.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 arch/x86/dts/u-boot.dtsi            | 18 +++++++++++++++++
 configs/qemu-x86_64_nospl_defconfig |  1 +
 scripts/Makefile.ulib-example       |  1 +
 test/py/tests/test_ulib.py          | 30 +++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+)
  

Patch

diff --git a/arch/x86/dts/u-boot.dtsi b/arch/x86/dts/u-boot.dtsi
index 69925c49c49..57b7be9ae29 100644
--- a/arch/x86/dts/u-boot.dtsi
+++ b/arch/x86/dts/u-boot.dtsi
@@ -213,4 +213,22 @@ 
 	};
 }; };
 #endif
+
+#ifdef CONFIG_RUST_EXAMPLES
+/ { binman {
+	rust-demo-rom {
+		filename = "rust-demo.rom";
+		insert-template = <&rom_common>;
+
+		blob {
+			filename = "examples/ulib/rust-demo-nodtb.bin";
+			offset = <CONFIG_X86_OFFSET_U_BOOT>;
+		};
+		u-boot-dtb {
+		};
+		fdtmap {
+		};
+	};
+}; };
+#endif
 #endif
diff --git a/configs/qemu-x86_64_nospl_defconfig b/configs/qemu-x86_64_nospl_defconfig
index 950d2d2e419..91aabf5d1a2 100644
--- a/configs/qemu-x86_64_nospl_defconfig
+++ b/configs/qemu-x86_64_nospl_defconfig
@@ -81,4 +81,5 @@  CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
 CONFIG_ULIB=y
 CONFIG_EXAMPLES=y
+CONFIG_RUST_EXAMPLES=y
 CONFIG_UNIT_TEST=y
diff --git a/scripts/Makefile.ulib-example b/scripts/Makefile.ulib-example
index 18d526f5b6b..4d8af88b898 100644
--- a/scripts/Makefile.ulib-example
+++ b/scripts/Makefile.ulib-example
@@ -21,6 +21,7 @@  ULIB_EXAMPLES := demo
 
 # --- Rust examples ---
 RUSTC := rustc
+RUST_TARGET_x86 := x86_64-unknown-none
 RUST_TARGET := $(RUST_TARGET_$(EXAMPLE_ARCH))
 
 ifeq ($(CONFIG_RUST_EXAMPLES),y)
diff --git a/test/py/tests/test_ulib.py b/test/py/tests/test_ulib.py
index 50784ea9c60..5ca46df0fe8 100644
--- a/test/py/tests/test_ulib.py
+++ b/test/py/tests/test_ulib.py
@@ -292,6 +292,36 @@  def test_ulib_demo_rom_64(ubman):
     """Test the ulib demo ROM image under QEMU x86_64."""
     run_x86_rom_demo(ubman, 'qemu-system-x86_64')
 
+def run_x86_rom_rust_demo(ubman, qemu_binary):
+    """Boot the Rust demo ROM image under QEMU and check for expected output.
+
+    Locates rust-demo.rom in the build directory, launches the given QEMU
+    binary with it, and asserts that the expected demo output is present.
+
+    Args:
+        ubman (ConsoleBase): Test fixture providing build directory
+            etc.
+        qemu_binary (str): QEMU system binary
+            (e.g. 'qemu-system-x86_64')
+    """
+    build = ubman.config.build_dir
+    demo_rom = os.path.join(build, 'rust-demo.rom')
+
+    assert os.path.exists(demo_rom), \
+        'rust-demo.rom not found in build directory'
+    assert shutil.which(qemu_binary), f'{qemu_binary} not found'
+
+    cmd = [qemu_binary, '-bios', demo_rom, '-nographic', '-no-reboot']
+    out = run_qemu_demo(cmd)
+    assert_demo_output(out)
+
+@pytest.mark.localqemu
+@pytest.mark.boardspec('qemu-x86_64_nospl')
+@pytest.mark.buildconfigspec("rust_examples")
+def test_ulib_rust_demo_rom_64(ubman):
+    """Test the Rust ulib demo ROM image under QEMU x86_64."""
+    run_x86_rom_rust_demo(ubman, 'qemu-system-x86_64')
+
 def run_bios_demo(ubman, qemu_binary, extra_qemu_args=None):
     """Boot the demo.bin binary under QEMU and check for expected output.