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 <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
0b24aaad2c
commit
f67dd39bb2
35 changed files with 298 additions and 173 deletions
|
@ -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.
|
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
|
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
|
:kconfig:option:`CONFIG_MASS_STORAGE_DISK_NAME` and should be the same as the name
|
||||||
of the options used by the disc access driver that the application wants to expose to
|
used by the disc access driver that the application wants to expose to the host.
|
||||||
the host, :kconfig:option:`CONFIG_DISK_RAM_VOLUME_NAME`,
|
SD card disk drivers use options :kconfig:option:`CONFIG_MMC_VOLUME_NAME` or
|
||||||
:kconfig:option:`CONFIG_MMC_VOLUME_NAME`, or :kconfig:option:`CONFIG_SDMMC_VOLUME_NAME`.
|
: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
|
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
|
flash disk to be used must be described in the devicetree. If a storage partition
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
config DISK_DRIVER_RAM
|
config DISK_DRIVER_RAM
|
||||||
bool "RAM Disk"
|
bool "RAM Disk"
|
||||||
|
default y if DT_HAS_ZEPHYR_RAM_DISK_ENABLED
|
||||||
help
|
help
|
||||||
RAM buffer used to emulate storage disk.
|
RAM buffer used to emulate storage disk.
|
||||||
This option can be used to test the file
|
This option can be used to test the file
|
||||||
|
@ -10,18 +11,6 @@ config DISK_DRIVER_RAM
|
||||||
|
|
||||||
if 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 = RAMDISK
|
||||||
module-str = ramdisk
|
module-str = ramdisk
|
||||||
source "subsys/logging/Kconfig.template.log_config"
|
source "subsys/logging/Kconfig.template.log_config"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
* Copyright (c) 2021, Nordic Semiconductor ASA
|
* Copyright (c) 2021,2023 Nordic Semiconductor ASA
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -15,15 +15,25 @@
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(ramdisk, CONFIG_RAMDISK_LOG_LEVEL);
|
LOG_MODULE_REGISTER(ramdisk, CONFIG_RAMDISK_LOG_LEVEL);
|
||||||
|
|
||||||
#define RAMDISK_SECTOR_SIZE 512
|
struct ram_disk_data {
|
||||||
#define RAMDISK_VOLUME_SIZE (CONFIG_DISK_RAM_VOLUME_SIZE * 1024)
|
struct disk_info info;
|
||||||
#define RAMDISK_SECTOR_COUNT (RAMDISK_VOLUME_SIZE / RAMDISK_SECTOR_SIZE)
|
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)
|
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,
|
static int disk_ram_access_read(struct disk_info *disk, uint8_t *buff,
|
||||||
uint32_t sector, uint32_t count)
|
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;
|
uint32_t last_sector = sector + count;
|
||||||
|
|
||||||
if (last_sector < sector || last_sector > RAMDISK_SECTOR_COUNT) {
|
if (last_sector < sector || last_sector > config->sector_count) {
|
||||||
LOG_ERR("Sector %" PRIu32 " is outside the range %u",
|
LOG_ERR("Sector %" PRIu32 " is outside the range %zu",
|
||||||
last_sector, RAMDISK_SECTOR_COUNT);
|
last_sector, config->sector_count);
|
||||||
return -EIO;
|
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;
|
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,
|
static int disk_ram_access_write(struct disk_info *disk, const uint8_t *buff,
|
||||||
uint32_t sector, uint32_t count)
|
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;
|
uint32_t last_sector = sector + count;
|
||||||
|
|
||||||
if (last_sector < sector || last_sector > RAMDISK_SECTOR_COUNT) {
|
if (last_sector < sector || last_sector > config->sector_count) {
|
||||||
LOG_ERR("Sector %" PRIu32 " is outside the range %u",
|
LOG_ERR("Sector %" PRIu32 " is outside the range %zu",
|
||||||
last_sector, RAMDISK_SECTOR_COUNT);
|
last_sector, config->sector_count);
|
||||||
return -EIO;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int disk_ram_access_ioctl(struct disk_info *disk, uint8_t cmd, void *buff)
|
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) {
|
switch (cmd) {
|
||||||
case DISK_IOCTL_CTRL_SYNC:
|
case DISK_IOCTL_CTRL_SYNC:
|
||||||
break;
|
break;
|
||||||
case DISK_IOCTL_GET_SECTOR_COUNT:
|
case DISK_IOCTL_GET_SECTOR_COUNT:
|
||||||
*(uint32_t *)buff = RAMDISK_SECTOR_COUNT;
|
*(uint32_t *)buff = config->sector_count;
|
||||||
break;
|
break;
|
||||||
case DISK_IOCTL_GET_SECTOR_SIZE:
|
case DISK_IOCTL_GET_SECTOR_SIZE:
|
||||||
*(uint32_t *)buff = RAMDISK_SECTOR_SIZE;
|
*(uint32_t *)buff = config->sector_size;
|
||||||
break;
|
break;
|
||||||
case DISK_IOCTL_GET_ERASE_BLOCK_SZ:
|
case DISK_IOCTL_GET_ERASE_BLOCK_SZ:
|
||||||
*(uint32_t *)buff = 1U;
|
*(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;
|
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 = {
|
static const struct disk_operations ram_disk_ops = {
|
||||||
.init = disk_ram_access_init,
|
.init = disk_ram_access_init,
|
||||||
.status = disk_ram_access_status,
|
.status = disk_ram_access_status,
|
||||||
|
@ -97,15 +122,51 @@ static const struct disk_operations ram_disk_ops = {
|
||||||
.ioctl = disk_ram_access_ioctl,
|
.ioctl = disk_ram_access_ioctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct disk_info ram_disk = {
|
#define DT_DRV_COMPAT zephyr_ram_disk
|
||||||
.name = CONFIG_DISK_RAM_VOLUME_NAME,
|
|
||||||
.ops = &ram_disk_ops,
|
|
||||||
};
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
35
dts/bindings/disk/zephyr,ram-disk.yaml
Normal file
35
dts/bindings/disk/zephyr,ram-disk.yaml
Normal file
|
@ -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.
|
|
@ -1,7 +1,5 @@
|
||||||
CONFIG_DISK_ACCESS=y
|
CONFIG_DISK_ACCESS=y
|
||||||
CONFIG_DISK_DRIVERS=y
|
CONFIG_DISK_DRIVERS=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=64
|
|
||||||
|
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_LOG_MODE_MINIMAL=y
|
CONFIG_LOG_MODE_MINIMAL=y
|
||||||
|
|
14
samples/subsys/fs/format/ramdisk.overlay
Normal file
14
samples/subsys/fs/format/ramdisk.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -12,5 +12,7 @@ tests:
|
||||||
- native_posix
|
- native_posix
|
||||||
- mimxrt1064_evk
|
- mimxrt1064_evk
|
||||||
build_only: true
|
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
|
tags: filesystem
|
||||||
|
|
|
@ -3,6 +3,3 @@
|
||||||
|
|
||||||
CONFIG_USB_MASS_STORAGE=y
|
CONFIG_USB_MASS_STORAGE=y
|
||||||
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
|
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
|
||||||
|
|
||||||
#RAM DISK
|
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
|
|
14
samples/subsys/usb/cdc_acm/ramdisk.overlay
Normal file
14
samples/subsys/usb/cdc_acm/ramdisk.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -27,7 +27,9 @@ tests:
|
||||||
depends_on: usb_device
|
depends_on: usb_device
|
||||||
tags: usb
|
tags: usb
|
||||||
arch_exclude: posix
|
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: console
|
||||||
harness_config:
|
harness_config:
|
||||||
type: one_line
|
type: one_line
|
||||||
|
|
|
@ -14,11 +14,9 @@ choice
|
||||||
|
|
||||||
config APP_MSC_STORAGE_NONE
|
config APP_MSC_STORAGE_NONE
|
||||||
bool "Use RAM disk as block device"
|
bool "Use RAM disk as block device"
|
||||||
imply DISK_DRIVER_RAM
|
|
||||||
|
|
||||||
config APP_MSC_STORAGE_RAM
|
config APP_MSC_STORAGE_RAM
|
||||||
bool "Use RAM disk and FAT file system"
|
bool "Use RAM disk and FAT file system"
|
||||||
imply DISK_DRIVER_RAM
|
|
||||||
imply FILE_SYSTEM
|
imply FILE_SYSTEM
|
||||||
imply FAT_FILESYSTEM_ELM
|
imply FAT_FILESYSTEM_ELM
|
||||||
|
|
||||||
|
@ -42,9 +40,6 @@ config APP_MSC_STORAGE_SDCARD
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config DISK_RAM_VOLUME_SIZE
|
|
||||||
default 32 if APP_MSC_STORAGE_NONE
|
|
||||||
|
|
||||||
config MASS_STORAGE_DISK_NAME
|
config MASS_STORAGE_DISK_NAME
|
||||||
default "NAND" if DISK_DRIVER_FLASH
|
default "NAND" if DISK_DRIVER_FLASH
|
||||||
default "RAM" if DISK_DRIVER_RAM
|
default "RAM" if DISK_DRIVER_RAM
|
||||||
|
|
14
samples/subsys/usb/mass/ramdisk.overlay
Normal file
14
samples/subsys/usb/mass/ramdisk.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -2,9 +2,11 @@ sample:
|
||||||
name: Mass Storage
|
name: Mass Storage
|
||||||
tests:
|
tests:
|
||||||
sample.usb.mass_ram_none:
|
sample.usb.mass_ram_none:
|
||||||
min_ram: 64
|
min_ram: 128
|
||||||
depends_on: usb_device
|
depends_on: usb_device
|
||||||
arch_exclude: posix
|
arch_exclude: posix
|
||||||
|
extra_args:
|
||||||
|
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_LOG_DEFAULT_LEVEL=3
|
- CONFIG_LOG_DEFAULT_LEVEL=3
|
||||||
tags:
|
tags:
|
||||||
|
@ -18,12 +20,14 @@ tests:
|
||||||
- "No file system selected"
|
- "No file system selected"
|
||||||
- "The device is put in USB mass storage mode."
|
- "The device is put in USB mass storage mode."
|
||||||
sample.usb_device_next.mass_ram_none:
|
sample.usb_device_next.mass_ram_none:
|
||||||
min_ram: 64
|
min_ram: 128
|
||||||
depends_on: usb_device
|
depends_on: usb_device
|
||||||
platform_allow:
|
platform_allow:
|
||||||
- nrf52840dk_nrf52840
|
- nrf52840dk_nrf52840
|
||||||
- frdm_k64f
|
- 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:
|
extra_configs:
|
||||||
- CONFIG_LOG_DEFAULT_LEVEL=3
|
- CONFIG_LOG_DEFAULT_LEVEL=3
|
||||||
tags:
|
tags:
|
||||||
|
@ -40,6 +44,8 @@ tests:
|
||||||
min_ram: 128
|
min_ram: 128
|
||||||
depends_on: usb_device
|
depends_on: usb_device
|
||||||
arch_exclude: posix
|
arch_exclude: posix
|
||||||
|
extra_args:
|
||||||
|
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_LOG_DEFAULT_LEVEL=3
|
- CONFIG_LOG_DEFAULT_LEVEL=3
|
||||||
- CONFIG_APP_MSC_STORAGE_RAM=y
|
- CONFIG_APP_MSC_STORAGE_RAM=y
|
||||||
|
|
|
@ -18,4 +18,11 @@
|
||||||
status = "okay";
|
status = "okay";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ramdisk0 {
|
||||||
|
compatible = "zephyr,ram-disk";
|
||||||
|
disk-name = "RAM";
|
||||||
|
sector-size = <512>;
|
||||||
|
sector-count = <192>;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC)
|
#elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC)
|
||||||
#define DISK_NAME CONFIG_MMC_VOLUME_NAME
|
#define DISK_NAME CONFIG_MMC_VOLUME_NAME
|
||||||
#elif IS_ENABLED(CONFIG_DISK_DRIVER_RAM)
|
#elif IS_ENABLED(CONFIG_DISK_DRIVER_RAM)
|
||||||
#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME
|
#define DISK_NAME "RAM"
|
||||||
#elif IS_ENABLED(CONFIG_NVME)
|
#elif IS_ENABLED(CONFIG_NVME)
|
||||||
#define DISK_NAME "nvme0n0"
|
#define DISK_NAME "nvme0n0"
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -14,8 +14,6 @@ tests:
|
||||||
- mimxrt1050_evk
|
- mimxrt1050_evk
|
||||||
- mimxrt1064_evk
|
- mimxrt1064_evk
|
||||||
drivers.disk.ram:
|
drivers.disk.ram:
|
||||||
extra_configs:
|
|
||||||
- CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
platform_allow: qemu_x86_64
|
platform_allow: qemu_x86_64
|
||||||
drivers.disk.nvme:
|
drivers.disk.nvme:
|
||||||
extra_configs:
|
extra_configs:
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
#define DISK_NAME CONFIG_SDMMC_VOLUME_NAME
|
#define DISK_NAME CONFIG_SDMMC_VOLUME_NAME
|
||||||
#elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC)
|
#elif IS_ENABLED(CONFIG_DISK_DRIVER_MMC)
|
||||||
#define DISK_NAME CONFIG_MMC_VOLUME_NAME
|
#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)
|
#elif IS_ENABLED(CONFIG_NVME)
|
||||||
#define DISK_NAME "nvme0n0"
|
#define DISK_NAME "nvme0n0"
|
||||||
#else
|
#else
|
||||||
|
|
14
tests/posix/fs/app.overlay
Normal file
14
tests/posix/fs/app.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,8 +1,6 @@
|
||||||
CONFIG_FILE_SYSTEM=y
|
CONFIG_FILE_SYSTEM=y
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=80
|
|
||||||
CONFIG_POSIX_API=y
|
CONFIG_POSIX_API=y
|
||||||
CONFIG_POSIX_FS=y
|
CONFIG_POSIX_FS=y
|
||||||
CONFIG_ZTEST=y
|
CONFIG_ZTEST=y
|
||||||
|
|
|
@ -4,7 +4,6 @@ CONFIG_FILE_SYSTEM_MKFS=y
|
||||||
|
|
||||||
CONFIG_DISK_ACCESS=y
|
CONFIG_DISK_ACCESS=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
CONFIG_DISK_DRIVER_RAM=y
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=200
|
|
||||||
|
|
||||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ CONFIG_FILE_SYSTEM_MKFS=y
|
||||||
|
|
||||||
CONFIG_DISK_ACCESS=y
|
CONFIG_DISK_ACCESS=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
CONFIG_DISK_DRIVER_RAM=y
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=9000
|
|
||||||
|
|
||||||
CONFIG_EXT2_MAX_BLOCK_COUNT=20
|
CONFIG_EXT2_MAX_BLOCK_COUNT=20
|
||||||
|
|
||||||
|
|
14
tests/subsys/fs/ext2/ramdisk_big.overlay
Normal file
14
tests/subsys/fs/ext2/ramdisk_big.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
14
tests/subsys/fs/ext2/ramdisk_small.overlay
Normal file
14
tests/subsys/fs/ext2/ramdisk_small.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -3,10 +3,14 @@ common:
|
||||||
tests:
|
tests:
|
||||||
filesystem.ext2.default:
|
filesystem.ext2.default:
|
||||||
platform_allow: native_posix native_posix_64 hifive_unmatched bl5340_dvk_cpuapp
|
platform_allow: native_posix native_posix_64 hifive_unmatched bl5340_dvk_cpuapp
|
||||||
|
extra_args:
|
||||||
|
- EXTRA_DTC_OVERLAY_FILE="ramdisk_small.overlay"
|
||||||
|
|
||||||
filesystem.ext2.big:
|
filesystem.ext2.big:
|
||||||
platform_allow: native_posix native_posix_64
|
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:
|
filesystem.ext2.sdcard:
|
||||||
platform_allow: hifive_unmatched bl5340_dvk_cpuapp
|
platform_allow: hifive_unmatched bl5340_dvk_cpuapp
|
||||||
|
|
|
@ -2,7 +2,6 @@ CONFIG_FILE_SYSTEM=y
|
||||||
CONFIG_FILE_SYSTEM_MKFS=y
|
CONFIG_FILE_SYSTEM_MKFS=y
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_ZTEST=y
|
CONFIG_ZTEST=y
|
||||||
CONFIG_ZTEST_NEW_API=y
|
CONFIG_ZTEST_NEW_API=y
|
||||||
CONFIG_FLASH=y
|
CONFIG_FLASH=y
|
||||||
|
|
14
tests/subsys/fs/fat_fs_api/ramdisk.overlay
Normal file
14
tests/subsys/fs/fat_fs_api/ramdisk.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -12,7 +12,7 @@
|
||||||
#include <ff.h>
|
#include <ff.h>
|
||||||
|
|
||||||
#ifdef CONFIG_DISK_DRIVER_RAM
|
#ifdef CONFIG_DISK_DRIVER_RAM
|
||||||
#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME
|
#define DISK_NAME "RAM"
|
||||||
#elif defined(CONFIG_DISK_DRIVER_FLASH)
|
#elif defined(CONFIG_DISK_DRIVER_FLASH)
|
||||||
#define DISK_NAME DT_PROP(DT_NODELABEL(test_disk), disk_name)
|
#define DISK_NAME DT_PROP(DT_NODELABEL(test_disk), disk_name)
|
||||||
#elif defined(CONFIG_DISK_DRIVER_SDMMC)
|
#elif defined(CONFIG_DISK_DRIVER_SDMMC)
|
||||||
|
|
|
@ -15,7 +15,9 @@ tests:
|
||||||
filter: dt_compat_enabled("zephyr,mmc-disk")
|
filter: dt_compat_enabled("zephyr,mmc-disk")
|
||||||
filesystem.fat.ram.api:
|
filesystem.fat.ram.api:
|
||||||
platform_allow: native_posix
|
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:
|
filesystem.fat.api.reentrant:
|
||||||
platform_allow: native_posix
|
platform_allow: native_posix
|
||||||
extra_configs:
|
extra_configs:
|
||||||
|
|
21
tests/subsys/fs/fat_fs_dual_drive/app.overlay
Normal file
21
tests/subsys/fs/fat_fs_dual_drive/app.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -3,7 +3,6 @@ CONFIG_LOG=y
|
||||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||||
CONFIG_FS_FATFS_NUM_FILES=8
|
CONFIG_FS_FATFS_NUM_FILES=8
|
||||||
CONFIG_FS_FATFS_NUM_DIRS=8
|
CONFIG_FS_FATFS_NUM_DIRS=8
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_ZTEST=y
|
CONFIG_ZTEST=y
|
||||||
CONFIG_ZTEST_NEW_API=y
|
CONFIG_ZTEST_NEW_API=y
|
||||||
CONFIG_MAIN_STACK_SIZE=2048
|
CONFIG_MAIN_STACK_SIZE=2048
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 Intel Corporation.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <zephyr/types.h>
|
|
||||||
#include <zephyr/sys/__assert.h>
|
|
||||||
#include <zephyr/storage/disk_access.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <zephyr/init.h>
|
|
||||||
#include <zephyr/device.h>
|
|
||||||
|
|
||||||
#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);
|
|
|
@ -6,8 +6,6 @@ CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=16384
|
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=16384
|
||||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=80
|
|
||||||
CONFIG_HEAP_MEM_POOL_SIZE=4096
|
CONFIG_HEAP_MEM_POOL_SIZE=4096
|
||||||
CONFIG_MAIN_STACK_SIZE=4096
|
CONFIG_MAIN_STACK_SIZE=4096
|
||||||
CONFIG_ZTEST_STACK_SIZE=4096
|
CONFIG_ZTEST_STACK_SIZE=4096
|
||||||
|
|
|
@ -10,8 +10,6 @@ CONFIG_SHELL_BACKEND_DUMMY=y
|
||||||
CONFIG_SHELL_CMD_BUFF_SIZE=90
|
CONFIG_SHELL_CMD_BUFF_SIZE=90
|
||||||
CONFIG_FILE_SYSTEM_SHELL=y
|
CONFIG_FILE_SYSTEM_SHELL=y
|
||||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||||
CONFIG_DISK_DRIVER_RAM=y
|
|
||||||
CONFIG_DISK_RAM_VOLUME_SIZE=80
|
|
||||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||||
CONFIG_MAIN_STACK_SIZE=1024
|
CONFIG_MAIN_STACK_SIZE=1024
|
||||||
CONFIG_ZTEST_STACK_SIZE=4096
|
CONFIG_ZTEST_STACK_SIZE=4096
|
||||||
|
|
14
tests/subsys/fs/multi-fs/ramdisk.overlay
Normal file
14
tests/subsys/fs/multi-fs/ramdisk.overlay
Normal file
|
@ -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>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -8,13 +8,17 @@ common:
|
||||||
- littlefs
|
- littlefs
|
||||||
tests:
|
tests:
|
||||||
filesystem.multifs:
|
filesystem.multifs:
|
||||||
|
extra_args:
|
||||||
|
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
|
||||||
platform_allow:
|
platform_allow:
|
||||||
- native_posix
|
- native_posix
|
||||||
- qemu_x86
|
- qemu_x86
|
||||||
integration_platforms:
|
integration_platforms:
|
||||||
- native_posix
|
- native_posix
|
||||||
filesystem.fs_shell:
|
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:
|
platform_allow:
|
||||||
- native_posix
|
- native_posix
|
||||||
- qemu_x86
|
- qemu_x86
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue