From f67dd39bb290fc28a03a1ab86265090e0ed0512a Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Fri, 7 Jul 2023 00:30:04 +0200 Subject: [PATCH] drivers: ramdisk: use devicetree to instantiate RAM disk Rework RAM disk driver to be configured using devicetree and support multiple instances. This patch also removes a copy of the RAM disk driver, tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c, that was there for testing multiple disk drivers support. Bonus: one SYS_INIT() less and a memory region can be exported to the host. Signed-off-by: Johann Fischer --- doc/connectivity/usb/device/usb_device.rst | 9 +- drivers/disk/Kconfig.ram | 13 +- drivers/disk/ramdisk.c | 113 ++++++++++++++---- dts/bindings/disk/zephyr,ram-disk.yaml | 35 ++++++ samples/subsys/fs/format/prj_ram.conf | 2 - samples/subsys/fs/format/ramdisk.overlay | 14 +++ samples/subsys/fs/format/sample.yaml | 4 +- .../cdc_acm/overlay-composite-cdc-msc.conf | 3 - samples/subsys/usb/cdc_acm/ramdisk.overlay | 14 +++ samples/subsys/usb/cdc_acm/sample.yaml | 4 +- samples/subsys/usb/mass/Kconfig | 5 - samples/subsys/usb/mass/ramdisk.overlay | 14 +++ samples/subsys/usb/mass/sample.yaml | 12 +- .../disk_access/boards/qemu_x86_64.overlay | 7 ++ tests/drivers/disk/disk_access/src/main.c | 2 +- tests/drivers/disk/disk_access/testcase.yaml | 2 - .../drivers/disk/disk_performance/src/main.c | 2 - tests/posix/fs/app.overlay | 14 +++ tests/posix/fs/prj.conf | 2 - tests/subsys/fs/ext2/prj.conf | 1 - tests/subsys/fs/ext2/prj_big.conf | 1 - tests/subsys/fs/ext2/ramdisk_big.overlay | 14 +++ tests/subsys/fs/ext2/ramdisk_small.overlay | 14 +++ tests/subsys/fs/ext2/testcase.yaml | 6 +- .../fs/fat_fs_api/prj_native_posix_ram.conf | 1 - tests/subsys/fs/fat_fs_api/ramdisk.overlay | 14 +++ tests/subsys/fs/fat_fs_api/src/test_fat.h | 2 +- tests/subsys/fs/fat_fs_api/testcase.yaml | 4 +- tests/subsys/fs/fat_fs_dual_drive/app.overlay | 21 ++++ tests/subsys/fs/fat_fs_dual_drive/prj.conf | 1 - .../src/disk_access_test_drv.c | 97 --------------- tests/subsys/fs/multi-fs/prj.conf | 2 - tests/subsys/fs/multi-fs/prj_fs_shell.conf | 2 - tests/subsys/fs/multi-fs/ramdisk.overlay | 14 +++ tests/subsys/fs/multi-fs/testcase.yaml | 6 +- 35 files changed, 298 insertions(+), 173 deletions(-) create mode 100644 dts/bindings/disk/zephyr,ram-disk.yaml create mode 100644 samples/subsys/fs/format/ramdisk.overlay create mode 100644 samples/subsys/usb/cdc_acm/ramdisk.overlay create mode 100644 samples/subsys/usb/mass/ramdisk.overlay create mode 100644 tests/posix/fs/app.overlay create mode 100644 tests/subsys/fs/ext2/ramdisk_big.overlay create mode 100644 tests/subsys/fs/ext2/ramdisk_small.overlay create mode 100644 tests/subsys/fs/fat_fs_api/ramdisk.overlay create mode 100644 tests/subsys/fs/fat_fs_dual_drive/app.overlay delete mode 100644 tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c create mode 100644 tests/subsys/fs/multi-fs/ramdisk.overlay diff --git a/doc/connectivity/usb/device/usb_device.rst b/doc/connectivity/usb/device/usb_device.rst index 6b17e2ec2ca..752d6392077 100644 --- a/doc/connectivity/usb/device/usb_device.rst +++ b/doc/connectivity/usb/device/usb_device.rst @@ -286,10 +286,11 @@ access and expose a RAM disk, emulated block device on a flash partition, or SD Card to the host. Only one disk instance can be exported at a time. The disc to be used by the implementation is set by the -:kconfig:option:`CONFIG_MASS_STORAGE_DISK_NAME` and should be equal to one -of the options used by the disc access driver that the application wants to expose to -the host, :kconfig:option:`CONFIG_DISK_RAM_VOLUME_NAME`, -:kconfig:option:`CONFIG_MMC_VOLUME_NAME`, or :kconfig:option:`CONFIG_SDMMC_VOLUME_NAME`. +:kconfig:option:`CONFIG_MASS_STORAGE_DISK_NAME` and should be the same as the name +used by the disc access driver that the application wants to expose to the host. +SD card disk drivers use options :kconfig:option:`CONFIG_MMC_VOLUME_NAME` or +:kconfig:option:`CONFIG_SDMMC_VOLUME_NAME`, and flash and RAM disk drivers use +node property ``disk-name`` to set the disk name. For the emulated block device on a flash partition, the flash partition and flash disk to be used must be described in the devicetree. If a storage partition diff --git a/drivers/disk/Kconfig.ram b/drivers/disk/Kconfig.ram index b662c41fa3a..f09bd3af45f 100644 --- a/drivers/disk/Kconfig.ram +++ b/drivers/disk/Kconfig.ram @@ -3,6 +3,7 @@ config DISK_DRIVER_RAM bool "RAM Disk" + default y if DT_HAS_ZEPHYR_RAM_DISK_ENABLED help RAM buffer used to emulate storage disk. This option can be used to test the file @@ -10,18 +11,6 @@ config DISK_DRIVER_RAM if DISK_DRIVER_RAM -config DISK_RAM_VOLUME_SIZE - int "RAM Disk size in kilobytes" - default 96 - help - Size of the RAM Disk. - -config DISK_RAM_VOLUME_NAME - string "RAM Disk mount point or drive name" - default "RAM" - help - Disk name as per file system naming guidelines. - module = RAMDISK module-str = ramdisk source "subsys/logging/Kconfig.template.log_config" diff --git a/drivers/disk/ramdisk.c b/drivers/disk/ramdisk.c index 7c9c8789c85..1d1fcc46a0d 100644 --- a/drivers/disk/ramdisk.c +++ b/drivers/disk/ramdisk.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2016 Intel Corporation. - * Copyright (c) 2021, Nordic Semiconductor ASA + * Copyright (c) 2021,2023 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,15 +15,25 @@ LOG_MODULE_REGISTER(ramdisk, CONFIG_RAMDISK_LOG_LEVEL); -#define RAMDISK_SECTOR_SIZE 512 -#define RAMDISK_VOLUME_SIZE (CONFIG_DISK_RAM_VOLUME_SIZE * 1024) -#define RAMDISK_SECTOR_COUNT (RAMDISK_VOLUME_SIZE / RAMDISK_SECTOR_SIZE) +struct ram_disk_data { + struct disk_info info; + const size_t sector_size; + const size_t sector_count; + uint8_t *const buf; +}; -static uint8_t ramdisk_buf[RAMDISK_VOLUME_SIZE]; +struct ram_disk_config { + const size_t sector_size; + const size_t sector_count; + const size_t size; + uint8_t *const buf; +}; -static void *lba_to_address(uint32_t lba) +static void *lba_to_address(const struct device *dev, uint32_t lba) { - return &ramdisk_buf[lba * RAMDISK_SECTOR_SIZE]; + const struct ram_disk_config *config = dev->config; + + return &config->buf[lba * config->sector_size]; } static int disk_ram_access_status(struct disk_info *disk) @@ -39,15 +49,17 @@ static int disk_ram_access_init(struct disk_info *disk) static int disk_ram_access_read(struct disk_info *disk, uint8_t *buff, uint32_t sector, uint32_t count) { + const struct device *dev = disk->dev; + const struct ram_disk_config *config = dev->config; uint32_t last_sector = sector + count; - if (last_sector < sector || last_sector > RAMDISK_SECTOR_COUNT) { - LOG_ERR("Sector %" PRIu32 " is outside the range %u", - last_sector, RAMDISK_SECTOR_COUNT); + if (last_sector < sector || last_sector > config->sector_count) { + LOG_ERR("Sector %" PRIu32 " is outside the range %zu", + last_sector, config->sector_count); return -EIO; } - memcpy(buff, lba_to_address(sector), count * RAMDISK_SECTOR_SIZE); + memcpy(buff, lba_to_address(dev, sector), count * config->sector_size); return 0; } @@ -55,29 +67,33 @@ static int disk_ram_access_read(struct disk_info *disk, uint8_t *buff, static int disk_ram_access_write(struct disk_info *disk, const uint8_t *buff, uint32_t sector, uint32_t count) { + const struct device *dev = disk->dev; + const struct ram_disk_config *config = dev->config; uint32_t last_sector = sector + count; - if (last_sector < sector || last_sector > RAMDISK_SECTOR_COUNT) { - LOG_ERR("Sector %" PRIu32 " is outside the range %u", - last_sector, RAMDISK_SECTOR_COUNT); + if (last_sector < sector || last_sector > config->sector_count) { + LOG_ERR("Sector %" PRIu32 " is outside the range %zu", + last_sector, config->sector_count); return -EIO; } - memcpy(lba_to_address(sector), buff, count * RAMDISK_SECTOR_SIZE); + memcpy(lba_to_address(dev, sector), buff, count * config->sector_size); return 0; } static int disk_ram_access_ioctl(struct disk_info *disk, uint8_t cmd, void *buff) { + const struct ram_disk_config *config = disk->dev->config; + switch (cmd) { case DISK_IOCTL_CTRL_SYNC: break; case DISK_IOCTL_GET_SECTOR_COUNT: - *(uint32_t *)buff = RAMDISK_SECTOR_COUNT; + *(uint32_t *)buff = config->sector_count; break; case DISK_IOCTL_GET_SECTOR_SIZE: - *(uint32_t *)buff = RAMDISK_SECTOR_SIZE; + *(uint32_t *)buff = config->sector_size; break; case DISK_IOCTL_GET_ERASE_BLOCK_SZ: *(uint32_t *)buff = 1U; @@ -89,6 +105,15 @@ static int disk_ram_access_ioctl(struct disk_info *disk, uint8_t cmd, void *buff return 0; } +static int disk_ram_init(const struct device *dev) +{ + struct disk_info *info = dev->data; + + info->dev = dev; + + return disk_access_register(info); +} + static const struct disk_operations ram_disk_ops = { .init = disk_ram_access_init, .status = disk_ram_access_status, @@ -97,15 +122,51 @@ static const struct disk_operations ram_disk_ops = { .ioctl = disk_ram_access_ioctl, }; -static struct disk_info ram_disk = { - .name = CONFIG_DISK_RAM_VOLUME_NAME, - .ops = &ram_disk_ops, -}; +#define DT_DRV_COMPAT zephyr_ram_disk -static int disk_ram_init(void) -{ +#define RAMDISK_DEVICE_SIZE(n) \ + (DT_INST_PROP(n, sector_size) * DT_INST_PROP(n, sector_count)) - return disk_access_register(&ram_disk); -} +#define RAMDISK_DEVICE_CONFIG_DEFINE_MEMREG(n) \ + BUILD_ASSERT(RAMDISK_DEVICE_SIZE(n) <= \ + DT_REG_SIZE(DT_INST_PHANDLE(n, ram_region)), \ + "Disk size is smaller than memory region"); \ + \ + static struct ram_disk_config disk_config_##n = { \ + .sector_size = DT_INST_PROP(n, sector_size), \ + .sector_count = DT_INST_PROP(n, sector_count), \ + .size = RAMDISK_DEVICE_SIZE(n), \ + .buf = UINT_TO_POINTER(DT_REG_ADDR(DT_INST_PHANDLE(n, ram_region))), \ + } -SYS_INIT(disk_ram_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +#define RAMDISK_DEVICE_CONFIG_DEFINE_LOCAL(n) \ + static uint8_t disk_buf_##n[DT_INST_PROP(n, sector_size) * \ + DT_INST_PROP(n, sector_count)]; \ + \ + static struct ram_disk_config disk_config_##n = { \ + .sector_size = DT_INST_PROP(n, sector_size), \ + .sector_count = DT_INST_PROP(n, sector_count), \ + .size = RAMDISK_DEVICE_SIZE(n), \ + .buf = disk_buf_##n, \ + } + +#define RAMDISK_DEVICE_CONFIG_DEFINE(n) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(n, ram_region), \ + (RAMDISK_DEVICE_CONFIG_DEFINE_MEMREG(n)), \ + (RAMDISK_DEVICE_CONFIG_DEFINE_LOCAL(n))) + +#define RAMDISK_DEVICE_DEFINE(n) \ + \ + static struct disk_info disk_info_##n = { \ + .name = DT_INST_PROP(n, disk_name), \ + .ops = &ram_disk_ops, \ + }; \ + \ + RAMDISK_DEVICE_CONFIG_DEFINE(n); \ + \ + DEVICE_DT_INST_DEFINE(n, disk_ram_init, NULL, \ + &disk_info_##n, &disk_config_##n, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + &ram_disk_ops); + +DT_INST_FOREACH_STATUS_OKAY(RAMDISK_DEVICE_DEFINE) diff --git a/dts/bindings/disk/zephyr,ram-disk.yaml b/dts/bindings/disk/zephyr,ram-disk.yaml new file mode 100644 index 00000000000..68b9709cede --- /dev/null +++ b/dts/bindings/disk/zephyr,ram-disk.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: RAM disk + +compatible: "zephyr,ram-disk" + +include: ["base.yaml", "memory-region.yaml"] + +properties: + disk-name: + type: string + required: true + description: | + Disk name. + + sector-size: + type: int + required: true + enum: [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536] + description: | + Disk sector size in bytes. + + sector-count: + type: int + required: true + description: | + Number of sectors. + + ram-region: + type: phandle + description: | + Optional phandle to the memory region to be used as a RAM disk, + if not used a local buffer is defined for each disk instance. + Use it with caution as it makes memory contents easily accessible. diff --git a/samples/subsys/fs/format/prj_ram.conf b/samples/subsys/fs/format/prj_ram.conf index 3604ca153db..feecc2eefd4 100644 --- a/samples/subsys/fs/format/prj_ram.conf +++ b/samples/subsys/fs/format/prj_ram.conf @@ -1,7 +1,5 @@ CONFIG_DISK_ACCESS=y CONFIG_DISK_DRIVERS=y -CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=64 CONFIG_LOG=y CONFIG_LOG_MODE_MINIMAL=y diff --git a/samples/subsys/fs/format/ramdisk.overlay b/samples/subsys/fs/format/ramdisk.overlay new file mode 100644 index 00000000000..b76a5ef6161 --- /dev/null +++ b/samples/subsys/fs/format/ramdisk.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <128>; + }; +}; diff --git a/samples/subsys/fs/format/sample.yaml b/samples/subsys/fs/format/sample.yaml index 0c41105fc63..ca93e00f075 100644 --- a/samples/subsys/fs/format/sample.yaml +++ b/samples/subsys/fs/format/sample.yaml @@ -12,5 +12,7 @@ tests: - native_posix - mimxrt1064_evk build_only: true - extra_args: CONF_FILE="prj_ram.conf" + extra_args: + - CONF_FILE="prj_ram.conf" + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" tags: filesystem diff --git a/samples/subsys/usb/cdc_acm/overlay-composite-cdc-msc.conf b/samples/subsys/usb/cdc_acm/overlay-composite-cdc-msc.conf index a272869511e..6618209fa63 100644 --- a/samples/subsys/usb/cdc_acm/overlay-composite-cdc-msc.conf +++ b/samples/subsys/usb/cdc_acm/overlay-composite-cdc-msc.conf @@ -3,6 +3,3 @@ CONFIG_USB_MASS_STORAGE=y CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y - -#RAM DISK -CONFIG_DISK_DRIVER_RAM=y diff --git a/samples/subsys/usb/cdc_acm/ramdisk.overlay b/samples/subsys/usb/cdc_acm/ramdisk.overlay new file mode 100644 index 00000000000..b76a5ef6161 --- /dev/null +++ b/samples/subsys/usb/cdc_acm/ramdisk.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <128>; + }; +}; diff --git a/samples/subsys/usb/cdc_acm/sample.yaml b/samples/subsys/usb/cdc_acm/sample.yaml index 60d6ab46fff..19e645174f7 100644 --- a/samples/subsys/usb/cdc_acm/sample.yaml +++ b/samples/subsys/usb/cdc_acm/sample.yaml @@ -27,7 +27,9 @@ tests: depends_on: usb_device tags: usb arch_exclude: posix - extra_args: OVERLAY_CONFIG=overlay-composite-cdc-msc.conf + extra_args: + - OVERLAY_CONFIG=overlay-composite-cdc-msc.conf + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" harness: console harness_config: type: one_line diff --git a/samples/subsys/usb/mass/Kconfig b/samples/subsys/usb/mass/Kconfig index eb47261d1c4..e031a4545db 100644 --- a/samples/subsys/usb/mass/Kconfig +++ b/samples/subsys/usb/mass/Kconfig @@ -14,11 +14,9 @@ choice config APP_MSC_STORAGE_NONE bool "Use RAM disk as block device" - imply DISK_DRIVER_RAM config APP_MSC_STORAGE_RAM bool "Use RAM disk and FAT file system" - imply DISK_DRIVER_RAM imply FILE_SYSTEM imply FAT_FILESYSTEM_ELM @@ -42,9 +40,6 @@ config APP_MSC_STORAGE_SDCARD endchoice -config DISK_RAM_VOLUME_SIZE - default 32 if APP_MSC_STORAGE_NONE - config MASS_STORAGE_DISK_NAME default "NAND" if DISK_DRIVER_FLASH default "RAM" if DISK_DRIVER_RAM diff --git a/samples/subsys/usb/mass/ramdisk.overlay b/samples/subsys/usb/mass/ramdisk.overlay new file mode 100644 index 00000000000..ff09a0f8ca7 --- /dev/null +++ b/samples/subsys/usb/mass/ramdisk.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <192>; + }; +}; diff --git a/samples/subsys/usb/mass/sample.yaml b/samples/subsys/usb/mass/sample.yaml index 2e7570a5ae3..9149012a212 100644 --- a/samples/subsys/usb/mass/sample.yaml +++ b/samples/subsys/usb/mass/sample.yaml @@ -2,9 +2,11 @@ sample: name: Mass Storage tests: sample.usb.mass_ram_none: - min_ram: 64 + min_ram: 128 depends_on: usb_device arch_exclude: posix + extra_args: + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" extra_configs: - CONFIG_LOG_DEFAULT_LEVEL=3 tags: @@ -18,12 +20,14 @@ tests: - "No file system selected" - "The device is put in USB mass storage mode." sample.usb_device_next.mass_ram_none: - min_ram: 64 + min_ram: 128 depends_on: usb_device platform_allow: - nrf52840dk_nrf52840 - frdm_k64f - extra_args: CONF_FILE="usbd_next_prj.conf" + extra_args: + - CONF_FILE="usbd_next_prj.conf" + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" extra_configs: - CONFIG_LOG_DEFAULT_LEVEL=3 tags: @@ -40,6 +44,8 @@ tests: min_ram: 128 depends_on: usb_device arch_exclude: posix + extra_args: + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" extra_configs: - CONFIG_LOG_DEFAULT_LEVEL=3 - CONFIG_APP_MSC_STORAGE_RAM=y diff --git a/tests/drivers/disk/disk_access/boards/qemu_x86_64.overlay b/tests/drivers/disk/disk_access/boards/qemu_x86_64.overlay index 1485f30e4d5..65f66de9273 100644 --- a/tests/drivers/disk/disk_access/boards/qemu_x86_64.overlay +++ b/tests/drivers/disk/disk_access/boards/qemu_x86_64.overlay @@ -18,4 +18,11 @@ status = "okay"; }; }; + + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <192>; + }; }; diff --git a/tests/drivers/disk/disk_access/src/main.c b/tests/drivers/disk/disk_access/src/main.c index 3677556ef0c..7dd58359f95 100644 --- a/tests/drivers/disk/disk_access/src/main.c +++ b/tests/drivers/disk/disk_access/src/main.c @@ -19,7 +19,7 @@ #elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC) #define DISK_NAME CONFIG_MMC_VOLUME_NAME #elif IS_ENABLED(CONFIG_DISK_DRIVER_RAM) -#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME +#define DISK_NAME "RAM" #elif IS_ENABLED(CONFIG_NVME) #define DISK_NAME "nvme0n0" #else diff --git a/tests/drivers/disk/disk_access/testcase.yaml b/tests/drivers/disk/disk_access/testcase.yaml index 2dc6cac00af..86c7a365a5f 100644 --- a/tests/drivers/disk/disk_access/testcase.yaml +++ b/tests/drivers/disk/disk_access/testcase.yaml @@ -14,8 +14,6 @@ tests: - mimxrt1050_evk - mimxrt1064_evk drivers.disk.ram: - extra_configs: - - CONFIG_DISK_DRIVER_RAM=y platform_allow: qemu_x86_64 drivers.disk.nvme: extra_configs: diff --git a/tests/drivers/disk/disk_performance/src/main.c b/tests/drivers/disk/disk_performance/src/main.c index 5def5931319..84402429082 100644 --- a/tests/drivers/disk/disk_performance/src/main.c +++ b/tests/drivers/disk/disk_performance/src/main.c @@ -16,8 +16,6 @@ #define DISK_NAME CONFIG_SDMMC_VOLUME_NAME #elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC) #define DISK_NAME CONFIG_MMC_VOLUME_NAME -#elif IS_ENABLED(CONFIG_DISK_DRIVER_RAM) -#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME #elif IS_ENABLED(CONFIG_NVME) #define DISK_NAME "nvme0n0" #else diff --git a/tests/posix/fs/app.overlay b/tests/posix/fs/app.overlay new file mode 100644 index 00000000000..87ae21b1e64 --- /dev/null +++ b/tests/posix/fs/app.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <160>; + }; +}; diff --git a/tests/posix/fs/prj.conf b/tests/posix/fs/prj.conf index 27758bc609e..24b214aa6ce 100644 --- a/tests/posix/fs/prj.conf +++ b/tests/posix/fs/prj.conf @@ -1,8 +1,6 @@ CONFIG_FILE_SYSTEM=y CONFIG_LOG=y CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=80 CONFIG_POSIX_API=y CONFIG_POSIX_FS=y CONFIG_ZTEST=y diff --git a/tests/subsys/fs/ext2/prj.conf b/tests/subsys/fs/ext2/prj.conf index 8661fc9969e..86f11ba1086 100644 --- a/tests/subsys/fs/ext2/prj.conf +++ b/tests/subsys/fs/ext2/prj.conf @@ -4,7 +4,6 @@ CONFIG_FILE_SYSTEM_MKFS=y CONFIG_DISK_ACCESS=y CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=200 CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/tests/subsys/fs/ext2/prj_big.conf b/tests/subsys/fs/ext2/prj_big.conf index 1a108557b47..4590cd4cd57 100644 --- a/tests/subsys/fs/ext2/prj_big.conf +++ b/tests/subsys/fs/ext2/prj_big.conf @@ -4,7 +4,6 @@ CONFIG_FILE_SYSTEM_MKFS=y CONFIG_DISK_ACCESS=y CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=9000 CONFIG_EXT2_MAX_BLOCK_COUNT=20 diff --git a/tests/subsys/fs/ext2/ramdisk_big.overlay b/tests/subsys/fs/ext2/ramdisk_big.overlay new file mode 100644 index 00000000000..0f0422c8fa4 --- /dev/null +++ b/tests/subsys/fs/ext2/ramdisk_big.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <18000>; + }; +}; diff --git a/tests/subsys/fs/ext2/ramdisk_small.overlay b/tests/subsys/fs/ext2/ramdisk_small.overlay new file mode 100644 index 00000000000..8a4d7708a80 --- /dev/null +++ b/tests/subsys/fs/ext2/ramdisk_small.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <400>; + }; +}; diff --git a/tests/subsys/fs/ext2/testcase.yaml b/tests/subsys/fs/ext2/testcase.yaml index 14654c83d0a..21615994ba6 100644 --- a/tests/subsys/fs/ext2/testcase.yaml +++ b/tests/subsys/fs/ext2/testcase.yaml @@ -3,10 +3,14 @@ common: tests: filesystem.ext2.default: platform_allow: native_posix native_posix_64 hifive_unmatched bl5340_dvk_cpuapp + extra_args: + - EXTRA_DTC_OVERLAY_FILE="ramdisk_small.overlay" filesystem.ext2.big: platform_allow: native_posix native_posix_64 - extra_args: CONF_FILE=prj_big.conf + extra_args: + - CONF_FILE=prj_big.conf + - EXTRA_DTC_OVERLAY_FILE="ramdisk_big.overlay" filesystem.ext2.sdcard: platform_allow: hifive_unmatched bl5340_dvk_cpuapp diff --git a/tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf b/tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf index 231fb7cf364..bff7a3e070d 100644 --- a/tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf +++ b/tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf @@ -2,7 +2,6 @@ CONFIG_FILE_SYSTEM=y CONFIG_FILE_SYSTEM_MKFS=y CONFIG_LOG=y CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_RAM=y CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y CONFIG_FLASH=y diff --git a/tests/subsys/fs/fat_fs_api/ramdisk.overlay b/tests/subsys/fs/fat_fs_api/ramdisk.overlay new file mode 100644 index 00000000000..b76a5ef6161 --- /dev/null +++ b/tests/subsys/fs/fat_fs_api/ramdisk.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <128>; + }; +}; diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat.h b/tests/subsys/fs/fat_fs_api/src/test_fat.h index 9c168b4bccf..8048ef084cf 100644 --- a/tests/subsys/fs/fat_fs_api/src/test_fat.h +++ b/tests/subsys/fs/fat_fs_api/src/test_fat.h @@ -12,7 +12,7 @@ #include #ifdef CONFIG_DISK_DRIVER_RAM -#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME +#define DISK_NAME "RAM" #elif defined(CONFIG_DISK_DRIVER_FLASH) #define DISK_NAME DT_PROP(DT_NODELABEL(test_disk), disk_name) #elif defined(CONFIG_DISK_DRIVER_SDMMC) diff --git a/tests/subsys/fs/fat_fs_api/testcase.yaml b/tests/subsys/fs/fat_fs_api/testcase.yaml index c6557e6f230..bc3927def92 100644 --- a/tests/subsys/fs/fat_fs_api/testcase.yaml +++ b/tests/subsys/fs/fat_fs_api/testcase.yaml @@ -15,7 +15,9 @@ tests: filter: dt_compat_enabled("zephyr,mmc-disk") filesystem.fat.ram.api: platform_allow: native_posix - extra_args: CONF_FILE="prj_native_posix_ram.conf" + extra_args: + - CONF_FILE="prj_native_posix_ram.conf" + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" filesystem.fat.api.reentrant: platform_allow: native_posix extra_configs: diff --git a/tests/subsys/fs/fat_fs_dual_drive/app.overlay b/tests/subsys/fs/fat_fs_dual_drive/app.overlay new file mode 100644 index 00000000000..59e564f8829 --- /dev/null +++ b/tests/subsys/fs/fat_fs_dual_drive/app.overlay @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <160>; + }; + + ramdisk1 { + compatible = "zephyr,ram-disk"; + disk-name = "CF"; + sector-size = <512>; + sector-count = <160>; + }; +}; diff --git a/tests/subsys/fs/fat_fs_dual_drive/prj.conf b/tests/subsys/fs/fat_fs_dual_drive/prj.conf index 7ac2ebe96cc..bfdefcdfdc4 100644 --- a/tests/subsys/fs/fat_fs_dual_drive/prj.conf +++ b/tests/subsys/fs/fat_fs_dual_drive/prj.conf @@ -3,7 +3,6 @@ CONFIG_LOG=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_FS_FATFS_NUM_FILES=8 CONFIG_FS_FATFS_NUM_DIRS=8 -CONFIG_DISK_DRIVER_RAM=y CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y CONFIG_MAIN_STACK_SIZE=2048 diff --git a/tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c b/tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c deleted file mode 100644 index 8af0f07a3ed..00000000000 --- a/tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#define RAMDISK_SECTOR_SIZE 512 - -/* A 96KB RAM Disk, which meets ELM FAT fs's minimum block requirement. Fit for - * qemu testing (as it may exceed target's RAM limits). - */ -#define RAMDISK_VOLUME_SIZE (192 * RAMDISK_SECTOR_SIZE) -static uint8_t ramdisk_buf[RAMDISK_VOLUME_SIZE]; - -static void *lba_to_address(uint32_t lba) -{ - __ASSERT(((lba * RAMDISK_SECTOR_SIZE) < RAMDISK_VOLUME_SIZE), - "FS bound error"); - - return &ramdisk_buf[(lba * RAMDISK_SECTOR_SIZE)]; -} - -static int disk_ram_access_status(struct disk_info *disk) -{ - return DISK_STATUS_OK; -} - -static int disk_ram_access_init(struct disk_info *disk) -{ - return 0; -} - -static int disk_ram_access_read(struct disk_info *disk, uint8_t *buff, - uint32_t sector, uint32_t count) -{ - memcpy(buff, lba_to_address(sector), count * RAMDISK_SECTOR_SIZE); - - return 0; -} - -static int disk_ram_access_write(struct disk_info *disk, const uint8_t *buff, - uint32_t sector, uint32_t count) -{ - memcpy(lba_to_address(sector), buff, count * RAMDISK_SECTOR_SIZE); - - return 0; -} - -static int disk_ram_access_ioctl(struct disk_info *disk, uint8_t cmd, void *buff) -{ - switch (cmd) { - case DISK_IOCTL_CTRL_SYNC: - break; - case DISK_IOCTL_GET_SECTOR_COUNT: - *(uint32_t *)buff = RAMDISK_VOLUME_SIZE / RAMDISK_SECTOR_SIZE; - break; - case DISK_IOCTL_GET_SECTOR_SIZE: - *(uint32_t *)buff = RAMDISK_SECTOR_SIZE; - break; - case DISK_IOCTL_GET_ERASE_BLOCK_SZ: - *(uint32_t *)buff = 1U; - break; - default: - return -EINVAL; - } - - return 0; -} - -static struct disk_operations ram_disk_ops = { - .init = disk_ram_access_init, - .status = disk_ram_access_status, - .read = disk_ram_access_read, - .write = disk_ram_access_write, - .ioctl = disk_ram_access_ioctl, -}; - -static struct disk_info ram_disk = { - .name = "CF", - .ops = &ram_disk_ops, -}; - -static int disk_ram_test_init(void) -{ - - return disk_access_register(&ram_disk); -} - -SYS_INIT(disk_ram_test_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/tests/subsys/fs/multi-fs/prj.conf b/tests/subsys/fs/multi-fs/prj.conf index 179e66c9378..7a2b28cffed 100644 --- a/tests/subsys/fs/multi-fs/prj.conf +++ b/tests/subsys/fs/multi-fs/prj.conf @@ -6,8 +6,6 @@ CONFIG_FILE_SYSTEM_LITTLEFS=y CONFIG_LOG=y CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=16384 CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=80 CONFIG_HEAP_MEM_POOL_SIZE=4096 CONFIG_MAIN_STACK_SIZE=4096 CONFIG_ZTEST_STACK_SIZE=4096 diff --git a/tests/subsys/fs/multi-fs/prj_fs_shell.conf b/tests/subsys/fs/multi-fs/prj_fs_shell.conf index 8a0e59b1ffc..aa2c4cfd79c 100644 --- a/tests/subsys/fs/multi-fs/prj_fs_shell.conf +++ b/tests/subsys/fs/multi-fs/prj_fs_shell.conf @@ -10,8 +10,6 @@ CONFIG_SHELL_BACKEND_DUMMY=y CONFIG_SHELL_CMD_BUFF_SIZE=90 CONFIG_FILE_SYSTEM_SHELL=y CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_RAM=y -CONFIG_DISK_RAM_VOLUME_SIZE=80 CONFIG_HEAP_MEM_POOL_SIZE=1024 CONFIG_MAIN_STACK_SIZE=1024 CONFIG_ZTEST_STACK_SIZE=4096 diff --git a/tests/subsys/fs/multi-fs/ramdisk.overlay b/tests/subsys/fs/multi-fs/ramdisk.overlay new file mode 100644 index 00000000000..87ae21b1e64 --- /dev/null +++ b/tests/subsys/fs/multi-fs/ramdisk.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <160>; + }; +}; diff --git a/tests/subsys/fs/multi-fs/testcase.yaml b/tests/subsys/fs/multi-fs/testcase.yaml index 07f543d64a4..b4c1e49d195 100644 --- a/tests/subsys/fs/multi-fs/testcase.yaml +++ b/tests/subsys/fs/multi-fs/testcase.yaml @@ -8,13 +8,17 @@ common: - littlefs tests: filesystem.multifs: + extra_args: + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" platform_allow: - native_posix - qemu_x86 integration_platforms: - native_posix filesystem.fs_shell: - extra_args: CONF_FILE="prj_fs_shell.conf" + extra_args: + - CONF_FILE="prj_fs_shell.conf" + - EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay" platform_allow: - native_posix - qemu_x86