diff --git a/samples/subsys/fs/fat_fs/CMakeLists.txt b/samples/subsys/fs/fs_sample/CMakeLists.txt similarity index 100% rename from samples/subsys/fs/fat_fs/CMakeLists.txt rename to samples/subsys/fs/fs_sample/CMakeLists.txt diff --git a/samples/subsys/fs/fat_fs/Kconfig b/samples/subsys/fs/fs_sample/Kconfig similarity index 62% rename from samples/subsys/fs/fat_fs/Kconfig rename to samples/subsys/fs/fs_sample/Kconfig index 06b3720fb65..25d7b95e6cd 100644 --- a/samples/subsys/fs/fat_fs/Kconfig +++ b/samples/subsys/fs/fs_sample/Kconfig @@ -1,20 +1,21 @@ # # Copyright (c) 2023 Nordic Semiconductor ASA +# Copyright (c) 2023 Antmicro # # SPDX-License-Identifier: Apache-2.0 # -mainmenu "FAT Filesystem Sample Application" +mainmenu "Filesystems Sample Application" -config SAMPLE_FATFS_CREATE_SOME_ENTRIES +config FS_SAMPLE_CREATE_SOME_ENTRIES bool "When no files are found on mounted partition create some" default y help In case when no files could be listed, because there are none, "some.dir" directory and "other.txt" file will be created and list will run again to show them. This is useful when - showing how FAT works on non-SD devices like internal flash - or (Q)SPI connected memories, where it is not possible to + showing how file system works on non-SD devices like internal + flash or (Q)SPI connected memories, where it is not possible to easily add files with use of other device. source "Kconfig.zephyr" diff --git a/samples/subsys/fs/fat_fs/README.rst b/samples/subsys/fs/fs_sample/README.rst similarity index 62% rename from samples/subsys/fs/fat_fs/README.rst rename to samples/subsys/fs/fs_sample/README.rst index 2f7ecb4952d..6a441e201cd 100644 --- a/samples/subsys/fs/fat_fs/README.rst +++ b/samples/subsys/fs/fs_sample/README.rst @@ -1,12 +1,12 @@ -.. _fat_fs: +.. _fs_sample: -FAT Filesystem Sample Application +Filesystems Sample Application ################################### Overview ******** -This sample app demonstrates use of the filesystem API and uses the FAT file +This sample app demonstrates use of the file system API and uses the FAT or Ext2 file system driver with SDHC card, SoC flash or external flash chip. To access device the sample uses :ref:`disk_access_api`. @@ -14,13 +14,11 @@ To access device the sample uses :ref:`disk_access_api`. Requirements for SD card support ******************************** -This project requires SD card support and microSD card formatted with FAT filesystem. -See the :ref:`disk_access_api` documentation for Zephyr implementation details. -Boards that by default use SD card for storage: -``arduino_mkrzero``, ``esp_wrover_kit``, ``mimxrt1050_evk``, ``nrf52840_blip`` -and ``olimexino_stm32``. -The sample should be able to run with any other board that has "zephyr,sdmmc-disk" -DT node enabled. +This project requires SD card support and microSD card formatted with proper file system +(FAT or Ext2) See the :ref:`disk_access_api` documentation for Zephyr implementation details. +Boards that by default use SD card for storage: ``arduino_mkrzero``, ``esp_wrover_kit``, +``mimxrt1050_evk``, ``nrf52840_blip`` and ``olimexino_stm32``. The sample should be able +to run with any other board that has "zephyr,sdmmc-disk" DT node enabled. Requirements for setting up FAT FS on SoC flash *********************************************** @@ -38,14 +36,14 @@ This type of configuration requires external flash device to be available on DK board. Currently following boards support the configuration: ``nrf52840dk_nrf52840`` by ``nrf52840dk_nrf52840_qspi`` configuration. -Building and Running -******************** +Building and Running FAT samples +******************************** Boards with default configurations, for example ``arduino_mkrzero`` or ``nrf52840dk_nrf52840`` using internal flash can be build using command: .. zephyr-app-commands:: - :zephyr-app: samples/subsys/fs/fat_fs + :zephyr-app: samples/subsys/fs/fs_sample :board: nrf52840_blip :goals: build :compact: @@ -57,7 +55,7 @@ for example ``nrf52840dk_nrf52840`` with MX25 device over QSPI, configuration and DTS overlays need to be also selected. The command would look like this: .. zephyr-app-commands:: - :zephyr-app: samples/subsys/fs/fat_fs + :zephyr-app: samples/subsys/fs/fs_sample :board: nrf52840dk_nrf52840 :gen-args: -DEXTRA_CONF_FILE=nrf52840dk_nrf52840_qspi.conf -DDTC_OVERLAY_FILE=nrf52840dk_nrf52840_qspi.overlay :goals: build @@ -70,3 +68,20 @@ sample lists them out on the debug serial output. .. warning:: In case when mount fails the device may get re-formatted to FAT FS. To disable this behaviour disable :kconfig:option:`CONFIG_FS_FATFS_MOUNT_MKFS` . + +Building and Running EXT2 samples +********************************* + +Ext2 sample can be build for ``hifive_unmatched`` or ``bl5340_dvk_cpuapp``. Because +FAT is default file system for this sample, additional flags must be passed to build +the sample. + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/fs/fs_sample + :board: hifive_unmatched + :gen-args: -DCONF_FILE=prj_ext.conf + :goals: build + :compact: + +A microSD card must be present in a microSD card slot of the board, for the sample to execute. +After starting the sample a contents of a root directory should be printed on the console. diff --git a/samples/subsys/fs/fat_fs/boards/esp_wrover_kit.conf b/samples/subsys/fs/fs_sample/boards/esp_wrover_kit.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/esp_wrover_kit.conf rename to samples/subsys/fs/fs_sample/boards/esp_wrover_kit.conf diff --git a/samples/subsys/fs/fat_fs/boards/esp_wrover_kit.overlay b/samples/subsys/fs/fs_sample/boards/esp_wrover_kit.overlay similarity index 100% rename from samples/subsys/fs/fat_fs/boards/esp_wrover_kit.overlay rename to samples/subsys/fs/fs_sample/boards/esp_wrover_kit.overlay diff --git a/samples/subsys/fs/fat_fs/boards/frdm_k64f.conf b/samples/subsys/fs/fs_sample/boards/frdm_k64f.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/frdm_k64f.conf rename to samples/subsys/fs/fs_sample/boards/frdm_k64f.conf diff --git a/samples/subsys/fs/fs_sample/boards/hifive_unmatched.overlay b/samples/subsys/fs/fs_sample/boards/hifive_unmatched.overlay new file mode 100644 index 00000000000..730370e1b5a --- /dev/null +++ b/samples/subsys/fs/fs_sample/boards/hifive_unmatched.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Antmicro + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi2 { + status = "okay"; + + sdhc0: sdhc@0 { + compatible = "zephyr,sdhc-spi-slot"; + reg = <0>; + status = "okay"; + mmc { + compatible = "zephyr,sdmmc-disk"; + status = "okay"; + }; + spi-max-frequency = <20000000>; + }; +}; diff --git a/samples/subsys/fs/fat_fs/boards/mg100.conf b/samples/subsys/fs/fs_sample/boards/mg100.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/mg100.conf rename to samples/subsys/fs/fs_sample/boards/mg100.conf diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840_blip.conf b/samples/subsys/fs/fs_sample/boards/nrf52840_blip.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nrf52840_blip.conf rename to samples/subsys/fs/fs_sample/boards/nrf52840_blip.conf diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840_blip.overlay b/samples/subsys/fs/fs_sample/boards/nrf52840_blip.overlay similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nrf52840_blip.overlay rename to samples/subsys/fs/fs_sample/boards/nrf52840_blip.overlay diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.conf b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.conf similarity index 87% rename from samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.conf rename to samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.conf index a040d02ec06..8bd2daab5a5 100644 --- a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.conf +++ b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.conf @@ -9,4 +9,4 @@ CONFIG_DISK_DRIVER_FLASH=y # There may be no files on internal SoC flash, so this Kconfig # options has ben enabled to create some if listing does not # find in the first place. -CONFIG_SAMPLE_FATFS_CREATE_SOME_ENTRIES=y +CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES=y diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.overlay b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.overlay similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.overlay rename to samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.overlay diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.conf b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.conf similarity index 90% rename from samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.conf rename to samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.conf index 99626d1d43c..892157f3a9c 100644 --- a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.conf +++ b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.conf @@ -12,4 +12,4 @@ CONFIG_DISK_DRIVER_FLASH=y # There may be no files on internal SoC flash, so this Kconfig # options has ben enabled to create some if listing does not # find in the first place. -CONFIG_SAMPLE_FATFS_CREATE_SOME_ENTRIES=y +CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES=y diff --git a/samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.overlay b/samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.overlay similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.overlay rename to samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.overlay diff --git a/samples/subsys/fs/fat_fs/boards/nucleo_f429zi.conf b/samples/subsys/fs/fs_sample/boards/nucleo_f429zi.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nucleo_f429zi.conf rename to samples/subsys/fs/fs_sample/boards/nucleo_f429zi.conf diff --git a/samples/subsys/fs/fat_fs/boards/nucleo_f429zi.overlay b/samples/subsys/fs/fs_sample/boards/nucleo_f429zi.overlay similarity index 100% rename from samples/subsys/fs/fat_fs/boards/nucleo_f429zi.overlay rename to samples/subsys/fs/fs_sample/boards/nucleo_f429zi.overlay diff --git a/samples/subsys/fs/fat_fs/boards/olimexino_stm32.conf b/samples/subsys/fs/fs_sample/boards/olimexino_stm32.conf similarity index 100% rename from samples/subsys/fs/fat_fs/boards/olimexino_stm32.conf rename to samples/subsys/fs/fs_sample/boards/olimexino_stm32.conf diff --git a/samples/subsys/fs/fat_fs/prj.conf b/samples/subsys/fs/fs_sample/prj.conf similarity index 100% rename from samples/subsys/fs/fat_fs/prj.conf rename to samples/subsys/fs/fs_sample/prj.conf diff --git a/samples/subsys/fs/fs_sample/prj_ext.conf b/samples/subsys/fs/fs_sample/prj_ext.conf new file mode 100644 index 00000000000..4c9fd15c510 --- /dev/null +++ b/samples/subsys/fs/fs_sample/prj_ext.conf @@ -0,0 +1,20 @@ +# Copyright (c) 2023 Antmicro +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_LOG=y +CONFIG_LOG_MODE_IMMEDIATE=y + +CONFIG_MAIN_STACK_SIZE=2048 + +CONFIG_FILE_SYSTEM=y +CONFIG_FILE_SYSTEM_EXT2=y + +# Enable to allow formatting +# CONFIG_FILE_SYSTEM_MKFS=y +# CONFIG_TEST_RANDOM_GENERATOR=y + +CONFIG_DISK_ACCESS=y +CONFIG_DISK_DRIVER_SDMMC=y + +# First block of first partition after GPT +CONFIG_EXT2_DISK_STARTING_SECTOR=2082 diff --git a/samples/subsys/fs/fat_fs/sample.yaml b/samples/subsys/fs/fs_sample/sample.yaml similarity index 88% rename from samples/subsys/fs/fat_fs/sample.yaml rename to samples/subsys/fs/fs_sample/sample.yaml index 7a820a15033..e022ca1e4c1 100644 --- a/samples/subsys/fs/fat_fs/sample.yaml +++ b/samples/subsys/fs/fs_sample/sample.yaml @@ -1,5 +1,5 @@ sample: - name: Fat filesystem sample + name: Filesystems sample common: tags: filesystem modules: @@ -42,3 +42,6 @@ tests: filter: dt_compat_enabled("zephyr,sdmmc-disk") integration_platforms: - frdm_k64f + sample.filesystem.ext2: + extra_args: CONF_FILE="prj_ext.conf" + platform_allow: hifive_unmatched bl5340_dvk_cpuapp diff --git a/samples/subsys/fs/fat_fs/src/main.c b/samples/subsys/fs/fs_sample/src/main.c similarity index 85% rename from samples/subsys/fs/fat_fs/src/main.c rename to samples/subsys/fs/fs_sample/src/main.c index a1837d0d319..52c74cc74b1 100644 --- a/samples/subsys/fs/fat_fs/src/main.c +++ b/samples/subsys/fs/fs_sample/src/main.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2019 Tavish Naruka * Copyright (c) 2023 Nordic Semiconductor ASA + * Copyright (c) 2023 Antmicro * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,16 +13,17 @@ #include #include #include + +#if defined(CONFIG_FAT_FILESYSTEM_ELM) + #include -LOG_MODULE_REGISTER(main); - +/* + * Note the fatfs library is able to mount only strings inside _VOLUME_STRS + * in ffconf.h + */ #define DISK_DRIVE_NAME "SD" #define DISK_MOUNT_PT "/"DISK_DRIVE_NAME":" -#define MAX_PATH 128 -#define SOME_FILE_NAME "some.dat" -#define SOME_DIR_NAME "some" -#define SOME_REQUIRED_LEN MAX(sizeof(SOME_FILE_NAME), sizeof(SOME_DIR_NAME)) static FATFS fat_fs; /* mounting info */ @@ -30,8 +32,31 @@ static struct fs_mount_t mp = { .fs_data = &fat_fs, }; +#elif defined(CONFIG_FILE_SYSTEM_EXT2) + +#include + +#define DISK_DRIVE_NAME "SDMMC" +#define DISK_MOUNT_PT "/ext" + +static struct fs_mount_t mp = { + .type = FS_EXT2, + .flags = FS_MOUNT_FLAG_NO_FORMAT, + .storage_dev = (void *)DISK_DRIVE_NAME, + .mnt_point = "/ext", +}; + +#endif + +LOG_MODULE_REGISTER(main); + +#define MAX_PATH 128 +#define SOME_FILE_NAME "some.dat" +#define SOME_DIR_NAME "some" +#define SOME_REQUIRED_LEN MAX(sizeof(SOME_FILE_NAME), sizeof(SOME_DIR_NAME)) + static int lsdir(const char *path); -#ifdef CONFIG_SAMPLE_FATFS_CREATE_SOME_ENTRIES +#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES static bool create_some_entries(const char *base_path) { char path[MAX_PATH]; @@ -71,10 +96,6 @@ static bool create_some_entries(const char *base_path) } #endif -/* -* Note the fatfs library is able to mount only strings inside _VOLUME_STRS -* in ffconf.h -*/ static const char *disk_mount_pt = DISK_MOUNT_PT; int main(void) @@ -113,10 +134,14 @@ int main(void) int res = fs_mount(&mp); +#if defined(CONFIG_FAT_FILESYSTEM_ELM) if (res == FR_OK) { +#else + if (res == 0) { +#endif printk("Disk mounted.\n"); if (lsdir(disk_mount_pt) == 0) { -#ifdef CONFIG_SAMPLE_FATFS_CREATE_SOME_ENTRIES +#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES if (create_some_entries(disk_mount_pt)) { lsdir(disk_mount_pt); } @@ -126,6 +151,8 @@ int main(void) printk("Error mounting disk.\n"); } + fs_unmount(&mp); + while (1) { k_sleep(K_MSEC(1000)); }