From patchwork Fri Jan 9 01:53:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1370 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=1767923656; bh=44BMBgtj66IiteBbw/u9KBVMQcVuSP/kf3KgukIIsw4=; 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=E45vNt1ycfO8vfVUmNR/nosdoY58c0vn1E3oUKjZDIp48a1tf/aQBuP7Aabgl/qMX nwXEDMVymfBacIOlb8CjdHfyc6ZKwleAsWkqzE1HQLoVRuyq76q5sGeQYrTpiJ5Bwe TEtgtmOYesw0BV1hS1UsUUy9IKZklQNnha42lQsB8J17/MEQkGGUs8oteVmQmMPe/3 ER/f/shXdkn17PvzNbij9BX4lvceCXTGrMPZU6xgecpOSmY5c18z/kWrxCt5D6U4qc LUmtTbmMj0tI0WeCBmkjEcBnFqSjBt11n+KGEPiKZcW3Mlv39VJcvhe9on41S8uH8r d3QPVJV+XwAHg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E3183691FE for ; Thu, 8 Jan 2026 18:54:16 -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 0L3rmymQMEIL for ; Thu, 8 Jan 2026 18:54:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923656; bh=44BMBgtj66IiteBbw/u9KBVMQcVuSP/kf3KgukIIsw4=; 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=E45vNt1ycfO8vfVUmNR/nosdoY58c0vn1E3oUKjZDIp48a1tf/aQBuP7Aabgl/qMX nwXEDMVymfBacIOlb8CjdHfyc6ZKwleAsWkqzE1HQLoVRuyq76q5sGeQYrTpiJ5Bwe TEtgtmOYesw0BV1hS1UsUUy9IKZklQNnha42lQsB8J17/MEQkGGUs8oteVmQmMPe/3 ER/f/shXdkn17PvzNbij9BX4lvceCXTGrMPZU6xgecpOSmY5c18z/kWrxCt5D6U4qc LUmtTbmMj0tI0WeCBmkjEcBnFqSjBt11n+KGEPiKZcW3Mlv39VJcvhe9on41S8uH8r d3QPVJV+XwAHg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CB62269130 for ; Thu, 8 Jan 2026 18:54:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923654; bh=+niLABB1Wr7vxG2f+9ITN9q8BZU14Oz8DMWR1qHLhQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFE74V2449s7OZ75ZGqwfuFN9LvYwlPzQQmEAiPo+fia7FjDgYXxqD9LT4dxz8K9Q +PdQ7QOODx0CvfbI/iauax/Gd+zn9FdboLbV9k0egUjWynv3itEIJF4A0zv1SQngaf AzaQWVj1V79iMFOG3ouix3R8iGnopFZFFid6K2C4BsnK2vNp2Aq4+A9n4mCKYPjARJ P4jaSW4bif62YCDS5zpy4bL1yvid4YbS1/NaiHHkolreNMuA1i8r9zpEbkperXNawx ycQABI9AAhnf8nlkYQoLtbv+O041kyL/rQrJg4cPwd8f1CCgC8MfEWKLxCrn6peywa +2+lVNpRpFy4Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0590B69130; Thu, 8 Jan 2026 18:54:14 -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 exCDQnlVXf0W; Thu, 8 Jan 2026 18:54:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767923653; bh=Srf1V7D6ClUcLNWA0itP/jKvfjq3RxQqxgFALcJp+aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNrYwfphoBQzw+UPa+wrZ1yYgeElOw4uLbEF9RTpxyh0zTP2exDK/nPG7OLidfceq U7JM3bNddhhpVhospSoqociR6kcEx0VulSL6Fx1hsPuyCrCJ0l1ptlQ39N1+pAE9xt ivnDbCfSBrgKKyVx5V4/MDL+FfyKahgekFsJBtNLlzgELHU4n7uZ0zRk3307ItOT+I wM0+nOPHEITom0tv3sTuUxQrQ9c3BJv7QXSIFli0AV4AGLjU5iRPdu1nFiSRW6NaSm H6my6NHhIAttO41tYaGNaWbEGnDjKXt87+6+BnXaNpa0d21j+UNzIRzaWFoYfuukEr gVaagD1lynzmQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5AEC46912D; Thu, 8 Jan 2026 18:54:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 8 Jan 2026 18:53:09 -0700 Message-ID: <20260109015323.3411528-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109015323.3411528-1-sjg@u-boot.org> References: <20260109015323.3411528-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: J22RQZOJJIQINEYVERUEWKP5HJRJIPI7 X-Message-ID-Hash: J22RQZOJJIQINEYVERUEWKP5HJRJIPI7 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 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/16] boot: pxe: Add a test for fdtdir path-resolution 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 a test that verifies fdtdir path-construction via sysboot: - fdtdir with fdtfile env var uses the variable directly - fdtdir with soc/board env vars constructs {soc}-{board}.dtb The test runs sysboot twice with different environment settings and checks console output to verify the correct FDT paths are constructed. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- test/boot/pxe.c | 93 ++++++++++++++++++++++++++++++++ test/py/tests/test_pxe_parser.py | 65 ++++++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/test/boot/pxe.c b/test/boot/pxe.c index 3d560fd9ade..a924247bf98 100644 --- a/test/boot/pxe.c +++ b/test/boot/pxe.c @@ -318,3 +318,96 @@ static int pxe_test_sysboot_norun(struct unit_test_state *uts) PXE_TEST_ARGS(pxe_test_sysboot_norun, UTF_CONSOLE | UTF_MANUAL, { "fs_image", UT_ARG_STR }, { "cfg_path", UT_ARG_STR }); + +/** + * Test fdtdir path resolution via sysboot + * + * This test verifies fdtdir path construction by running sysboot and + * checking console output: + * 1. fdtdir with fdtfile env var - uses fdtfile value directly + * 2. fdtdir with soc/board env vars - constructs {soc}-{board}.dtb + * 3. fdtdir without trailing slash - slash is inserted + */ +static int pxe_test_fdtdir_norun(struct unit_test_state *uts) +{ + const char *fs_image = ut_str(PXE_ARG_FS_IMAGE); + const char *cfg_path = ut_str(PXE_ARG_CFG_PATH); + void *fdt; + + ut_assertnonnull(fs_image); + ut_assertnonnull(cfg_path); + + /* Bind the filesystem image */ + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + + /* + * Test 1: fdtdir with fdtfile env var + * The first label uses fdtdir=/dtb/ and we set fdtfile=test-board.dtb + * so it should retrieve /dtb/test-board.dtb + */ + ut_assertok(env_set_hex("pxefile_addr_r", PXE_LOAD_ADDR)); + ut_assertok(env_set_hex("kernel_addr_r", PXE_KERNEL_ADDR)); + ut_assertok(env_set_hex("fdt_addr_r", PXE_FDT_ADDR)); + ut_assertok(env_set_hex("fdtoverlay_addr_r", PXE_OVERLAY_ADDR)); + ut_assertok(env_set("fdtfile", "test-board.dtb")); + ut_assertok(env_set("bootfile", cfg_path)); + + ut_assertok(run_commandf("sysboot host 0:0 any %x %s", + PXE_LOAD_ADDR, cfg_path)); + + /* Skip to the boot attempt - first label is fdtfile-test */ + ut_assert_skip_to_line("Enter choice: 1:\tTest fdtfile env var"); + + /* Verify fdtdir used fdtfile env var to construct path */ + ut_assert_nextline("Retrieving file: /vmlinuz"); + ut_assert_nextline("append: console=ttyS0"); + ut_assert_nextline("Retrieving file: /dtb/test-board.dtb"); + ut_assert_nextline("Retrieving file: /dtb/overlay1.dtbo"); + + /* Boot fails but we verified the path construction */ + ut_assert_nextline("Unrecognized zImage"); + ut_assert_nextlinen(" unmap_physmem"); + + /* Verify FDT was loaded correctly */ + fdt = map_sysmem(PXE_FDT_ADDR, 0); + ut_assertok(fdt_check_header(fdt)); + + /* + * Test 2: fdtdir with soc/board env vars (no fdtfile) + * Clear fdtfile and set soc/board - the default label (fdtfile-test) + * will now construct the path from soc-board: /dtb/tegra-jetson.dtb + */ + ut_assertok(env_set("fdtfile", NULL)); /* Clear fdtfile */ + ut_assertok(env_set("soc", "tegra")); + ut_assertok(env_set("board", "jetson")); + + ut_assertok(run_commandf("sysboot host 0:0 any %x %s", + PXE_LOAD_ADDR, cfg_path)); + + /* Still boots default label, but now uses soc-board path construction */ + ut_assert_skip_to_line("Enter choice: 1:\tTest fdtfile env var"); + + /* Verify fdtdir constructed path from soc-board */ + ut_assert_nextline("Retrieving file: /vmlinuz"); + ut_assert_nextline("append: console=ttyS0"); + ut_assert_nextline("Retrieving file: /dtb/tegra-jetson.dtb"); + ut_assert_nextline("Retrieving file: /dtb/overlay1.dtbo"); + + /* Boot fails but we verified the path construction */ + ut_assert_nextline("Unrecognized zImage"); + ut_assert_nextlinen(" unmap_physmem"); + + /* Verify FDT was loaded */ + fdt = map_sysmem(PXE_FDT_ADDR, 0); + ut_asserteq(FDT_MAGIC, fdt_magic(fdt)); + + /* Clean up env vars */ + env_set("fdtfile", NULL); + env_set("soc", NULL); + env_set("board", NULL); + + return 0; +} +PXE_TEST_ARGS(pxe_test_fdtdir_norun, UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }, + { "cfg_path", UT_ARG_STR }); diff --git a/test/py/tests/test_pxe_parser.py b/test/py/tests/test_pxe_parser.py index c2467f70f5d..ee8acb8c674 100644 --- a/test/py/tests/test_pxe_parser.py +++ b/test/py/tests/test_pxe_parser.py @@ -269,6 +269,64 @@ def pxe_image(u_boot_config): fsh.cleanup() +@pytest.fixture +def pxe_fdtdir_image(u_boot_config): + """Create a filesystem image with fdtdir-based configuration + + This tests the fdtdir path-resolution logic where the FDT filename + is constructed from environment variables. + """ + fsh = FsHelper(u_boot_config, 'vfat', 4, prefix='pxe_fdtdir') + fsh.setup() + + # Create labels using fdtdir instead of explicit fdt path + labels = [ + { + 'name': 'fdtfile-test', + 'menu': 'Test fdtfile env var', + 'kernel': '/vmlinuz', + 'append': 'console=ttyS0', + 'fdtdir': '/dtb/', # Will use fdtfile env var + 'fdtoverlays': '/dtb/overlay1.dtbo', + 'default': True, + }, + { + 'name': 'socboard-test', + 'menu': 'Test soc/board construction', + 'kernel': '/vmlinuz', + 'append': 'console=ttyS0', + 'fdtdir': '/dtb', # No trailing slash - tests slash insertion + }, + ] + + cfg_path = create_extlinux_conf(fsh.srcdir, labels) + + # Create DTB directory with files for different naming conventions + dtbdir = os.path.join(fsh.srcdir, 'dtb') + os.makedirs(dtbdir, exist_ok=True) + + # DTB for fdtfile env var test (fdtfile=test-board.dtb) + compile_dts(BASE_DTS, os.path.join(dtbdir, 'test-board.dtb')) + + # DTB for soc-board construction (soc=tegra, board=jetson) + compile_dts(BASE_DTS, os.path.join(dtbdir, 'tegra-jetson.dtb')) + + # Overlay for fdtdir test + compile_dts(OVERLAY1_DTS, os.path.join(dtbdir, 'overlay1.dtbo'), + is_overlay=True) + + # Create dummy kernel + with open(os.path.join(fsh.srcdir, 'vmlinuz'), 'wb') as fd: + fd.write(b'kernel') + fd.write(b'\x00' * (1024 - 6)) + + fsh.mk_fs() + + yield fsh.fs_img, cfg_path + + fsh.cleanup() + + @pytest.mark.boardspec('sandbox') @pytest.mark.requiredtool('dtc') class TestPxeParser: @@ -287,3 +345,10 @@ class TestPxeParser: with ubman.log.section('Test PXE sysboot'): ubman.run_ut('pxe', 'pxe_test_sysboot', fs_image=fs_img, cfg_path=cfg_path) + + def test_pxe_fdtdir(self, ubman, pxe_fdtdir_image): + """Test fdtdir path resolution with fdtfile and soc/board env vars""" + fs_img, cfg_path = pxe_fdtdir_image + with ubman.log.section('Test PXE fdtdir'): + ubman.run_ut('pxe', 'pxe_test_fdtdir', + fs_image=fs_img, cfg_path=cfg_path)