
From: Simon Glass <sjg@chromium.org> Add a simple test of a filesystem on sandbox. Signed-off-by: Simon Glass <sjg@chromium.org> --- MAINTAINERS | 2 ++ arch/sandbox/dts/test.dts | 13 ++++++++ drivers/virtio/virtio_sandbox.c | 3 ++ fs/fs-uclass.c | 4 ++- fs/sandbox/sandboxfs.c | 59 +++++++++++++++++++++++++++++++++ include/dt-bindings/virtio.h | 1 + test/boot/bootdev.c | 5 ++- test/dm/Makefile | 1 + test/dm/fs.c | 28 ++++++++++++++++ 9 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 test/dm/fs.c diff --git a/MAINTAINERS b/MAINTAINERS index 08b57e5306e..14a0e2a9de3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1186,7 +1186,9 @@ FILESYSTEM LAYER M: Simon Glass <sjg@chromium.org> S: Maintained F: fs/fs-uclass.c +F: fs/sandbox/sandboxfs.c F: include/fs.h +F: test/dm/fs.c FPGA M: Michal Simek <michal.simek@amd.com> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index c880cc56818..760153f99a3 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -575,6 +575,10 @@ compatible = "denx,u-boot-devres-test"; }; + fs { + compatible = "sandbox,fs"; + }; + another-test { reg = <0 2>; compatible = "denx,u-boot-fdt-test"; @@ -1712,6 +1716,15 @@ }; }; + sandbox-virtio-fs { + compatible = "sandbox,virtio1"; + virtio-type = <VIRTIO_ID_FS>; + + virtio-fs { + compatible = "virtio,fs"; + }; + }; + sandbox_scmi { compatible = "sandbox,scmi-devices"; power-domains = <&pwrdom_scmi 2>; diff --git a/drivers/virtio/virtio_sandbox.c b/drivers/virtio/virtio_sandbox.c index 0f1ebef22e5..857acd672ca 100644 --- a/drivers/virtio/virtio_sandbox.c +++ b/drivers/virtio/virtio_sandbox.c @@ -219,4 +219,7 @@ U_BOOT_DRIVER(virtio_sandbox2) = { .ops = &virtio_sandbox2_ops, .probe = virtio_sandbox_probe, .priv_auto = sizeof(struct virtio_sandbox_priv), +#if CONFIG_IS_ENABLED(OF_REAL) + .bind = dm_scan_fdt_dev, +#endif }; diff --git a/fs/fs-uclass.c b/fs/fs-uclass.c index 9e698972df8..d92b0e24538 100644 --- a/fs/fs-uclass.c +++ b/fs/fs-uclass.c @@ -5,7 +5,6 @@ * Copyright 2025 Simon Glass <sjg@chromium.org> */ -#define LOG_DEBUG #define LOG_CATEGORY UCLASS_FS #include <bootdev.h> @@ -45,6 +44,9 @@ static int fs_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, log_debug("get_bootflow fs '%s'\n", fsdev->name); + /* for now, always fail here as we don't have FS support in bootmeths */ + return -ENOENT; + ret = bootmeth_check(bflow->method, iter); if (ret) return log_msg_ret("check", ret); diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index bfb30ef47fe..74c94528cf4 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -1,14 +1,24 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Provides access to the host filesystem from sandbox + * * Copyright (c) 2012, Google Inc. */ +#include <dm.h> #include <stdio.h> +#include <fs.h> #include <fs_legacy.h> #include <malloc.h> #include <os.h> #include <sandboxfs.h> +/** + * struct sandbox_fs_priv - Private info about the sandbox filesystem + */ +struct sandbox_fs_priv { +}; + int sandbox_fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info) { /* @@ -142,3 +152,52 @@ int fs_write_sandbox(const char *filename, void *buf, loff_t offset, return ret; } + +static int sandbox_fs_mount(struct udevice *dev) +{ + struct fs_priv *uc_priv = dev_get_uclass_priv(dev); + + if (uc_priv->mounted) + return log_msg_ret("vfi", -EISCONN); + + uc_priv->mounted = true; + + return 0; +} + +static int sandbox_fs_unmount(struct udevice *dev) +{ + struct fs_priv *uc_priv = dev_get_uclass_priv(dev); + + if (!uc_priv->mounted) + return log_msg_ret("vfu", -ENOTCONN); + + uc_priv->mounted = false; + + return 0; +} + +static int sandbox_fs_remove(struct udevice *dev) +{ + return 0; +} + +static const struct fs_ops sandbox_fs_ops = { + .mount = sandbox_fs_mount, + .unmount = sandbox_fs_unmount, +}; + +static const struct udevice_id sandbox_fs_ids[] = { + { .compatible = "sandbox,fs" }, + { } +}; + +U_BOOT_DRIVER(sandbox_fs) = { + .name = "sandbox_fs", + .id = UCLASS_FS, + .of_match = sandbox_fs_ids, + .ops = &sandbox_fs_ops, + .remove = sandbox_fs_remove, + .priv_auto = sizeof(struct sandbox_fs_priv), + .flags = DM_FLAG_ACTIVE_DMA, +}; diff --git a/include/dt-bindings/virtio.h b/include/dt-bindings/virtio.h index 9e3fea14567..8de4a9efcfa 100644 --- a/include/dt-bindings/virtio.h +++ b/include/dt-bindings/virtio.h @@ -15,5 +15,6 @@ #define VIRTIO_ID_BLOCK 2 /* virtio block */ #define VIRTIO_ID_RNG 4 /* virtio rng */ #define VIRTIO_ID_MAX_NUM 27 +#define VIRTIO_ID_FS 26 /* virtio filesystem */ #endif diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index a578af5ccf0..b1966f7d72c 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -365,7 +365,7 @@ static int bootdev_test_prio(struct unit_test_state *uts) ut_asserteq(0, bootflow_scan_next(&iter, &bflow)); ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); - ut_asserteq(8, iter.num_devs); + ut_asserteq(9, iter.num_devs); ut_asserteq_str("hub1.p1.usb_mass_storage.lun0.bootdev", iter.dev_used[0]->name); ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); @@ -754,6 +754,9 @@ static int bootdev_test_next_prio(struct unit_test_state *uts) ut_asserteq_str("mmc0.bootdev", dev->name); ut_assert_console_end(); + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_assert_nextline("Hunting with: fs"); + ut_assertok(bootdev_next_prio(&iter, &dev)); ut_asserteq_str("spi.bin@0.bootdev", dev->name); ut_assert_skip_to_line("Hunting with: spi_flash"); diff --git a/test/dm/Makefile b/test/dm/Makefile index 7ddd3e78e23..eab78d3ac4a 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_CROS_EC) += cros_ec.o +obj-$(CONFIG_FS) += fs.o obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o obj-$(CONFIG_$(PHASE_)DEVRES) += devres.o obj-$(CONFIG_DMA) += dma.o diff --git a/test/dm/fs.c b/test/dm/fs.c new file mode 100644 index 00000000000..d82d2250c59 --- /dev/null +++ b/test/dm/fs.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for the filesystems layer + * + * Copyright 2025 Simon Glass <sjg@chromium.org> + */ + +#include <dm.h> +#include <fs.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Test basic filesystem access */ +static int dm_test_fs_base(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_first_device_err(UCLASS_FS, &dev)); + + ut_assertok(fs_mount(dev)); + ut_asserteq(-EISCONN, fs_mount(dev)); + + ut_assertok(fs_unmount(dev)); + ut_asserteq(-ENOTCONN, fs_unmount(dev)); + + return 0; +} +DM_TEST(dm_test_fs_base, UTF_SCAN_FDT); -- 2.43.0