fs: littlefs: Extend sample program to test block devices
Up till now, the littlefs sample program was only supporting the flash medium. However, it would be also welcome to be able to test reading and writing data from littlefs stored on block devices - like SD card. In this case we do use the block API, to read and write data to it. To achieve this goal - the CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC define has been introduced. One can change the disk mount point by defining board specific CONFIG_SDMMC_VOLUME_NAME. The test for nucleo board equipped with SD card shall be built with: west build -p always -b nucleo_h743zi ./zephyr/samples/subsys/fs/littlefs \ -DCONF_FILE=prj_blk.conf Moreover, the README.rst has been extended to describe running this test on block devices. Signed-off-by: Lukasz Majewski <lukma@denx.de>
This commit is contained in:
parent
7710f5ef61
commit
2c8a7e7757
6 changed files with 113 additions and 1 deletions
|
@ -17,6 +17,8 @@ choice
|
||||||
config APP_LITTLEFS_STORAGE_FLASH
|
config APP_LITTLEFS_STORAGE_FLASH
|
||||||
bool "Use flash memory backend"
|
bool "Use flash memory backend"
|
||||||
|
|
||||||
|
config APP_LITTLEFS_STORAGE_BLK_SDMMC
|
||||||
|
bool "Use block device (e.g. SD MMC) backend"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
source "Kconfig.zephyr"
|
source "Kconfig.zephyr"
|
||||||
|
|
|
@ -19,6 +19,9 @@ Other information about the file system is also displayed.
|
||||||
Requirements
|
Requirements
|
||||||
************
|
************
|
||||||
|
|
||||||
|
Flash memory device
|
||||||
|
-------------------
|
||||||
|
|
||||||
The partition labeled "storage" will be used for the file system; see
|
The partition labeled "storage" will be used for the file system; see
|
||||||
:ref:`flash_map_api`. If that area does not already have a
|
:ref:`flash_map_api`. If that area does not already have a
|
||||||
compatible littlefs file system its contents will be replaced by an
|
compatible littlefs file system its contents will be replaced by an
|
||||||
|
@ -38,15 +41,57 @@ After the file system is mounted you'll also see::
|
||||||
This error is also normal for Zephyr not finding a file (the boot count,
|
This error is also normal for Zephyr not finding a file (the boot count,
|
||||||
in this case).
|
in this case).
|
||||||
|
|
||||||
|
Block device (e.g. SD card)
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
One needs to prepare the SD card with littlefs file system on
|
||||||
|
the host machine with the `lfs`_ program.
|
||||||
|
|
||||||
|
.. _lfs:
|
||||||
|
https://www.thevtool.com/mounting-littlefs-on-linux-machine/
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
sudo chmod a+rw /dev/sda
|
||||||
|
lfs -d -s -f --read_size=512 --prog_size=512 --block_size=512 --cache_size=512 --lookahead_size=8192 --format /dev/sda
|
||||||
|
lfs -d -s -f --read_size=512 --prog_size=512 --block_size=512 --cache_size=512 --lookahead_size=8192 /dev/sda ./mnt_littlefs
|
||||||
|
cd ./mnt_littlefs
|
||||||
|
echo -en '\x01' > foo.txt
|
||||||
|
cd -
|
||||||
|
fusermount -u ./mnt_littlefs
|
||||||
|
|
||||||
|
|
||||||
Building and Running
|
Building and Running
|
||||||
********************
|
********************
|
||||||
|
|
||||||
|
Flash memory device
|
||||||
|
-------------------
|
||||||
|
|
||||||
This example should work on any board that provides a "storage"
|
This example should work on any board that provides a "storage"
|
||||||
partition. Two tested board targets are described below.
|
partition. Two tested board targets are described below.
|
||||||
|
|
||||||
You can set ``CONFIG_APP_WIPE_STORAGE`` to force the file system to be
|
You can set ``CONFIG_APP_WIPE_STORAGE`` to force the file system to be
|
||||||
recreated.
|
recreated.
|
||||||
|
|
||||||
|
Block device (e.g. SD card)
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
This example has been devised and initially tested on :ref:`Nucleo H743ZI <nucleo_h743zi_board>`
|
||||||
|
board. It can be also run on any other board with SD card connected to it.
|
||||||
|
|
||||||
|
To build the test:
|
||||||
|
|
||||||
|
.. zephyr-app-commands::
|
||||||
|
:zephyr-app: samples/subsys/fs/littlefs
|
||||||
|
:board: nucleo_h743zi
|
||||||
|
:goals: build flash
|
||||||
|
:gen-args: -DCONF_FILE=prj_blk.conf
|
||||||
|
:compact:
|
||||||
|
|
||||||
|
One can also set ``CONFIG_SDMMC_VOLUME_NAME`` to provide the mount point name
|
||||||
|
for `littlefs` file system block device.
|
||||||
|
|
||||||
|
|
||||||
NRF52840 Development Kit
|
NRF52840 Development Kit
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Lukasz Majewski, DENX Software Engineering GmbH
|
* Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
/delete-node/ &storage_partition;
|
/delete-node/ &storage_partition;
|
||||||
|
|
||||||
|
&sdmmc1 {
|
||||||
|
status = "okay";
|
||||||
|
pinctrl-0 = <&sdmmc1_d0_pc8
|
||||||
|
&sdmmc1_ck_pc12
|
||||||
|
&sdmmc1_cmd_pd2>;
|
||||||
|
|
||||||
|
pinctrl-names = "default";
|
||||||
|
};
|
||||||
|
|
||||||
&quadspi {
|
&quadspi {
|
||||||
pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk2_ncs_pc11
|
pinctrl-0 = <&quadspi_clk_pf10 &quadspi_bk2_ncs_pc11
|
||||||
&quadspi_bk2_io0_pe7 &quadspi_bk2_io1_pe8
|
&quadspi_bk2_io0_pe7 &quadspi_bk2_io1_pe8
|
||||||
|
|
9
samples/subsys/fs/littlefs/boards/nucleo_h743zi_blk.conf
Normal file
9
samples/subsys/fs/littlefs/boards/nucleo_h743zi_blk.conf
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
CONFIG_MAIN_STACK_SIZE=2048
|
||||||
|
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=8192
|
||||||
|
|
||||||
|
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=8192
|
26
samples/subsys/fs/littlefs/prj_blk.conf
Normal file
26
samples/subsys/fs/littlefs/prj_blk.conf
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Lukasz Majewski, DENX Software Engineering GmbH
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
CONFIG_DISK_ACCESS=y
|
||||||
|
CONFIG_DISK_DRIVERS=y
|
||||||
|
CONFIG_DISK_DRIVER_SDMMC=y
|
||||||
|
|
||||||
|
CONFIG_DEBUG=y
|
||||||
|
CONFIG_LOG=y
|
||||||
|
CONFIG_LOG_MODE_MINIMAL=y
|
||||||
|
|
||||||
|
CONFIG_FLASH=y
|
||||||
|
CONFIG_FLASH_MAP=y
|
||||||
|
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||||
|
|
||||||
|
CONFIG_FILE_SYSTEM=y
|
||||||
|
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||||
|
|
||||||
|
CONFIG_FS_LITTLEFS_BLK_DEV=y
|
||||||
|
CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC=y
|
||||||
|
|
||||||
|
CONFIG_NOCACHE_MEMORY=y
|
||||||
|
CONFIG_SDMMC_STM32_HWFC=y
|
|
@ -308,6 +308,27 @@ static int littlefs_mount(struct fs_mount_t *mp)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_APP_LITTLEFS_STORAGE_FLASH */
|
#endif /* CONFIG_APP_LITTLEFS_STORAGE_FLASH */
|
||||||
|
|
||||||
|
#ifdef CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC
|
||||||
|
struct fs_littlefs lfsfs;
|
||||||
|
static struct fs_mount_t __mp = {
|
||||||
|
.type = FS_LITTLEFS,
|
||||||
|
.fs_data = &lfsfs,
|
||||||
|
.flags = FS_MOUNT_FLAG_USE_DISK_ACCESS,
|
||||||
|
};
|
||||||
|
struct fs_mount_t *mp = &__mp;
|
||||||
|
|
||||||
|
static int littlefs_mount(struct fs_mount_t *mp)
|
||||||
|
{
|
||||||
|
static const char *disk_mount_pt = "/"CONFIG_SDMMC_VOLUME_NAME":";
|
||||||
|
static const char *disk_pdrv = CONFIG_SDMMC_VOLUME_NAME;
|
||||||
|
|
||||||
|
mp->storage_dev = (void *)disk_pdrv;
|
||||||
|
mp->mnt_point = disk_mount_pt;
|
||||||
|
|
||||||
|
return fs_mount(mp);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_APP_LITTLEFS_STORAGE_BLK_SDMMC */
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
char fname1[MAX_PATH_LEN];
|
char fname1[MAX_PATH_LEN];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue