Skip to content

Commit ee09fc5

Browse files
committed
samples: fs: Added FS shell sample
Added file system shell sample Signed-off-by: Jan Van Winkel <[email protected]>
1 parent 4726f28 commit ee09fc5

File tree

8 files changed

+222
-0
lines changed

8 files changed

+222
-0
lines changed

samples/subsys/fs/fs.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _fs-samples:
2+
3+
File System Samples
4+
###################
5+
6+
.. toctree::
7+
:maxdepth: 1
8+
:glob:
9+
10+
**/*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.13.1)
2+
macro(set_conf_file)
3+
if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf)
4+
set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf")
5+
elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf)
6+
set(CONF_FILE
7+
"prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf")
8+
else()
9+
set(CONF_FILE "prj.conf")
10+
endif()
11+
endmacro()
12+
13+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
14+
project(fs_shell)
15+
16+
FILE(GLOB app_sources src/*.c)
17+
target_sources(app PRIVATE ${app_sources})

samples/subsys/fs/shell/README.rst

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
.. _fs_shell-sample:
2+
3+
File system shell example
4+
#########################
5+
6+
Overview
7+
********
8+
9+
This example provides shell access to a NFFS file system partition in flash.
10+
11+
Requirements
12+
************
13+
14+
A board with NFFS file system support and UART console
15+
16+
Building
17+
********
18+
19+
Native Posix
20+
============
21+
22+
Before starting a build, make sure that the i386 pkconfig directory is in your
23+
search path.
24+
25+
.. code-block:: console
26+
27+
export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig
28+
29+
.. zephyr-app-commands::
30+
:zephyr-app: samples/subsys/fs/shell
31+
:board: native_posix
32+
:goals: build
33+
:compact:
34+
35+
See :ref:`native_posix` on how to connect to the UART.
36+
37+
Reel Board
38+
==========
39+
40+
.. zephyr-app-commands::
41+
:zephyr-app: samples/subsys/fs/shell
42+
:board: reel_board
43+
:goals: build
44+
:compact:
45+
46+
Running
47+
*******
48+
49+
Once the board has booted, you will be presented with a shell prompt.
50+
All file system related commands are available as sub-commands of fs.
51+
52+
Begin by mounting the NFSS file system.
53+
54+
.. code-block:: console
55+
56+
fs mount nfss /nffs
57+
58+
Files System Shell Commands
59+
===========================
60+
61+
Mount
62+
-----
63+
64+
Mount a file system partition to a given mount point
65+
66+
.. code-block:: console
67+
68+
fs mount (nffs|fat) <path>
69+
70+
Ls
71+
--
72+
73+
List all files and directories in a given path
74+
75+
.. code-block:: console
76+
77+
fs ls [path]
78+
79+
Cd
80+
--
81+
82+
Change current working directory to given path
83+
84+
.. code-block:: console
85+
86+
fs cd [path]
87+
88+
Pwd
89+
---
90+
91+
List current working directory
92+
93+
.. code-block:: console
94+
95+
fs pwd
96+
97+
Write
98+
-----
99+
100+
Write hexadecimal numbers to a given file.
101+
Optionally a offset in the file can be given.
102+
103+
.. code-block:: console
104+
105+
fs write <path> [-o <offset>] <hex number> ...
106+
107+
Read
108+
----
109+
110+
Read file and dump in hex and ASCII format
111+
112+
.. code-block:: console
113+
114+
fs read <path>
115+
116+
Trunc
117+
-----
118+
119+
Truncate a given file
120+
121+
.. code-block:: console
122+
123+
fs trunc <path>
124+
125+
Mkdir
126+
-----
127+
128+
Create a directory
129+
130+
.. code-block:: console
131+
132+
fs mkdir <path>
133+
134+
Rm
135+
--
136+
137+
Remove a file or directory
138+
139+
.. code-block:: console
140+
141+
fs rm <path>
142+
143+
Flash Host Access
144+
=================
145+
146+
For the Native POSIX board the flash partitions can be accessed from the host
147+
Linux system.
148+
149+
By default the flash partitions are accessible through the directory *flash*
150+
relative to the directory where the build is started.
151+
152+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_NATIVE_POSIX_FUSE_FLASH_ACCESS=y
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_MPU_ALLOW_FLASH_WRITE=y
2+

samples/subsys/fs/shell/prj.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CONFIG_FLASH=y
2+
3+
CONFIG_LOG=y
4+
5+
CONFIG_HEAP_MEM_POOL_SIZE=16384
6+
7+
CONFIG_CONSOLE=y
8+
9+
CONFIG_SHELL=y
10+
11+
CONFIG_FLASH=y
12+
13+
CONFIG_FILE_SYSTEM=y
14+
CONFIG_FILE_SYSTEM_NFFS=y
15+
CONFIG_FILE_SYSTEM_SHELL=y
16+
CONFIG_FS_NFFS_FLASH_DEV_NAME="flash_ctrl"
17+
18+
CONFIG_LOG=y
19+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sample:
2+
description: FS shell sample
3+
name: FS shell
4+
tests:
5+
test_fs_shell:
6+
platform_whitelist: reel_board

samples/subsys/fs/shell/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2019 Jan Van Winkel <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
9+
#include <logging/log.h>
10+
LOG_MODULE_REGISTER(app);
11+
12+
void main(void)
13+
{
14+
}

0 commit comments

Comments
 (0)