Commit graph

287 commits

Author SHA1 Message Date
Sihyun Noh 3788ce3b8b fs: change fatFS initialization to match littleFS.
Mounting the disk in a global function can lead to an issue
where fatFS cannot be mounted due to it not being registered beforehand.
To solve this problem, fatFS is now initialized in POST_KERNEL,
just like the littleFS initialization function.
fatfs_init must be called before attempting to mounte the disk.

Signed-off-by: Sihyun Noh <awake_noh@naver.com>
2023-04-24 13:34:12 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Manuel Arguelles 09dd8c74ae littlefs: translate error code when mount fails
When lfs mount fails and there is no formatting requested, the return
code must be translated to errno before being passed to the application
layer.

Additionally, only log a warning that the FS will be formatted, when the
system is not read-only.

Fixes #56378

Signed-off-by: Manuel Arguelles <manuel.arguelles@nxp.com>
2023-04-04 18:22:10 +02:00
Franciszek Zdobylak 3ff1e97367 fs: Fix Kconfig formatting
- use tabs instead of spaces in indentation
- use 2 spaces instead of tab in help message

Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
2023-03-22 13:52:07 +01:00
Dominik Ermel abb93d4089 fs: Prevent mounting file system re-using private data
The commit changes the fs_mount to not allow mounting same system,
with the same private data pointer, at two different mount paths.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-20 09:51:10 +01:00
Nicola Ochsenbein eba73727ee modules: fs: Add reentrant zephyr support
This commit enables zephyr to configure the FatFs FF_FS_REENTRANT
option and support fs actions from multiple threads.
CONFIG_FS_FATFS_REENTRANT enables the option and provides zephyr
mutex wrappers.

Signed-off-by: Nicola Ochsenbein <Nicola.Ochsenbein@husqvarnagroup.com>
2023-03-13 11:58:57 +01:00
Julien D'Ascenzio f76bfa5712 nvs: use NVS cache in write and gc functions
NVS cache was used only in read function. This commit add the usage of
NVS cache in write and gc functions.

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2023-03-13 09:21:22 +00:00
Jamie McCrae 7c6f6cd080 fs: fs_shell: Add read test
Adds an optional shell command for testing the speed of the flash
device and file system, which outputs a rough speed for reading a
file.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-20 09:48:24 +01:00
Jamie McCrae cef77afba5 fs: fs_shell: Add erase/write test
Adds an optional shell command for testing the speed of the flash
device and file system, which outputs a rough speed.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-02-20 09:48:24 +01:00
Dominik Ermel 1e0f36e896 fs/fatfs: Move FF_USE_LFN logic to Kconfig
Commit add hidden Kconfig option CONFIG_FS_FATFS_FF_USE_LFN
that is passed to ELM FAT to define FF_USE_LFN configuration.
The FF_USE_LFN still depends, indirectly, on choice
CONFIG_FS_FATFS_LFN_MODE config options
CONFIG_FS_FATFS_LFN_MODE_BSS, FS_FATFS_LFN_MODE_STACK and
FS_FATFS_LFN_MODE_HEAP, but the logic has been moved out of
zephyr_fatfs_config.h into Kconfig file.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-20 09:44:18 +01:00
Julien D'Ascenzio 740f915721 nvs: use CRC8 if cache size is 256
When cache size is 256, we can use CRC8

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2023-01-23 12:04:55 +00:00
Julien D'Ascenzio b7c2b3fc3a nvs: NVS cache always rebuild on successful NVS initialization
During the NVS initialization, if gc had to be done, the NVS cache
rebuild wasn't called.

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2023-01-19 17:14:55 +01:00
Eivind Jølsgard cfa1ba1261 fs: fcb: add option to disable CRC for fcb entries
Add option to disable CRC for fcb entries. This improves the write
throughput significantly at the cost of not detecting corrupted data
in flash. This is beneficial for aplications that needs the extra
write throughput, where error detection is done elsewhere.

Allow the FCB entries in flash to have a valid CRC when CRC is
disabled in the FCB. This allows existing solutions to disable
CRC checking, while keeping the CRC areas intact. Note that this
is a one-way option.

Fixes #53707

Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
2023-01-18 22:18:37 +00:00
Armin Brauns dfc97f3f38 fs: fat: document path transformation
The FAT driver converts zephyr paths like /SD:/foo into ELM-FATFS paths
like SD:/foo. Document this behaviour by extracting it into a separate
function (and adding a sanity check).

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2022-12-07 10:31:01 +00:00
Dominik Ermel 5f4664dabe fs/fat: Improve help of Kconfig options for FAT
The commit fixes usage of old identifiers, from ELM FAT module,
and adds additional information on how certain options affect
FAT operation in Zephyr.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-05 17:55:58 +01:00
Franciszek Zdobylak 2259e98d95 fs: Implement mkfs operation in FAT fs
Provide an implementation of fs_mkfs operation in FAT fs.

Signed-off-by: Franciszek Zdobylak <fzdobylak@internships.antmicro.com>
2022-12-05 15:36:00 +01:00
Franciszek Zdobylak 78f8937470 fs: Implement mkfs operation in littleFS
Provide an implementation of fs_mkfs operation in littleFS.

Signed-off-by: Franciszek Zdobylak <fzdobylak@internships.antmicro.com>
2022-12-05 15:36:00 +01:00
Franciszek Zdobylak 7a96ed2771 fs: Add fs_mkfs operation to fs api
Adds fs_mkfs function to fs api. It will allow to perform mkfs operation
in file systems added to Zephyr.

Signed-off-by: Franciszek Zdobylak <fzdobylak@internships.antmicro.com>
2022-12-05 15:36:00 +01:00
Dominik Ermel 043cea12e5 fs/fatfs: Add CONFIG_FS_FATFS_MIN_SS
The Kconfig option allows to set minimum expected sector size
to be supported by FAT fs driver.
When this value differs from CONFIG_FS_FATFS_MAX_SS the driver
will query device for actual sector size, expecting different
sector sizes for different device. When CONFIG_FS_FATFS_MIN_SS
and CONFIG_FS_FATFS_MAX_SS are the same, then there is slight
reduction if FAT driver size, as the query logic is removed
and CONFIG_FS_FATFS_MAX_SS is used for all devices.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-05 15:18:05 +01:00
Anas Nashif cffe98d9de crc: Make the build of crc function dependent on a Kconfig
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.

Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.

Partial fix for #50654

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-23 13:30:00 +01:00
Gerard Marull-Paretas 6a0f554ffa include: add missing kernel.h include
Some files make use of Kernel APIs without including kernel.h, fix this
problem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Dominik Ermel c058a457b2 fs: Switch from FLASH_AREA_ to FIXED_PARTITION_ macros
The commit switches LittleFS code from using FLASH_AREA_
macros to FIXED_PARTITION_ macros.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Théophile Ranquet f044a356dd shell: typos
This addresses a few typos in the filesystem shell.

Signed-off-by: Théophile Ranquet <theophile.ranquet@gmail.com>
2022-08-18 12:25:39 +02:00
Nahal Farhi 557fdaf2e3 fs: fat_fs: Changing mkfs options to create FAT32 on larger storage
Changing mkfs options from FM_FAT to FM_ANY so that on larger storage
FAT32 instead of FAT16 is automatically created.

Signed-off-by: Nahal Farhi <nahal@whisper.ai>
2022-08-10 18:37:33 +02:00
Reto Schneider 75ea632ba1 fs: fcb: Define length padding bytes
Before this, on flashes with a write alignment greater than one, the
padding bytes had no defined value.

The effect of this non-deterministic code made it hard(er) to verify
data written by FCB.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2022-07-20 11:09:29 +02:00
Anas Nashif 718750f962 fs/testsuite: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Dominik Ermel 6238bf4185 fs: Use fs_mount_t.node to check if system is mounted
The commit changes fs_mount and fs_unmount to use node fs_mount_t
member to decide whether file system described by given fs_mount_t
object has already been mounted.
Previously there was no such check in case of fs_mount, which
would allow to remount the same object as long as mount path
has been changed.
The fs_unmount has been checking whether API pointer (fs) has been
filled now it checks whether fs_mount_t is linked anywhere,
which is sign that the object is used.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-07-04 15:47:56 +02:00
Jordan Yates 75680f7ae0 treewide: update flash_area name retrieval
Update usage of `flash_area->fa_dev_name` to `flash_area->fa_dev->name`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-02 16:04:16 +02:00
Jordan Yates 4543f82c12 storage: flash_map: remove device_get_binding
Remove all usage of `device_get_binding` in the subsys by directly
storing the `const struct device*` in the `struct flash_area`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-02 16:04:16 +02:00
Krzysztof Chruscinski 041f0e5379 all: logging: Remove log_strdup function
Logging v1 has been removed and log_strdup wrapper function is no
longer needed. Removing the function and its use in the tree.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 13:42:23 +02:00
Yong Cong Sin 57b1f6622d fs/nvs: Fix comment typo
Minor fix to a comment typo.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-06-05 14:49:20 +02:00
Yong Cong Sin 267b4ae6b8 fs/nvs: removed extra empty lines
Minor edit to the code style.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-06-05 14:49:20 +02:00
Yong Cong Sin 85f54380f6 fs/nvs: Remove unused variable
ate_size doesn't seem to be used in the function, removed.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2022-06-05 14:49:20 +02:00
Damian Krolik 74e4ac0883 nvs: implement NVS cache
The NVS data lookup time grows linearly with the number of
allocation table entries to walk through, meaning that if
some data pair in the NVS changes frequently, access to
other data pairs that change rarely can take a lot of time.

It is particularly visible when the NVS is used as the
settings backend since the backend needs to perform multiple
NVS reads to find a requested key.

Implement a simple cache that stores an address of the most
recent ATE for all NVS IDs that fall into the given cache
position. CRC8/16 is used as a hash function used to
distribute NVS IDs across the cache entries.

The cache entries are only invalidated when an NVS sector
is erased as part of the garbage collector task.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2022-06-05 14:43:59 +02:00
Achatzi Julian 90236b0650 fs: fcb: Make FCB work with sectors larger than 16K
Enhance FCB to also work with sectors larger than 16K and
to handle larger flash alignment constraints correctly.

use fcb_len_in_flash when setting the offset of the data
and use buffers sizes of at least the alignment value.

The test in fcb_test_append_to_big has been altered, as it
would otherwise not come to a data length which fits the
fcb on sectors larger than 16K.

Closes: https://github.com/zephyrproject-rtos/zephyr/issues/45345

Signed-off-by: Achatzi Julian <jachatzi@baumer.com>
2022-05-25 14:57:45 +02:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Dominik Ermel 069fed9ca9 fs: Kconifg: use rsource instead of source for local Kconfigs
Change from absolute path to relative path for sourcing sub-Kconfigs.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-04-11 12:12:20 +02:00
Christian Taedcke 05a5db4821 fs: littlefs: Use flash map macro in automount
To identify the flash partition id, the macro DT_FIXED_PARTITION_ID()
was used previously.

Now the macro FLASH_AREA_ID() is used. This also supports the usecase
when a different flash map implementation is used that redefines the
macros in include/storage/flash_map.h, e.g. the nordic partition
manager.

Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
2022-03-26 12:15:09 +01:00
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