Commit graph

247 commits

Author SHA1 Message Date
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Torsten Rasmussen aff31cf62b modules: littlefs: move CMake glue code from littlefs repo into Zephyr
Fixes: #40559

Moving CMakeLists.txt gluecode into Zephyr repo minimizes the patching
needed in LittleFS repo.

It provides a dedicate Zephyr LFS config header which will define the
equivalent LittleFS settings based upon Kconfig settings.
This further reduces the patching needed in LittleFS.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-03-02 15:34:11 +01:00
Gerard Marull-Paretas 56d5486fbf fs: nvs: introduce nvs_mount and deprecate nvs_init
Add a new API call to replace nvs_init: nvs_mount. The new API does the
same as nvs_init except that it assumes to be provided with a valid
flash device via `struct nvs_fs` `flash_device` field. Previously, it
was not possible to avoid the runtime overhead of device_get_binding()
even if the flash device was known at compile time.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-01 12:46:34 +01:00
Dominik Ermel d7db973b04 fs/fat_fs: Allow configuration of number of root entries
The commit adds FS_FATFS_MAX_ROOT_ENTRIES Kconfig option that allows
to select number of root node entries that will be allocated while
creating FAT file system on a device.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-02-22 08:14:20 -05:00
Boon Khai Ng e46d8a1d51 fat_fs: Add support for the "win" variable alignment in FATFS struct
This is to support Sypnosys Designware SDMMC controller read and write
operation where the buffer address is needed to be 16bytes and 512bytes
aligned. Adding macro FS_FATFS_WINDOW_ALIGNMENT to align the "win"
variable address in FATFS struct.

Signed-off-by: Boon Khai Ng <boon.khai.ng@intel.com>
2022-02-21 20:48:54 -05:00
Lukasz Majewski c9902412e6 fs: Extend the littlefs code to support block devices
Up till now the littlefs only has been supporting the flash medium in
Zephyr.

This change provides code to also use littlefs stored on the block
devices - like SD card (accessed via SPI).

When FS_LITTLEFS_BLK_DEV Kconfig option is defined, the support for
using littlefs on block devices is enabled.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2022-01-17 12:53:43 -05:00
Lukasz Majewski 6fa771f2d0 fs: littlefs: Rename *area (struct flash_area*) to *backend void pointer
The struct flash_area *area pointer has been renamed to void *backend
pointer.

This change is enabling further rework of the littlefs subsystem to work
with other backend devices (like block ones - i.e. SD card).

Signed-off-by: Lukasz Majewski <lukma@denx.de>
2022-01-17 12:53:43 -05:00
Dominik Ermel f5b27ca0bd fs: littlefs: Add processing of FS_MOUNT_FLAG_USE_DISK_ACCESS flag
Atempting to mount LittleFS with the flag will cause the fs_mount
to return -ENOSUP and log error message.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-12-06 08:08:26 -05:00
Dominik Ermel 5036043268 fs: fat_fs: Set FS_MOUNT_FLAG_USE_DISK_ACCESS on mount
Mounting FAT FS will set FS_MOUNT_FLAG_USE_DISK_ACCESS to the flags
of an object serving the mount point.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-12-06 08:08:26 -05:00
Dominik Ermel 2cb4d41e9d fs: Correct LOG_ERR messages for directory API calss
The commit changes messages of VFS API LOG_ERR calls to distinguish
between file and directory operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-11-09 16:04:34 -06:00
Dominik Ermel 3614f91887 fs: fs_open will only copy flags into fs_file_t structure on success
The fs_open copies open flags into fs_file_t structure for use with
other VFS API calls; the commit moves the operation into success path.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-11-09 11:58:12 +01:00
Dominik Ermel e489bb18a4 fs: Fix fs_statvfs returning 0 when statvfs not implemented
The fs_statvfs is supposed to return, as all VFS functions, -ENOTSUP
error when underlying file-system driver does not implement the
API call.
The fs_statvfs was returning 0 for success and when API call is not
implemented, which means it is indistinguishable whether stat
structure has been filled by diver with any data or not touched at all.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-11-09 11:19:40 +01:00
Pavel Hübner 104714394f kernel: Introduce K_MEM_SLAB_DEFINE_STATIC
As the already existing macro K_MEM_SLAB_DEFINE results in
two variable definitions, the preceding static modifier leads to
a seemingly working solution, though linkage conflicts will occur
when the same memory slab name is used across multiple modules.

The new K_MEM_SLAB_DEFINE_STATIC macro duplicates the functionality of
K_MEM_SLAB_DEFINE with the difference that the static keywords are
internally prepended before both variable definitions.

The implementation has been tested on my Zephyr project (the build
issue faded out). The documentation has been updated altogether
with all incorrect occurences of static K_MEM_SLAB_DEFINE.

Signed-off-by: Pavel Hübner <pavel.hubner@hardwario.com>
2021-11-07 05:36:48 -05:00
Artur Lipowski 29855b41b4 fs: allow to configure per-alloaction heap overhead
The size of overhead for each heap allocation can change after
heap implementation change and such change impacts automatic
calculation of heap size for littleFS.
This patch allows per-alloaction overhead to be configurable and then
automatic heap size calculation can be adjusted without code change.
This is a temporary fix until per-alloaction overhead value will be
available from kernel internals.

Fixes #36962

Signed-off-by: Artur Lipowski <Artur.Lipowski@hidglobal.com>
2021-10-29 06:09:43 -04:00
Dominik Ermel 6546397035 fs/shell: Fix formatting for output of ssize_t variable
Fix compilation error for devices where ssize_t can not
be formatted with %d, due to ssize_t not being equal int.

Fixes #39629

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-10-28 11:19:04 +02:00
Chris Reed b0ad42428c fs: core: remove include of <sys/stat.h> from fs.c.
This include is not used at all by fs.c. Zephyr includes a minimal
sys/stat.h, but only for the minimal libc.

Signed-off-by: Chris Reed <chris.reed@arm.com>
2021-10-16 06:30:23 -04:00
Krzysztof Chruscinski eb3375f47c shell: Add __printf_like to shell_fprintf
Add __printf_like modifier to validate strings used by shell.
Fixing warnings triggered by this change.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-10-14 16:32:19 -04:00
Emil Lindqvist f7dad07bb0 kconfig: add names to some choices
In order to be able to make a "choice" from any other
Kconfig.defconfig (-ish) file, the choice needs to be named.
This commit names a few choices.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-09-28 19:56:32 -04:00
Markus Fuchs b852bdd816 fs: fat_fs: Fix fs_statvfs when using variable sector sizes
The fs_statvfs function assumes FatFs is configured for a fixed sector
size and therefore may return wrong sector sizes when it is configured
for variable sector sizes instead. Fix that by returning the ssize
variable given in the file system object structure.

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2021-08-26 06:53:57 -04:00
Dominik Ermel 33a7c98789 fs/fatfs: Apply changes required for version 0.14b
The commit applies changes that are required by update of ELM Chan's
FAT FS driver update to version 0.14b.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-08-17 17:52:55 -04:00
Emil Lindqvist 1e9f1231fe logging: fs: treat absent file on stat as no error
There are multiple reasons to want to find out if file or
directory exists, for example to create it. Stating and
finding out it doesn't exist should not cause an LOG_ERR call as
this gives information to the user in a normal call case.

Fixes #35718

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-07-26 10:44:42 -04:00
Ioannis Papamanoglou 3415f71910 fs/nvs: prevent use after clear without init
Unset ready flag in nvs instance on clear.

Signed-off-by: Ioannis Papamanoglou <ioannis.papamanoglou@zonneplan.nl>
2021-07-20 13:34:45 +02:00
Marcin Niestroj 577315c4ff fs: littlefs: drop newline character in log messages
Newline character is automatically appended in log backends such as
UART, so there is no need to add it explicitly.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-07-19 12:03:15 +02:00
Marcin Niestroj c314557f2a fs: shell: fix incorrect message format when mount fails
There is '%u' and '%d' in format message, while there is only one
argument (besides format string). Remove ununsed '%u' to stop printing
garbage.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-07-19 12:02:58 +02:00
Dominik Ermel f06902cc69 fs/littlefs: Remove deprecated *_MEM_POOL_* Kconfig options
The following options, marked to be deprecated in release 2.5, have
been finally removed from Kconfig:
 FS_LITTLEFS_FC_MEM_POOL_MIN_SIZE
 FS_LITTLEFS_FC_MEM_POOL_MAX_SIZE
 FS_LITTLEFS_FC_MEM_POOL_NUM_BLOCKS

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-06-23 10:03:14 -05:00
Dominik Ermel 86b1dc340e fs/littlefs: Completely switch from mem pool to heap
The LittleFS file cache has been completely switched from k_mem_slab
to heap allocated.  The *_MEM_POOL_* kconfig variables no longer
affect the code.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-06-23 10:03:14 -05:00
Fredrik Gihl 7e385d7d04 fs: logstr_dup causes error in LOG_ERROR messages
Using %s, without logstr_dup causes error when
CONFIG_LOG_DETECT_MISSED_STRDUP is enable.
Removing %s argument. LOG_FUNC_NAME_PREFIX_ERR can be used if prefix
is wanted.

Signed-off-by: Fredrik Gihl <fredrik.gihl@flir.se>
2021-05-11 07:14:24 -05:00
Laczen JMS 5e9d6d638c nvs: fix possibility of losing data
Fix the possibility of losing data after startup as a result of a badly
erased sector.

Fixes #34722.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2021-05-10 05:31:36 -05:00
Shlomi Vaknin 8d48b919c6 fs: shell: add cat file command
Add cat command to fs shell module.
This command prints to the standard output
the given files.

Signed-off-by: Shlomi Vaknin <shlomi.39sd@gmail.com>
2021-05-07 20:52:36 -04:00
Laczen JMS a71a8dbfca nvs: hardening against bad sector close
A badly written sector close ate that has correct crc8 could allow
jumps outside the assigned flash area. This behavior is fixed.

A possibility existed that a badly erased sector or a incomplete write
of a large item created a empty closed sector. This has been fixed by:
a. Erase verification.
b. Clearing such a sector at startup.

Fixes #34382

Signed-off-by: Laczen JMS <laczenjms@gmail.com>

Co-Authered-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-05-06 11:10:05 +02:00
Andrzej Puzdrowski 29c838ed1d fs/nvs: document flash wbs migration capability
Document the fact than NVS image of different wbs
are compatible each other if psychical ATE size
is kept.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-04-30 12:27:27 +02:00
Damian Krolik 95121b544a nvs: fix initialization of fs->data_wra on alignment change
When existing records stored in the NVS are not properly
aligned according to the current flash driver requirements,
fs->data_wra may be initialized with an unaligned address.
Fix the initialization code, so that fs->data_wra is rounded
up to the nearest multiple of the current flash driver block
size.

The situation may occur during a firmware upgrade which
introduces a new flash driver or changes its parameters.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2021-04-30 12:27:27 +02:00
Andrzej Puzdrowski 1a6492d8b3 fs/nvs: removed unneeded if statements
Removed two unneeded `if` statements. These statements had not
effect in function results.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-03-29 13:43:55 -04:00
Andrzej Puzdrowski 9ea02a39ee fs/nvs: remove flash_write_protect_set() usage
flash_write_protection_set() was deprecated.
This patch removes usage of it and the test case which was
testing deprecated API behaviors.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-03-29 13:43:55 -04:00
Dominik Ermel d0017e9e5e fs: shell: Remove unneeded flags from fs_open calls
The cmd_write and cmd_ctunc have been opening/creating file for
read/write operation.
The commit changes cmd_write to open/create file for write only,
and cmd_trunc to only open file for write.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-04 06:10:58 -05:00
Dominik Ermel bbacab82f1 fs: shell: cmd_read does should open file for read-only
The cmd_read function uses fs_open with FS_O_CREATE | FS_O_RDWR flags
to open file it will only read; the flags has been changed
to FS_O_READ.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-01 12:57:55 -06:00
Peter Bigot 9519140270 fs: littlefs: fix mis-use of preprocessor
llvm 11 doesn't like having preprocessor directives in the expansion
of a macro used as a preprocessor conditional expression.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-08 11:36:24 -05:00
Andrzej Puzdrowski 6fb7ac233c fs: Fix fs_opendir resource leak when invoked on fs_dir_t object in use
Fixes problem when fs_opendir invoked on fs_dir_t object,
which is already holding information on opened directory,
overwrites references to other memory objects within
the fs_dir_t object causing resource leak.
If fs_opendir is invoked on already used fs_dir_t object,
it will return
-EBUSY.

Note: The change requires that all fs_dir_t objects should be
initialized to 0.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 07:32:20 -05:00
Andrzej Puzdrowski 7a4940d270 fs: Add fs_dir_t type variable initializations
The commit adds initializations of fs_dir_t variables in preparation
for fs_opendir function change that will require fs_dir_t object, passed
to the function, to be initialized before first usage.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-02-05 07:32:20 -05:00
Peter Bigot 487b0002cb tests: fs: littlefs: update filecache configuration
The mem_pool Kconfig API is deprecated as allocation now uses a k_heap.
Update to allocate a heap with the same amount of memory as was
defaulted with mem_pool customization.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-02 07:15:17 -05:00
Peter Bigot 8ea2956ca3 fs: littlefs: revise how per-file cache memory is allocated
Originally the file cache used a mem_pool, but that data structure has
been deprecated and replaced by a heap that includes metadata in the
heap area.  As a result attempts to allocate all blocks will fail
because some of the reservation intended for cache data is now holding
metadata instead.

It's not immediately clear how to adjust the required heap size to
support this metadata as it depends on heap chunk units and data
structures that are not visible to the application.  Experimentally a
value of 24 bytes works, while smaller values do not.

Further the previous Kconfig API to configure the allocation pool is
completely inappropriate with the new heap data structure which has
such different behavior.

So: Deprecate the old Kconfig API.  Add a new Kconfig option to
directly control the cache size.  Infer a default cache size that
works with the old mem_pool parameters assuming a per-block overhead.
But to avoid wasted memory use the heap allocation only when the
application customizes the size, and use a slab in other cases.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-02 07:15:17 -05:00
Dominik Ermel d4666f537c fs: Fix fs_open resource leak when invoked on fs_file_t object in use
Fixes problem when fs_open invoked on fs_file_t object, which is already
holding information on opened file, overwrites references to other
memory objects within the fs_file_t object causing resource leak.
If fs_open is invoked on already used fs_file_t object, it will return
-EBUSY.

Note: The change requires that all fs_file_t objects should be
initialized to 0.

Fixes: #29478

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-01-29 08:04:51 -05:00
Dominik Ermel fd610846ef native_posix: fuse: Add fs_file_t type variable initializations
The commit adds initializations of fs_file_t variables in preparation
for fs_open function change that will require fs_file_t object, passed
to the function, to be initialized before first usage.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-01-29 08:04:51 -05:00
Dominik Ermel 512a6f8cb6 fs: shell: Add fs_file_t type variable initializations
The commit adds initializations of fs_file_t variables in preparation
for fs_open function change that will require fs_file_t object, passed
to the function, to be initialized before first usage.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-01-29 08:04:51 -05:00
Mattias Säteri cf4295d106 native_posix: Add flags to fs_open invocation
Added flags that were missing from fs_open() call.

Signed-off-by: Mattias Säteri <mattias.sateri@flir.com>
2021-01-22 10:37:57 -05:00
Fredrik Gihl 49031cf6e2 fs: littlefs: Fix transient string in LOG_ messages
Fix transient string errors found when enable
CONFIG_LOG_DETECT_MISSED_STRDUP.

Signed-off-by: Fredrik Gihl <fredrik.gihl@flir.se>
2021-01-18 18:47:41 +01:00
Markus Fuchs ea6f7a4292 disk: disk_access_flash: Make sector size configurable in Kconfig
Make sector size used by flash disk configurable and expose new disk and
fatfs configurations to Kconfig.

Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
2021-01-15 11:21:01 -05:00
Peter Bigot 5b544e115b fs: littlefs: define mount point structures for file systems
Use the devicetree filesystem bindings to populate an fs_mount_t
object that is preconfigured for a particular set of file system
properties on a specified partition.

At this time the mount point data is accessed by reference using the
partition's devicetree node identifier.

Note: While a file system can register itself before its devices
are available, it cannot do the automount.  In this commit the
initialization priority is increased to compensate, but that's not
a long-term solution.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-27 18:16:20 +01:00
Andy Ross fcd392f6ce kernel: subsys: lib: drivers: Use k_heap instead of z_mem_pool wrappers
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.

Almost all of this is straightforward swapping of one alloc/free call
for another.  In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.

Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00