Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
/subsys/debug/ @nashif
/subsys/fs/ @nashif
/subsys/fs/fcb/ @nvlsianpu
/subsys/fs/fuse_fs_access.c @vanwinkeljan
/subsys/fs/nvs/ @Laczen
/subsys/logging/ @nordic-krch
/subsys/net/buf.c @jukkar @jhedberg @tbursztyka @pfalcon
Expand Down
38 changes: 38 additions & 0 deletions boards/posix/native_posix/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ The following peripherals are currently provided with this board:
configuration. In case the file does not exists the driver will take care of
creating the file, else the existing file is used.

The flash content can be accessed from the host system, as explained in the
`Host based flash access`_ section.

UART
****

Expand Down Expand Up @@ -626,3 +629,38 @@ development by integrating more seamlessly with the host operating system:
A backend/"bottom" for Zephyr's CTF tracing subsystem which writes the tracing
data to a file in the host filesystem.
More information can be found in :ref:`Common Tracing Format <ctf>`

Host based flash access
***********************

If a flash device is present, the file system partitions on the flash
device can be exposed through the host file system by enabling
:option:`CONFIG_FUSE_FS_ACCESS`. This option enables a FUSE
(File system in User space) layer that maps the Zephyr file system calls to
the required UNIX file system calls, and provides access to the flash file
system partitions with normal operating system commands such as ``cd``,
``ls`` and ``mkdir``.

By default the partitions are exposed through the directory *flash* in the
current working directory. This directory can be changed via the command line
option *--flash-mount*. As this directory operates as a mount point for FUSE
you have to ensure that it exists before starting the native POSIX board.

On exit, the native POSIX board application will take care of unmounting the
directory. In the unfortunate case that the native POSIX board application
crashes, you can cleanup the stale mount point by using the program
``fusermount``::

$ fusermount -u flash

Note that this feature requires a 32-bit version of the FUSE library, with a
minimal version of 2.6, on the host system and ``pkg-config`` settings to
correctly pickup the FUSE install path and compiler flags.

On a Ubuntu 18.04 host system, for example, install the ``pkg-config`` and
``libfuse-dev:i386`` packages, and configure the pkg-config search path with
these commands::

$ sudo apt-get install pkg-config libfuse-dev:i386
$ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig

16 changes: 16 additions & 0 deletions include/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,22 @@ int fs_mount(struct fs_mount_t *mp);
*/
int fs_unmount(struct fs_mount_t *mp);

/**
* @brief Mount point read entry
*
* Read mount point entry
*
* @param number Pointer to mount point number
* @param name Pointer to mount point name
*
* @retval 0 Success
* @retval -ERRNO errno code if error
* @return On success \p number is incremented and \p name is set to mount
* point name. In case no mount point exists for the given \p number
* -ENOENT is returned and \p name is set to NULL.
*/
int fs_readmount(int *number, const char **name);

/**
* @brief File or directory status
*
Expand Down
9 changes: 9 additions & 0 deletions samples/subsys/shell/fs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(fs_shell)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
152 changes: 152 additions & 0 deletions samples/subsys/shell/fs/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
.. _shell-fs-sample:

File system shell example
#########################

Overview
********

This example provides shell access to a NFFS file system partition in flash.

Requirements
************

A board with NFFS file system support and UART console

Building
********

Native Posix
============

Before starting a build, make sure that the i386 pkconfig directory is in your
search path.

.. code-block:: console

export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig

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

See :ref:`native_posix` on how to connect to the UART.

Reel Board
==========

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

Running
*******

Once the board has booted, you will be presented with a shell prompt.
All file system related commands are available as sub-commands of fs.

Begin by mounting the NFSS file system.

.. code-block:: console

fs mount nffs /nffs

Files System Shell Commands
===========================

Mount
-----

Mount a file system partition to a given mount point

.. code-block:: console

fs mount (nffs|fat) <path>

Ls
--

List all files and directories in a given path

.. code-block:: console

fs ls [path]

Cd
--

Change current working directory to given path

.. code-block:: console

fs cd [path]

Pwd
---

List current working directory

.. code-block:: console

fs pwd

Write
-----

Write hexadecimal numbers to a given file.
Optionally a offset in the file can be given.

.. code-block:: console

fs write <path> [-o <offset>] <hex number> ...

Read
----

Read file and dump in hex and ASCII format

.. code-block:: console

fs read <path>

Trunc
-----

Truncate a given file

.. code-block:: console

fs trunc <path>

Mkdir
-----

Create a directory

.. code-block:: console

fs mkdir <path>

Rm
--

Remove a file or directory

.. code-block:: console

fs rm <path>

Flash Host Access
=================

For the Native POSIX board the flash partitions can be accessed from the host
Linux system.

By default the flash partitions are accessible through the directory *flash*
relative to the directory where the build is started.


2 changes: 2 additions & 0 deletions samples/subsys/shell/fs/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FUSE_FS_ACCESS=y

2 changes: 2 additions & 0 deletions samples/subsys/shell/fs/boards/reel_board.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_MPU_ALLOW_FLASH_WRITE=y

17 changes: 17 additions & 0 deletions samples/subsys/shell/fs/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CONFIG_FLASH=y

CONFIG_LOG=y

CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_SHELL=y

CONFIG_FLASH=y

CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_NFFS=y
CONFIG_FILE_SYSTEM_SHELL=y
CONFIG_FS_NFFS_FLASH_DEV_NAME="flash_ctrl"

CONFIG_LOG=y

6 changes: 6 additions & 0 deletions samples/subsys/shell/fs/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sample:
description: FS shell sample
name: FS shell
tests:
test_fs_shell:
platform_whitelist: reel_board
14 changes: 14 additions & 0 deletions samples/subsys/shell/fs/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
*
* SPDX-License-Identifier: Apache-2.0
*/


#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(app);

void main(void)
{
}
10 changes: 10 additions & 0 deletions samples/subsys/shell/shell.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _shell-samples:

Shell System Samples
####################

.. toctree::
:maxdepth: 1
:glob:

**/*
10 changes: 10 additions & 0 deletions subsys/fs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ endif()

add_subdirectory_ifdef(CONFIG_FCB ./fcb)
add_subdirectory_ifdef(CONFIG_NVS ./nvs)

if(CONFIG_FUSE_FS_ACCESS)
zephyr_library_named(FS_FUSE)
find_package(PkgConfig REQUIRED)
pkg_search_module(FUSE REQUIRED fuse)
zephyr_include_directories(${FUSE_INCLUDE_DIR})
zephyr_link_libraries(${FUSE_LIBRARIES})
zephyr_library_compile_definitions(_FILE_OFFSET_BITS=64)
zephyr_library_sources(fuse_fs_access.c)
endif()
6 changes: 6 additions & 0 deletions subsys/fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ config FILE_SYSTEM_SHELL
This shell provides basic browsing of the contents of the
file system.

config FUSE_FS_ACCESS
bool "Enable FUSE based access to file system partitions"
depends on ARCH_POSIX
help
Expose file system partitions to the host system through FUSE.

menu "FatFs Settings"
visible if FAT_FILESYSTEM_ELM

Expand Down
32 changes: 32 additions & 0 deletions subsys/fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,38 @@ int fs_unmount(struct fs_mount_t *mp)
return rc;
}

int fs_readmount(int *number, const char **name)
{
sys_dnode_t *node;
int rc = -ENOENT;
int cnt = 0;
struct fs_mount_t *itr = NULL;

*name = NULL;

k_mutex_lock(&mutex, K_FOREVER);

SYS_DLIST_FOR_EACH_NODE(&fs_mnt_list, node) {
if (*number == cnt) {
itr = CONTAINER_OF(node, struct fs_mount_t, node);
break;
}

++cnt;
}

k_mutex_unlock(&mutex);

if (itr != NULL) {
rc = 0;
*name = itr->mnt_point;
++(*number);
}

return rc;

}

/* Register File system */
int fs_register(enum fs_type type, struct fs_file_system_t *fs)
{
Expand Down
Loading