From ca0ec90742a92748c67c289f80bd3225959848e1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 16:39:44 +0900 Subject: [PATCH 1/6] fs/littlefs: don't use lfs_getsetattr.patch unless FS_LITTLEFS_ATTR_UPDATE --- fs/littlefs/lfs_vfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index d2d6782e9dd5d..55f127314c1fe 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -742,7 +742,9 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf) FAR struct littlefs_mountpt_s *fs; FAR struct littlefs_file_s *priv; FAR struct inode *inode; +#ifdef CONFIG_FS_LITTLEFS_ATTR_UPDATE struct littlefs_attr_s attr; +#endif int ret; memset(buf, 0, sizeof(*buf)); @@ -768,6 +770,7 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf) goto errout; } +#ifdef CONFIG_FS_LITTLEFS_ATTR_UPDATE ret = littlefs_convert_result(lfs_file_getattr(&fs->lfs, &priv->file, 0, &attr, sizeof(attr))); if (ret < 0) @@ -791,6 +794,7 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf) buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull; buf->st_ctim.tv_sec = attr.at_ctim / 1000000000ull; buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull; +#endif /* CONFIG_FS_LITTLEFS_ATTR_UPDATE */ buf->st_blksize = fs->cfg.block_size; buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize; From 129708a23d0afed3f98439d4bf4929519dbe075a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 20:21:33 +0900 Subject: [PATCH 2/6] fs/littlefs: stop applying local patches for unknown versions of littlefs Because they are not expected to apply cleanly. In that case, disable all features which require the local patches. Note: lfs_util.patch is actually necessary regardless of the littlefs version. It should be ok to drop it for the simplest flat memory model configurations with a single heap though. I plan to fix it once littlefs 2.9.4 is released. Tested with esp32s3-devkitc:toywasm + CONFIG_FS_LITTLEFS_VERSION="v2.9.3". --- fs/littlefs/CMakeLists.txt | 38 ++++++++++++++++++++++++-------------- fs/littlefs/Kconfig | 25 +++++++++++++++++++++++++ fs/littlefs/Make.defs | 2 ++ fs/littlefs/lfs_vfs.c | 6 ++++++ 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/fs/littlefs/CMakeLists.txt b/fs/littlefs/CMakeLists.txt index b81e07405e607..4ce674d781aa7 100644 --- a/fs/littlefs/CMakeLists.txt +++ b/fs/littlefs/CMakeLists.txt @@ -22,20 +22,30 @@ if(CONFIG_FS_LITTLEFS) if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/littlefs) - - FetchContent_Declare( - littlefs - URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz - SOURCE_DIR - ${CMAKE_CURRENT_LIST_DIR}/littlefs - BINARY_DIR - ${CMAKE_BINARY_DIR}/fs/littlefs/littlefs - PATCH_COMMAND - patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch && patch -p2 -d - ${CMAKE_CURRENT_LIST_DIR} < ${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch - && patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} < - ${CMAKE_CURRENT_LIST_DIR}/lfs_getsetattr.patch) + if(CONFIG_FS_LITTLEFS_LOCAL_PATCHES) + FetchContent_Declare( + littlefs + URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz + SOURCE_DIR + ${CMAKE_CURRENT_LIST_DIR}/littlefs + BINARY_DIR + ${CMAKE_BINARY_DIR}/fs/littlefs/littlefs + PATCH_COMMAND + patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} < + ${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch && patch -p2 -d + ${CMAKE_CURRENT_LIST_DIR} < + ${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch && patch -p2 -d + ${CMAKE_CURRENT_LIST_DIR} < + ${CMAKE_CURRENT_LIST_DIR}/lfs_getsetattr.patch) + else() + FetchContent_Declare( + littlefs + URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz + SOURCE_DIR + ${CMAKE_CURRENT_LIST_DIR}/littlefs + BINARY_DIR + ${CMAKE_BINARY_DIR}/fs/littlefs/littlefs) + endif() FetchContent_MakeAvailable(littlefs) endif() diff --git a/fs/littlefs/Kconfig b/fs/littlefs/Kconfig index 517d500ef064e..af8af03fe38b8 100644 --- a/fs/littlefs/Kconfig +++ b/fs/littlefs/Kconfig @@ -120,13 +120,38 @@ config FS_LITTLEFS_ATTR_MAX Note: Many of tools to generate LITTLEFS images use 1022 for this by default. +config FS_LITTLEFS_LOCAL_PATCHES + bool + depends on FS_LITTLEFS_VERSION = "v2.5.1" + default y + ---help--- + For the internal use to control the application of NuttX local + patches for LITTLEFS. + This is NOT expected to be tweaked directly by users. + config FS_LITTLEFS_ATTR_UPDATE bool "LITTLEFS update attributes" depends on FS_LITTLEFS_ATTR_MAX > 0 + depends on FS_LITTLEFS_LOCAL_PATCHES default y ---help--- Enable support for attributes when create a file. + CAVEAT: This feature is implemented with NuttX specific + modifications to LITTLEFS v2.5.1. The modifications might + not be compatible with other versions of LITTLEFS. + +config FS_LITTLEFS_GETPATH + bool "LITTLEFS FIOC_FILEPATH ioctl support" + depends on FS_LITTLEFS_LOCAL_PATCHES + default y + ---help--- + FIOC_FILEPATH ioctl support for LITTLEFS file system. + + CAVEAT: This feature is implemented with NuttX specific + modifications to LITTLEFS v2.5.1. The modifications might + not be compatible with other versions of LITTLEFS. + config FS_LITTLEFS_VERSION string "LITTLEFS version to use" default "v2.5.1" diff --git a/fs/littlefs/Make.defs b/fs/littlefs/Make.defs index afabeb94079df..ae73a36f076f1 100644 --- a/fs/littlefs/Make.defs +++ b/fs/littlefs/Make.defs @@ -55,9 +55,11 @@ $(LITTLEFS_TARBALL): .littlefsunpack: $(LITTLEFS_TARBALL) $(Q) tar zxf littlefs/$(LITTLEFS_TARBALL) -C littlefs $(Q) mv littlefs/littlefs-* littlefs/littlefs +ifeq ($(CONFIG_FS_LITTLEFS_LOCAL_PATCHES),y) $(Q) git apply littlefs/lfs_util.patch $(Q) git apply littlefs/lfs_getpath.patch $(Q) git apply littlefs/lfs_getsetattr.patch +endif $(Q) touch littlefs/.littlefsunpack # Download and unpack tarball if no git repo found diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index 55f127314c1fe..0960142134847 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -598,14 +598,18 @@ static off_t littlefs_seek(FAR struct file *filep, off_t offset, int whence) static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct littlefs_mountpt_s *fs; +#ifdef CONFIG_FS_LITTLEFS_GETPATH FAR struct littlefs_file_s *priv; +#endif FAR struct inode *inode; FAR struct inode *drv; int ret; /* Recover our private data from the struct file instance */ +#ifdef CONFIG_FS_LITTLEFS_GETPATH priv = filep->f_priv; +#endif inode = filep->f_inode; fs = inode->i_private; drv = fs->drv; @@ -618,6 +622,7 @@ static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) switch (cmd) { +#ifdef CONFIG_FS_LITTLEFS_GETPATH case FIOC_FILEPATH: { FAR char *path = (FAR char *)(uintptr_t)arg; @@ -637,6 +642,7 @@ static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } } break; +#endif default: { From babd48c0052b7e1ede4f1219dc0d54b690eef935 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 16:38:38 +0900 Subject: [PATCH 3/6] fs/littlefs: disable -Wshadow and explain why --- fs/littlefs/CMakeLists.txt | 4 ++++ fs/littlefs/Make.defs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/fs/littlefs/CMakeLists.txt b/fs/littlefs/CMakeLists.txt index 4ce674d781aa7..03f1821d5e68f 100644 --- a/fs/littlefs/CMakeLists.txt +++ b/fs/littlefs/CMakeLists.txt @@ -61,6 +61,10 @@ if(CONFIG_FS_LITTLEFS) -DLFS_FILE_MAX=${CONFIG_FS_LITTLEFS_FILE_MAX} -DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX}) + # Note: the littlefs upstream doesn't seems to care -Wshadow cf. + # https://github.com/littlefs-project/littlefs/pull/873 + target_compile_options(fs PRIVATE -Wno-shadow) + target_sources(fs PRIVATE lfs_vfs.c ${CMAKE_CURRENT_LIST_DIR}/littlefs/lfs.c ${CMAKE_CURRENT_LIST_DIR}/littlefs/lfs_util.c) diff --git a/fs/littlefs/Make.defs b/fs/littlefs/Make.defs index ae73a36f076f1..9a55eabf0f258 100644 --- a/fs/littlefs/Make.defs +++ b/fs/littlefs/Make.defs @@ -37,6 +37,10 @@ CSRCS += lfs.c lfs_util.c DEPPATH += --dep-path littlefs/littlefs VPATH += :littlefs/littlefs +# Note: the littlefs upstream doesn't seems to care -Wshadow +# cf. https://github.com/littlefs-project/littlefs/pull/873 +CFLAGS += -Wno-shadow + CFLAGS += -DLFS_TRACE=finfo CFLAGS += -DLFS_DEBUG=finfo CFLAGS += -DLFS_WARN=fwarn From 679dbb8085cf715429863edf4819842640b31fe9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 16:41:02 +0900 Subject: [PATCH 4/6] fs/littlefs: add LFS_MULTIVERSION support --- fs/littlefs/CMakeLists.txt | 3 ++- fs/littlefs/Kconfig | 17 +++++++++++++++++ fs/littlefs/Make.defs | 3 +++ fs/littlefs/lfs_vfs.c | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/littlefs/CMakeLists.txt b/fs/littlefs/CMakeLists.txt index 03f1821d5e68f..236dde467352a 100644 --- a/fs/littlefs/CMakeLists.txt +++ b/fs/littlefs/CMakeLists.txt @@ -59,7 +59,8 @@ if(CONFIG_FS_LITTLEFS) -DLFS_CONFIG=${CMAKE_CURRENT_LIST_DIR}/lfs_vfs.h -DLFS_NAME_MAX=${CONFIG_FS_LITTLEFS_NAME_MAX} -DLFS_FILE_MAX=${CONFIG_FS_LITTLEFS_FILE_MAX} - -DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX}) + -DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX} + $<$:-DLFS_MULTIVERSION>) # Note: the littlefs upstream doesn't seems to care -Wshadow cf. # https://github.com/littlefs-project/littlefs/pull/873 diff --git a/fs/littlefs/Kconfig b/fs/littlefs/Kconfig index af8af03fe38b8..adefd7fbfafbd 100644 --- a/fs/littlefs/Kconfig +++ b/fs/littlefs/Kconfig @@ -158,4 +158,21 @@ config FS_LITTLEFS_VERSION ---help--- The LITTLEFS version to use. +config FS_LITTLEFS_MULTI_VERSION + bool "Support multiple on-disk versions" + default n + ---help--- + Enable LFS_MULTIVERSION for LITTLEFS file system + +config FS_LITTLEFS_DISK_VERSION + hex "LITTLEFS on-disk version" + default 0x0 + depends on FS_LITTLEFS_MULTI_VERSION + ---help--- + The LITTLEFS disk version to use. + + 0 means to leave it to the default from the LITTLEFS. + 0x00020000 means 2.0. + 0x00020001 means 2.1. + endif diff --git a/fs/littlefs/Make.defs b/fs/littlefs/Make.defs index 9a55eabf0f258..57109d575510b 100644 --- a/fs/littlefs/Make.defs +++ b/fs/littlefs/Make.defs @@ -50,6 +50,9 @@ CFLAGS += -DLFS_CONFIG=../lfs_vfs.h CFLAGS += -DLFS_NAME_MAX=$(CONFIG_FS_LITTLEFS_NAME_MAX) CFLAGS += -DLFS_FILE_MAX=$(CONFIG_FS_LITTLEFS_FILE_MAX) CFLAGS += -DLFS_ATTR_MAX=$(CONFIG_FS_LITTLEFS_ATTR_MAX) +ifeq ($(CONFIG_FS_LITTLEFS_MULTI_VERSION),y) +CFLAGS += -DLFS_MULTIVERSION +endif LITTLEFS_TARBALL = $(CONFIG_FS_LITTLEFS_VERSION).tar.gz diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index 0960142134847..01f28464a0622 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -1323,6 +1323,10 @@ static int littlefs_bind(FAR struct inode *driver, FAR const void *data, fs->cfg.lookahead_size = CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE; #endif +#ifdef CONFIG_FS_LITTLEFS_MULTI_VERSION + fs->cfg.disk_version = CONFIG_FS_LITTLEFS_DISK_VERSION; +#endif + /* Then get information about the littlefs filesystem on the devices * managed by this driver. */ From ff038587c9d35606b7eb86e26b8d1bebfbb1f3b9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 20:46:10 +0900 Subject: [PATCH 5/6] linum-stm32h753bi/littlefs: use littlefs 2.9.3 I chose this config just because it seems to support cmake-based build. --- boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig b/boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig index 8cf685d943354..493f9695aa73c 100644 --- a/boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig +++ b/boards/arm/stm32h7/linum-stm32h753bi/configs/littlefs/defconfig @@ -29,6 +29,8 @@ CONFIG_DEFAULT_TASK_STACKSIZE=4096 CONFIG_EXAMPLES_ALARM=y CONFIG_EXAMPLES_ALARM_STACKSIZE=2048 CONFIG_FS_LITTLEFS=y +CONFIG_FS_LITTLEFS_MULTI_VERSION=y +CONFIG_FS_LITTLEFS_VERSION="v2.9.3" CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INTELHEX_BINARY=y CONFIG_LIBM=y From c44fa656f1c2fffe7492de694166ee10a91b9778 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 26 Nov 2024 21:01:41 +0900 Subject: [PATCH 6/6] esp32s3-devkit/toywasm: use littlefs 2.9.3 I chose this config because I have a hardware and I occasionally use littlefs on its flash. --- boards/xtensa/esp32s3/esp32s3-devkit/configs/toywasm/defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/toywasm/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/toywasm/defconfig index 6b0aea34dc1bf..8f034d79bf068 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/toywasm/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/toywasm/defconfig @@ -35,6 +35,8 @@ CONFIG_ESP32S3_WIFI=y CONFIG_EXAMPLES_RANDOM=y CONFIG_FS_LARGEFILE=y CONFIG_FS_LITTLEFS=y +CONFIG_FS_LITTLEFS_MULTI_VERSION=y +CONFIG_FS_LITTLEFS_VERSION="v2.9.3" CONFIG_FS_PROCFS=y CONFIG_HOST_MACOS=y CONFIG_IDLETHREAD_STACKSIZE=3072