Skip to content
Permalink
Browse files

subsys/fs/shell: add littlefs support

Add support for the littlefs file system in the fs shell.  Update
the sample to use the same partition configuration as the littlefs
example for the SPI NOR test platform.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information...
pabigot authored and carlescufi committed Jul 22, 2019
1 parent cfa64bd commit 5fe2591074a9a2eb6969cdc783855467e28c9a8e
@@ -44,6 +44,18 @@ Reel Board
:goals: build
:compact:

Particle Xenon
==============

This target is customized to support the same SPI NOR partition table as
the :ref:`littlefs-sample`.

.. zephyr-app-commands::
:zephyr-app: samples/subsys/shell/fs
:board: particle_xenon
:goals: build
:compact:

Running
*******

@@ -0,0 +1,8 @@
#
# Copyright (c) 2019 Peter Bigot Consulting, LLC
#
# SPDX-License-Identifier: Apache-2.0
#
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2019 Peter Bigot Consulting, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

/delete-node/ &storage_partition;

&mx25l32 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

/* This is the littlefs v1 file system pre-installed
* by Particle.
*/
littlefs_partition: partition@0 {
label = "littlefs";
reg = <0x00000000 0x00200000>;
};
/* A 16 KiBy partition to use for the test. */
storage_partition: partition@200000 {
label = "storage";
reg = <0x00200000 0x00004000>;
};
/* A bigger partition for something else. */
partition@220000 {
label = "scratch";
reg = <0x00204000 0x001fc000>;
};
};
};
@@ -1,16 +1,18 @@
CONFIG_FLASH=y

CONFIG_LOG=y
#CONFIG_FS_LOG_LEVEL_DBG=y

CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_SHELL=y

CONFIG_FLASH=y
CONFIG_SHELL_LOG_LEVEL_INF=y

CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_NFFS=y
CONFIG_FILE_SYSTEM_SHELL=y

CONFIG_LOG=y
CONFIG_FILE_SYSTEM_NFFS=y

CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
@@ -31,14 +31,26 @@ static struct fs_mount_t fatfs_mnt = {
#ifdef CONFIG_FILE_SYSTEM_NFFS
#include <nffs/nffs.h>
#define NFFS_MNTP "/nffs"
/* NFFS work area strcut */
/* NFFS work area struct */
static struct nffs_flash_desc flash_desc;
/* mounting info */
static struct fs_mount_t nffs_mnt = {
.type = FS_NFFS,
.fs_data = &flash_desc,
};
#endif
/* LITTLEFS */
#ifdef CONFIG_FILE_SYSTEM_LITTLEFS
#include <fs/littlefs.h>
#include <storage/flash_map.h>

FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(lfs_data);
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &lfs_data,
.storage_dev = (void *)DT_FLASH_AREA_STORAGE_ID,
};
#endif

#define BUF_CNT 64

@@ -404,7 +416,9 @@ static int cmd_write(const struct shell *shell, size_t argc, char **argv)
return 0;
}

#if defined(CONFIG_FILE_SYSTEM_NFFS) || defined(CONFIG_FAT_FILESYSTEM_ELM)
#if defined(CONFIG_FAT_FILESYSTEM_ELM) \
|| defined(CONFIG_FILE_SYSTEM_LITTLEFS) \
|| defined(CONFIG_FILE_SYSTEM_NFFS)
static char *mntpt_prepare(char *mntpt)
{
char *cpy_mntpt;
@@ -481,14 +495,50 @@ static int cmd_mount_nffs(const struct shell *shell, size_t argc, char **argv)
}
#endif

#if defined(CONFIG_FILE_SYSTEM_NFFS) || defined(CONFIG_FAT_FILESYSTEM_ELM)
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)

static int cmd_mount_littlefs(const struct shell *shell, size_t argc, char **argv)
{
if (littlefs_mnt.mnt_point != NULL) {
return -EBUSY;
}

char *mntpt = mntpt_prepare(argv[1]);

if (!mntpt) {
shell_error(shell, "Failed to allocate mount point");
return -ENOEXEC; /* ?!? */
}

littlefs_mnt.mnt_point = mntpt;

int rc = fs_mount(&littlefs_mnt);

if (rc != 0) {
shell_error(shell, "Error mounting %u as littlefs: %d", rc);
return -ENOEXEC;
}

return rc;
}
#endif

#if defined(CONFIG_FAT_FILESYSTEM_ELM) \
|| defined(CONFIG_FILE_SYSTEM_LITTLEFS) \
|| defined(CONFIG_FILE_SYSTEM_NFFS)
SHELL_STATIC_SUBCMD_SET_CREATE(sub_fs_mount,
#if defined(CONFIG_FAT_FILESYSTEM_ELM)
SHELL_CMD_ARG(fat, NULL,
"Mount fatfs. fs mount fat <mount-point>",
cmd_mount_fat, 2, 0),
#endif

#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
SHELL_CMD_ARG(littlefs, NULL,
"Mount littlefs. fs mount littlefs <mount-point>",
cmd_mount_littlefs, 2, 0),
#endif

#if defined(CONFIG_FILE_SYSTEM_NFFS)
SHELL_CMD_ARG(nffs, NULL,
"Mount nffs. fs mount nffs <mount-point>",
@@ -503,7 +553,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_fs,
SHELL_CMD(cd, NULL, "Change working directory", cmd_cd),
SHELL_CMD(ls, NULL, "List files in current directory", cmd_ls),
SHELL_CMD_ARG(mkdir, NULL, "Create directory", cmd_mkdir, 2, 0),
#if defined(CONFIG_FILE_SYSTEM_NFFS) || defined(CONFIG_FAT_FILESYSTEM_ELM)
#if defined(CONFIG_FAT_FILESYSTEM_ELM) \
|| defined(CONFIG_FILE_SYSTEM_LITTLEFS) \
|| defined(CONFIG_FILE_SYSTEM_NFFS)
SHELL_CMD(mount, &sub_fs_mount,
"<Mount fs, syntax:- fs mount <fs type> <mount-point>", NULL),
#endif

0 comments on commit 5fe2591

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