From 5b1dac9ee2029c6aa9fe4f8554f2250b94b89da2 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Wed, 15 Jul 2026 18:57:15 +0200 Subject: fs: dispatch null_dev_desc_ok filesystems before lookup Filesystems that are null_dev_desc_ok (semihosting, ubifs) have no UCLASS_BLK device under their ifname, so on real hardware fs_set_blk_dev() always fails at the partition lookup. The workaround was to add a per-filesystem command (example cmd/ubifs.c), which duplicates the plumbing of fstype_info. Probe such entries with block_desc=NULL up front, so load semihosting - works without a new command. Sandbox boards that exercise the existing fallback through "host bind" stay unchanged. Signed-off-by: Vincent Jardin Reviewed-by: Simon Glass --- fs/fs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 8ea50a6c13c..56f3e0c9204 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -459,11 +459,53 @@ const char *fs_get_type_name(void) return fs_get_info(fs_type)->name; } +/* + * Some fstypes (semihosting, ubifs) have no underlying block device + * and ignore the block_desc argument of their probe hook. The legacy + * commands (ubifsload, semihosting via env macros) just pass NULL; + * for "load ..." to behave the same, the dispatcher opts + * those fstypes in by name here, before any block-device lookup is + * attempted. + * + * Returns the matching fstype_info if @ifname names a fstype that + * opts into null_dev_desc_ok dispatch and the caller's @fstype filter + * permits it. Returns NULL otherwise. + */ +static struct fstype_info *fs_lookup_null_dev_info(const char *ifname, + int fstype) +{ + struct fstype_info *info; + int i; + + for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { + if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY && + fstype != info->fstype) + continue; + if (!info->null_dev_desc_ok || !info->name) + continue; + if (!strcmp(info->name, ifname)) + return info; + } + + return NULL; +} + int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) { struct fstype_info *info; int part, i; + info = fs_lookup_null_dev_info(ifname, fstype); + if (info) { + fs_dev_desc = NULL; + memset(&fs_partition, 0, sizeof(fs_partition)); + if (!info->probe(NULL, &fs_partition)) { + fs_type = info->fstype; + fs_dev_part = 0; + return 0; + } + } + part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc, &fs_partition, 1); if (part < 0) -- cgit v1.3.1 From c23eeeadfc4a2f351f056bc1d12b210a5fb9c3e9 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Wed, 15 Jul 2026 18:57:16 +0200 Subject: doc: usage: cmd: load: null-block-device Document the dispatch path added by the former commit fs: dispatch null_dev_desc_ok filesystems before lookup Add a null-block-device interfaces section that: * lists the three fstypes that can benefit of it (semihosting, ubifs, sandbox) and the CONFIG option that builds each * explains the '-' convention for the unused field Suggested-by: Simon Glass Signed-off-by: Vincent Jardin Reviewed-by: Simon Glass --- doc/usage/cmd/load.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/doc/usage/cmd/load.rst b/doc/usage/cmd/load.rst index bfa45c6f36c..bf2fffbed21 100644 --- a/doc/usage/cmd/load.rst +++ b/doc/usage/cmd/load.rst @@ -63,6 +63,39 @@ Example 16 bytes read in 1 ms (15.6 KiB/s) => +Null-block-device interfaces +---------------------------- + +A few ```` values have no underlying block device. Their +filesystem implementations directly call a back-end (JTAG +debugger, UBI volume, host running U-Boot under sandbox, ...) and +ignore the ```` field, which may be given as ``-``. So +``load - `` works. + +semihosting + Read files from the host filesystem of an attached JTAG debugger + using the ARM semihosting protocol. Useful with OpenOCD. + Built when ``CONFIG_SEMIHOSTING=y``. + +ubifs + Read files from a UBIFS volume that has already been attached + and mounted with the ``ubi part`` + ``ubifsmount`` commands. + Built when ``CONFIG_CMD_UBIFS=y``. + +sandbox + Read files from the host filesystem the sandbox binary is + running under. Available on sandbox builds. + +The ```` argument is conventionally written as ``-`` for +these interfaces, to make it visible at the call site that the field +is unused. The filesystem layer never looks at it. + +Example:: + + => load semihosting - ${kernel_addr_r} kernel.itb + 9437184 bytes read in 412 ms (21.8 MiB/s) + => + Configuration ------------- -- cgit v1.3.1 From 0ccf0193a58120f7a898a4379434b481be41b9f6 Mon Sep 17 00:00:00 2001 From: Vincent Jardin Date: Wed, 15 Jul 2026 18:57:17 +0200 Subject: test: py: load: check null_dev_desc_ok dispatch Some pytest modules exercising the dispatch added by fs: dispatch null_dev_desc_ok filesystems before lookup test_load_semihosting.py: "load semihosting - " and the optional [bytes] [pos] variant. Runs on qemu_arm64 with CONFIG_SEMIHOSTING=y; reuses test_hostfs.py's host-staged fixture. test_load_sandbox.py: "load sandbox - " and the optional [bytes] [pos] variant. Runs on sandbox (boardspec('sandbox')); the sandbox fstype is registered with name="sandbox" and null_dev_desc_ok=true, so the same fs_lookup_null_dev_info() helper that routes semihosting also routes the "sandbox". A "load ubifs - " test is intentionally not provided. UBIFS is built on UBI on MTD, which requires some additional works that are not available with qemu/sandbox-ing. Signed-off-by: Vincent Jardin Reviewed-by: Simon Glass --- test/py/tests/test_load_sandbox.py | 51 ++++++++++++++++++++++ test/py/tests/test_semihosting/conftest.py | 4 +- .../test_semihosting/test_load_semihosting.py | 38 ++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 test/py/tests/test_load_sandbox.py create mode 100644 test/py/tests/test_semihosting/test_load_semihosting.py diff --git a/test/py/tests/test_load_sandbox.py b/test/py/tests/test_load_sandbox.py new file mode 100644 index 00000000000..8d28a630e76 --- /dev/null +++ b/test/py/tests/test_load_sandbox.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2026 Free Mobile - Vincent Jardin + +"""Regression test for `load sandbox - `. + +Exercises the null_dev_desc_ok dispatch added in +"fs: dispatch null_dev_desc_ok filesystems before block lookup". + +It is the counterpart of test_load_semihosting.py +""" + +import os +import pytest + + +@pytest.fixture(scope='session') +def sandbox_fixture(u_boot_config): + """Host-staged fixture file read by `load sandbox`.""" + path = os.path.join(u_boot_config.persistent_data_dir, + 'sandbox-fstype.txt') + with open(path, 'w', encoding='utf-8') as f: + f.write('Das U-Boot\n') # 11 bytes, same as test_hostfs.py / semihosting + yield path + os.remove(path) + + +@pytest.mark.boardspec('sandbox') +def test_sandbox_load(ubman, sandbox_fixture): + """Run `load sandbox - ` and check the bytes.""" + response = ubman.run_command( + f'load sandbox - $loadaddr {sandbox_fixture}') + + # Fixture is "Das U-Boot\n" (11 bytes). + assert '11 bytes read' in response + + # crc32("Das U-Boot\n") -- identical to the semihosting / hostfs checks. + response = ubman.run_command('crc32 $loadaddr $filesize') + assert '==> 60cfccfc' in response + + +@pytest.mark.boardspec('sandbox') +def test_sandbox_load_offset(ubman, sandbox_fixture): + """Run the [bytes] [pos] variant through the same dispatch.""" + response = ubman.run_command( + f'load sandbox - $loadaddr {sandbox_fixture} 4 6') + # bytes=4 pos=6 over "Das U-Boot\n" -> "Boot". + assert '4 bytes read' in response + + # crc32("Boot") + response = ubman.run_command('crc32 $loadaddr $filesize') + assert '==> e6df01fa' in response diff --git a/test/py/tests/test_semihosting/conftest.py b/test/py/tests/test_semihosting/conftest.py index b00d8f4ea9c..6b7f3f3c2d9 100644 --- a/test/py/tests/test_semihosting/conftest.py +++ b/test/py/tests/test_semihosting/conftest.py @@ -6,9 +6,9 @@ import os import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope='function') def semihosting_data(u_boot_config): - """Set up a file system to be used in semihosting tests + """Set up a new file for each semihosting test Args: u_boot_config -- U-Boot configuration. diff --git a/test/py/tests/test_semihosting/test_load_semihosting.py b/test/py/tests/test_semihosting/test_load_semihosting.py new file mode 100644 index 00000000000..7c2eb72c69a --- /dev/null +++ b/test/py/tests/test_semihosting/test_load_semihosting.py @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2026 Free Mobile - Vincent Jardin + +"""Regression test for `load semihosting - `. + +Companion to test_hostfs.py: same fixture, same crc32, different +fstype routing: +see the doc/usage/cmd/load.rst "Null-block-device interfaces" section. +""" + +import pytest + + +@pytest.mark.buildconfigspec('semihosting') +def test_semihosting_load(ubman, semihosting_data): + """Run `load semihosting - ` and check the bytes.""" + response = ubman.run_command( + f'load semihosting - $loadaddr {semihosting_data}') + + # Fixture is "Das U-Boot\n" (11 bytes). + assert '11 bytes read' in response + + # crc32("Das U-Boot\n") + response = ubman.run_command('crc32 $loadaddr $filesize') + assert '==> 60cfccfc' in response + + +@pytest.mark.buildconfigspec('semihosting') +def test_semihosting_load_offset(ubman, semihosting_data): + """Run the [bytes] [pos] variant through the same dispatch.""" + response = ubman.run_command( + f'load semihosting - $loadaddr {semihosting_data} 4 6') + # bytes=4 pos=6 over "Das U-Boot\n" -> "Boot". + assert '4 bytes read' in response + + # crc32("Boot") + response = ubman.run_command('crc32 $loadaddr $filesize') + assert '==> e6df01fa' in response -- cgit v1.3.1