Browse Source

samples: subsys: fs: create common fs sample

Sample for FAT fs is reworked to run also with Ext2 file system

Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
pull/61126/head
Franciszek Zdobylak 2 years ago committed by Anas Nashif
parent
commit
16183f665e
  1. 0
      samples/subsys/fs/fs_sample/CMakeLists.txt
  2. 9
      samples/subsys/fs/fs_sample/Kconfig
  3. 43
      samples/subsys/fs/fs_sample/README.rst
  4. 0
      samples/subsys/fs/fs_sample/boards/esp_wrover_kit.conf
  5. 0
      samples/subsys/fs/fs_sample/boards/esp_wrover_kit.overlay
  6. 0
      samples/subsys/fs/fs_sample/boards/frdm_k64f.conf
  7. 20
      samples/subsys/fs/fs_sample/boards/hifive_unmatched.overlay
  8. 0
      samples/subsys/fs/fs_sample/boards/mg100.conf
  9. 0
      samples/subsys/fs/fs_sample/boards/nrf52840_blip.conf
  10. 0
      samples/subsys/fs/fs_sample/boards/nrf52840_blip.overlay
  11. 2
      samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.conf
  12. 0
      samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.overlay
  13. 2
      samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.conf
  14. 0
      samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.overlay
  15. 0
      samples/subsys/fs/fs_sample/boards/nucleo_f429zi.conf
  16. 0
      samples/subsys/fs/fs_sample/boards/nucleo_f429zi.overlay
  17. 0
      samples/subsys/fs/fs_sample/boards/olimexino_stm32.conf
  18. 0
      samples/subsys/fs/fs_sample/prj.conf
  19. 20
      samples/subsys/fs/fs_sample/prj_ext.conf
  20. 5
      samples/subsys/fs/fs_sample/sample.yaml
  21. 51
      samples/subsys/fs/fs_sample/src/main.c

0
samples/subsys/fs/fat_fs/CMakeLists.txt → samples/subsys/fs/fs_sample/CMakeLists.txt

9
samples/subsys/fs/fat_fs/Kconfig → samples/subsys/fs/fs_sample/Kconfig

@ -1,20 +1,21 @@ @@ -1,20 +1,21 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
# Copyright (c) 2023 Antmicro <www.antmicro.com>
#
# 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"

43
samples/subsys/fs/fat_fs/README.rst → samples/subsys/fs/fs_sample/README.rst

@ -1,12 +1,12 @@ @@ -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`. @@ -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 @@ -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 @@ -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. @@ -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.

0
samples/subsys/fs/fat_fs/boards/esp_wrover_kit.conf → samples/subsys/fs/fs_sample/boards/esp_wrover_kit.conf

0
samples/subsys/fs/fat_fs/boards/esp_wrover_kit.overlay → samples/subsys/fs/fs_sample/boards/esp_wrover_kit.overlay

0
samples/subsys/fs/fat_fs/boards/frdm_k64f.conf → samples/subsys/fs/fs_sample/boards/frdm_k64f.conf

20
samples/subsys/fs/fs_sample/boards/hifive_unmatched.overlay

@ -0,0 +1,20 @@ @@ -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>;
};
};

0
samples/subsys/fs/fat_fs/boards/mg100.conf → samples/subsys/fs/fs_sample/boards/mg100.conf

0
samples/subsys/fs/fat_fs/boards/nrf52840_blip.conf → samples/subsys/fs/fs_sample/boards/nrf52840_blip.conf

0
samples/subsys/fs/fat_fs/boards/nrf52840_blip.overlay → samples/subsys/fs/fs_sample/boards/nrf52840_blip.overlay

2
samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.conf → samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.conf

@ -9,4 +9,4 @@ CONFIG_DISK_DRIVER_FLASH=y @@ -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

0
samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840.overlay → samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840.overlay

2
samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.conf → samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.conf

@ -12,4 +12,4 @@ CONFIG_DISK_DRIVER_FLASH=y @@ -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

0
samples/subsys/fs/fat_fs/boards/nrf52840dk_nrf52840_qspi.overlay → samples/subsys/fs/fs_sample/boards/nrf52840dk_nrf52840_qspi.overlay

0
samples/subsys/fs/fat_fs/boards/nucleo_f429zi.conf → samples/subsys/fs/fs_sample/boards/nucleo_f429zi.conf

0
samples/subsys/fs/fat_fs/boards/nucleo_f429zi.overlay → samples/subsys/fs/fs_sample/boards/nucleo_f429zi.overlay

0
samples/subsys/fs/fat_fs/boards/olimexino_stm32.conf → samples/subsys/fs/fs_sample/boards/olimexino_stm32.conf

0
samples/subsys/fs/fat_fs/prj.conf → samples/subsys/fs/fs_sample/prj.conf

20
samples/subsys/fs/fs_sample/prj_ext.conf

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
# Copyright (c) 2023 Antmicro <www.antmicro.com>
# 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

5
samples/subsys/fs/fat_fs/sample.yaml → samples/subsys/fs/fs_sample/sample.yaml

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
sample:
name: Fat filesystem sample
name: Filesystems sample
common:
tags: filesystem
modules:
@ -42,3 +42,6 @@ tests: @@ -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

51
samples/subsys/fs/fat_fs/src/main.c → samples/subsys/fs/fs_sample/src/main.c

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
/*
* Copyright (c) 2019 Tavish Naruka <tavishnaruka@gmail.com>
* Copyright (c) 2023 Nordic Semiconductor ASA
* Copyright (c) 2023 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -12,16 +13,17 @@ @@ -12,16 +13,17 @@
#include <zephyr/storage/disk_access.h>
#include <zephyr/logging/log.h>
#include <zephyr/fs/fs.h>
#include <ff.h>
LOG_MODULE_REGISTER(main);
#if defined(CONFIG_FAT_FILESYSTEM_ELM)
#include <ff.h>
/*
* 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 = { @@ -30,8 +32,31 @@ static struct fs_mount_t mp = {
.fs_data = &fat_fs,
};
#elif defined(CONFIG_FILE_SYSTEM_EXT2)
#include <zephyr/fs/ext2.h>
#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) @@ -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) @@ -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) @@ -126,6 +151,8 @@ int main(void)
printk("Error mounting disk.\n");
}
fs_unmount(&mp);
while (1) {
k_sleep(K_MSEC(1000));
}
Loading…
Cancel
Save