Skip to content
Permalink
Browse files

subsys/fs: add support for littlefs

littlefs is a fail-safe filesystem from ARM Mbed that has wear-leveling
capabilities.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Signed-off-by: Jim Paris <jim@bolt.io>
  • Loading branch information...
pabigot authored and carlescufi committed Jul 21, 2019
1 parent b8be48e commit fb73fcd4baf360666b51627bfca38b659a74a4e1
Showing with 781 additions and 6 deletions.
  1. +1 −0 CODEOWNERS
  2. +1 −0 include/fs/fs.h
  3. +1 −1 include/fs/fs_interface.h
  4. +39 −0 include/fs/littlefs.h
  5. +7 −5 subsys/fs/CMakeLists.txt
  6. +64 −0 subsys/fs/Kconfig
  7. +665 −0 subsys/fs/littlefs_fs.c
  8. +3 −0 west.yml
@@ -337,6 +337,7 @@
/subsys/fs/ @nashif
/subsys/fs/fcb/ @nvlsianpu
/subsys/fs/fuse_fs_access.c @vanwinkeljan
/subsys/fs/littlefs_fs.c @pabigot
/subsys/fs/nvs/ @Laczen
/subsys/logging/ @nordic-krch
/subsys/mgmt/ @carlescufi @nvlsianpu
@@ -48,6 +48,7 @@ enum fs_dir_entry_type {
enum fs_type {
FS_FATFS = 0,
FS_NFFS,
FS_LITTLEFS,
FS_TYPE_END,
};

@@ -11,7 +11,7 @@
extern "C" {
#endif

#ifdef CONFIG_FILE_SYSTEM_NFFS
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS) || defined(CONFIG_FILE_SYSTEM_NFFS)
#define MAX_FILE_NAME 256
#else /* FAT_FS */
#define MAX_FILE_NAME 12 /* Uses 8.3 SFN */
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019 Bolt Innovation Management, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_FS_LITTLEFS_H_
#define ZEPHYR_INCLUDE_FS_LITTLEFS_H_

#include <zephyr/types.h>
#include <kernel.h>
#include <storage/flash_map.h>

#include <lfs.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @brief Filesystem info structure for LittleFS mount */
struct fs_littlefs {
/* These structures are filled automatically at mount. */
struct lfs lfs;
struct lfs_config cfg;
const struct flash_area *area;
struct k_mutex mutex;

/* Static buffers */
u8_t read_buffer[CONFIG_FS_LITTLEFS_CACHE_SIZE];
u8_t prog_buffer[CONFIG_FS_LITTLEFS_CACHE_SIZE];
/* Multiple of 8 bytes, but 4-byte aligned (littlefs #239) */
u32_t lookahead_buffer[CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE / sizeof(u32_t)];
};

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_INCLUDE_FS_LITTLEFS_H_ */
@@ -6,14 +6,16 @@ if(CONFIG_FILE_SYSTEM)
zephyr_library()
zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
zephyr_library_sources(fs.c fs_impl.c)
zephyr_library_sources_ifdef(CONFIG_FAT_FILESYSTEM_ELM fat_fs.c)
zephyr_library_sources_ifdef(CONFIG_FILE_SYSTEM_NFFS nffs_fs.c)
zephyr_library_sources_ifdef(CONFIG_FILE_SYSTEM_SHELL shell.c)
zephyr_library_sources_ifdef(CONFIG_FAT_FILESYSTEM_ELM fat_fs.c)
zephyr_library_sources_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS littlefs_fs.c)
zephyr_library_sources_ifdef(CONFIG_FILE_SYSTEM_NFFS nffs_fs.c)
zephyr_library_sources_ifdef(CONFIG_FILE_SYSTEM_SHELL shell.c)

zephyr_library_link_libraries(FS)

target_link_libraries_ifdef(CONFIG_FAT_FILESYSTEM_ELM FS INTERFACE ELMFAT)
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS FS INTERFACE NFFS)
target_link_libraries_ifdef(CONFIG_FAT_FILESYSTEM_ELM FS INTERFACE ELMFAT)
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS FS INTERFACE LITTLEFS)
target_link_libraries_ifdef(CONFIG_FILE_SYSTEM_NFFS FS INTERFACE NFFS)
endif()

add_subdirectory_ifdef(CONFIG_FCB ./fcb)
@@ -39,6 +39,13 @@ config FILE_SYSTEM_NFFS
Note: NFFS requires 1-byte unaligned access to flash thus it
will not work on devices that support only aligned flash access.

config FILE_SYSTEM_LITTLEFS
bool "LittleFS file system support"
depends on FLASH_MAP
depends on FLASH_PAGE_LAYOUT
help
Enables LittleFS file system support.

config FILE_SYSTEM_SHELL
bool "Enable file system shell"
depends on SHELL
@@ -121,6 +128,63 @@ config NFFS_FILESYSTEM_MAX_BLOCK_SIZE

endmenu

menu "LittleFS Settings"
visible if FILE_SYSTEM_LITTLEFS

config FS_LITTLEFS_NUM_FILES
int "Maximum number of opened files"
default 4
help
This is a global maximum across all mounted littlefs filesystems.

config FS_LITTLEFS_NUM_DIRS
int "Maximum number of opened directories"
default 4
help
This is a global maximum across all mounted littlefs filesystems.

config FS_LITTLEFS_READ_SIZE
int "Minimum size of a block read"
default 16
help
All read operations will be a multiple of this value.

config FS_LITTLEFS_PROG_SIZE
int "Minimum size of a block program"
default 16
help
All program operations will be a multiple of this value.

config FS_LITTLEFS_CACHE_SIZE
int "Size of block caches in bytes"
default 64
help
Each cache buffers a portion of a block in RAM. The littlefs
needs a read cache, a program cache, and one additional cache
per file. Larger caches can improve performance by storing
more data and reducing the number of disk accesses. Must be a
multiple of the read and program sizes of the underlying flash
device, and a factor of the block size.

config FS_LITTLEFS_LOOKAHEAD_SIZE
int "Size of lookahead buffer in bytes"
default 32
help
A larger lookahead buffer increases the number of blocks found
during an allocation pass. The lookahead buffer is stored as a
compact bitmap, so each byte of RAM can track 8 blocks. Must
be a multiple of 8.

config FS_LITTLEFS_BLOCK_CYCLES
int "Number of erase cycles before moving data to another block"
default 512
help
For dynamic wear leveling, the number of erase cycles before data
is moved to another block. Set to a non-positive value to
disable leveling.

endmenu

endif # FILE_SYSTEM

source "subsys/fs/fcb/Kconfig"

0 comments on commit fb73fcd

Please sign in to comment.
You can’t perform that action at this time.