From patchwork Mon Feb 16 01:34:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1887 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205753; bh=R6aPMhV27Qvq3a5q9JKS/ZhqvfNH7Q8Xo4SQtuAmQG0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UuT0i7RehqP1O/mqAHLoKsI/Hoon8ESJ7wECo9xJhGC/RAHkRo+3pHe4B9A2vRRLJ eu7gRIE9xwGC+jS3pXW5DiV4iry6ooObFyWcctcVyiJpvyIPp+IdN2umbUmVIcGSkG MWTSTSeuAquZcZ4x/QJdIIUqugkBr/dvX3HzjqZWOwE4Ng2mrtQUe5+h469Xh1DSYu W1pQy3dp6ai8jg9tsGVql4SCtTqchdUU+/G6rWhpuwd7Q890bXbTmbjAzqzWy+wA2j N4Q2zT54nauOkHz+bp75PNqrnhcqyb5jCabUu14f4oCqtKzLdnXek2hysbbjQFckg5 zeM/iifm+LWYw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 56CE669BE1 for ; Sun, 15 Feb 2026 18:35:53 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id VR67TiWvT3kv for ; Sun, 15 Feb 2026 18:35:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205752; bh=R6aPMhV27Qvq3a5q9JKS/ZhqvfNH7Q8Xo4SQtuAmQG0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=s/lLmjtZgeJaH1UdLYUv5OJX7VxoLOHBdRXP2zbzd9kCGvK/VocjA1H6VSnZLG+l6 wCciREztEkUW/tTZT+lUTnAMRhDxs6yfeDXvYfZQJyN0iGiYynEyjJ7f0Tb529PLYO 1mxSb/fwA9E7nqYPC7FCO2O9qZlZknSa1SibEHzQ4mqCf/uVYDn5w+Hi3ya4KklZ3F rmRiU6u70cxTOyYa6IIQcLtQZmi8aBnW77ITXCc8YwQGWrP0yC2dViO4ZVGeJP0MUq FY0n6Uv6iHVcHQjFFAXrnhCFCQ6sI2XNumSdIOTa2u5/8osF9zpfSkU2eveUGDNjSU 1oz6MEkB3i8jA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC44069BDF for ; Sun, 15 Feb 2026 18:35:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205750; bh=tXg75FOD/AkOBRSDYHMFwdaIo9Pg+8NMwfgIzYlOkOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hiagr2NozGTW9iMVf2PEWWGMnAJ8vFibYaxvStUwOzmDa5up6iXzuk9i0NOjkX+0E T7nQKZMYaj5RMIX1NXDPfPPloIP/ZQjGuyAztf501jX1Bf+yzFgQIedLRYJrwaM18K RrBR0qFSDOVIXnqOL4p+Juft+dag0062mdhh4NlgCfgaA6bA1xzrKe8AXqVDkmrc5B 66RCrTnMI6iNkMdCDdKUBFN6zeh8tzDm7gFjw5XgFCAdKPCG2xikfgCzABRROKUOuY ywJlBIEosZK4fQd3OqfDasEeE/rU0KoQUyzl77HNF7SY8fCQv8nRf2gGy3r6dbdwj7 ujZgHOcmQ7Gtw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4D98B69B01; Sun, 15 Feb 2026 18:35:50 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id mlrVwQm4NwJu; Sun, 15 Feb 2026 18:35:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1771205749; bh=ShJtPLVg4405ZpA6+d6fo+FYgEurxmx/A2gtkun+fI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2KUA5GLEkNGd1pqEtNn/aiKVTzRm7F65hTNn6vRuGfVM942gikBO8/R3AuUS5sYZ HLiF9lDhODitMIftYo7Ts/NXWDvJW/Ex1HS9poB8aVw/u7R8l23xMvpUh0yLk3glIs dbg95QimI2tHvKT1HthcJRC1C6guqAI2CO8eOsuwksIXsjtvBKTwR3pwgeOO3ki6aI gYDpp/+WvHs/YXvxYz26mCcDc+5+ZYeZKOK4Nbz7F5gqOeEHKomstZTvcdP2jb41PO LjMswH9SajGH0R4RhdXdGUEmldZf8XtVRpc0xl8BSks12qJfHjvjD5BRx0/siudPgm hrp30VrLrnMQw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9DC8069AD9; Sun, 15 Feb 2026 18:35:49 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 15 Feb 2026 18:34:55 -0700 Message-ID: <20260216013511.4079770-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260216013511.4079770-1-sjg@u-boot.org> References: <20260216013511.4079770-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7OWPN44RKYT6UIOSPCQ2L5LYSWYSTDMC X-Message-ID-Hash: 7OWPN44RKYT6UIOSPCQ2L5LYSWYSTDMC X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 6" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/17] ulib: arm: Add demo binary and examples for qemu_arm64 List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add build infrastructure to compile and link the ulib demo for ARM64. In this case, arch/arm/Makefile re-links U-Boot with example objects using the u-boot-link helper, so the example's strong main() overrides the weak default, then creates demo-nodtb.bin and appends the devicetree to produce demo.bin Unlike x86 which uses a ROM image, ARM64 produces a binary that is loaded directly via QEMU's -bios parameter. Enable CONFIG_EXAMPLES in qemu_arm64_defconfig so the demo is built by default. Add a pytest which boots demo.bin under qemu-system-aarch64 and verifies the expected output. Also refactor the test code to share QEMU demo helpers between x86 and ARM64: run_qemu_demo() handles subprocess execution with timeout, and assert_demo_output() validates the expected output strings. Co-developed-by: Claude Opus 4.6 Signed-off-by: Simon Glass --- arch/arm/Makefile | 6 ++++ configs/qemu_arm64_defconfig | 2 ++ examples/ulib/Kbuild | 2 +- test/py/tests/test_ulib.py | 68 +++++++++++++++++++++++++++--------- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 90e7d33c881..9c521a11f29 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -124,5 +124,11 @@ ifneq (,$(filter $(SOC), kirkwood)) libs-y += arch/arm/mach-mvebu/ endif +ifdef CONFIG_EXAMPLES +EXAMPLE_ARCH := arm +EXAMPLE_APPEND_DTB := y +include scripts/Makefile.ulib-example +endif + # deprecated -include $(machdirs)/config.mk diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 4e0bfa3a572..507c08bc514 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -76,3 +76,5 @@ CONFIG_TPM_PCR_ALLOCATE=y CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE=y CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y +CONFIG_ULIB=y +CONFIG_EXAMPLES=y diff --git a/examples/ulib/Kbuild b/examples/ulib/Kbuild index 88d6a805b91..f1f0131ae11 100644 --- a/examples/ulib/Kbuild +++ b/examples/ulib/Kbuild @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ # -# Example objects for x86 platforms (compiled via kbuild, not linked into +# Example objects for platform builds (compiled via kbuild, not linked into # u-boot). The standalone Makefile is used for sandbox builds instead. extra-y += demo.o demo_helper.o diff --git a/test/py/tests/test_ulib.py b/test/py/tests/test_ulib.py index b1ce5792801..94d40256c59 100644 --- a/test/py/tests/test_ulib.py +++ b/test/py/tests/test_ulib.py @@ -221,6 +221,39 @@ def test_ulib_api_header(ubman): assert 'ub_snprintf(char *buf, size_t size, const char *fmt, ...)' in out assert 'ub_vprintf(const char *fmt, va_list args)' in out +def assert_demo_output(out): + """Assert that demo output contains expected strings. + + Args: + out (str): Decoded output string from QEMU + """ + assert 'U-Boot Library Demo Helper' in out + assert '==========================' in out + assert 'U-Boot version:' in out + assert 'helper: Adding 42 + 13 = 55' in out + assert '=================================' in out + assert 'Demo complete' in out + +def run_qemu_demo(qemu_cmd): + """Run a ulib demo under QEMU and return output. + + Args: + qemu_cmd (list): QEMU command and arguments (e.g. + ['qemu-system-i386', '-bios', 'demo.rom', ...]) + + Returns: + str: Decoded stdout from QEMU + """ + with subprocess.Popen(qemu_cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) as proc: + try: + stdout, _ = proc.communicate(timeout=5) + except subprocess.TimeoutExpired: + proc.kill() + stdout, _ = proc.communicate() + + return stdout.decode('utf-8', errors='replace') + def run_x86_rom_demo(ubman, qemu_binary): """Boot the demo ROM image under QEMU and check for expected output. @@ -240,23 +273,8 @@ def run_x86_rom_demo(ubman, qemu_binary): assert shutil.which(qemu_binary), f'{qemu_binary} not found' cmd = [qemu_binary, '-bios', demo_rom, '-nographic', '-no-reboot'] - - with subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) as proc: - try: - stdout, _ = proc.communicate(timeout=5) - except subprocess.TimeoutExpired: - proc.kill() - stdout, _ = proc.communicate() - - out = stdout.decode('utf-8', errors='replace') - - assert 'U-Boot Library Demo Helper' in out - assert '==========================' in out - assert 'U-Boot version:' in out - assert 'helper: Adding 42 + 13 = 55' in out - assert '=================================' in out - assert 'Demo complete' in out + out = run_qemu_demo(cmd) + assert_demo_output(out) @pytest.mark.localqemu @pytest.mark.boardspec('qemu-x86') @@ -271,3 +289,19 @@ def test_ulib_demo_rom(ubman): 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') + +@pytest.mark.localqemu +@pytest.mark.boardspec('qemu_arm64') +@pytest.mark.buildconfigspec("examples") +def test_ulib_demo_arm64(ubman): + """Test the ulib demo binary under QEMU ARM64.""" + build = ubman.config.build_dir + demo_bin = os.path.join(build, 'examples', 'ulib', 'demo.bin') + + assert os.path.exists(demo_bin), 'demo.bin not found in build directory' + assert shutil.which('qemu-system-aarch64'), 'qemu-system-aarch64 not found' + + cmd = ['qemu-system-aarch64', '-machine', 'virt', '-cpu', 'cortex-a57', + '-nographic', '-no-reboot', '-bios', demo_bin] + out = run_qemu_demo(cmd) + assert_demo_output(out)