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>
This commit is contained in:
Peter A. Bigot 2019-07-21 11:28:29 -05:00 committed by Carles Cufí
commit fb73fcd4ba
8 changed files with 781 additions and 6 deletions

View file

@ -48,6 +48,7 @@ enum fs_dir_entry_type {
enum fs_type {
FS_FATFS = 0,
FS_NFFS,
FS_LITTLEFS,
FS_TYPE_END,
};

View file

@ -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 */

39
include/fs/littlefs.h Normal file
View file

@ -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_ */