Instead of relaying on stddef.h being included by other headers
let's include it explicitly, following a report of it being
missing for Ubuntu 22.04 (glibc 2.35)
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
When nvs_write is called, the nvs_flash_block_cmp is used to check if
the new data to be written matches the data already on flash. This check
always fail when CONFIG_NVS_DATA_CRC is enabled, caused by the
NVS_DATA_CRC_SIZE being added to the len parameter. The pointer to the
new data does not already have the CRC part added, while the data on
flash does, and the size to be compared includes CRC section.
By removing the addition of NVS_DATA_CRC_SIZE to the compare size, only
the data without CRC is compared, which will make the compare work in
both cases.
Signed-off-by: Yonas Alizadeh <yonas.alizadeh@alfalaval.com>
Settings subsystem is storing the name ID and the linked list node ID
with only one bit difference at BIT(0).
Settings subsystem is also storing the name ID and the data ID in two
different ZMS entries at an exact offset of ZMS_DATA_ID_OFFSET.
Using the regular lookup function could result in many cache misses.
Therefore, to assure the least number of collisions in the lookup cache,
the BIT(0) of the hash indicates whether the given ZMS ID represents a
linked list entry or not, the BIT(1) indicates whether the ZMS ID is a
name or data and the remaining bits of the hash are set to a truncated
part of the original hash generated by Settings.
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
When the CONFIG_ZMS_NO_DOUBLE_WRITE is not enabled there is no need to
search in the cache for matching ID
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
When power cuts during a GC operation, the sector is erased again in the
next reboot cycle and the cycle_cnt of the empty ATE is incremented.
If the same power cut happens 255 times in a row, the empty ATE cycle_cnt
will become equal to the close ATE which causes a memory corruption.
Fix this by checking the close ATE cycle_cnt before incrementing the
empty ATE cycle_cnt.
Fixes: #84874
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
Previously, when detecting the GC_done ATE the gc_done_marker boolean
variable was not set.
Fix this by setting it to true if the GC_done ATE is found.
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
In order to use fstab with fatfs in addition to
littlefs a new driver fstab,fatfs was introduced
containing the required logic to detect and if
needed automount fatfs devices specified in fstab.
Additionally as the partition phandle is not needed
by fatfs and currently is specific to littlefs it
was moved from the common dts binding into the
littlefs binding.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Co-authored-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Co-authored-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Split the fuse FS driver into 2 parts: A top built in the embedded side,
with the embedded libC, and a bottom built in the runner side with the
host libC.
The error returns are converted to match the host libC.
Also, before the host FUSE thread, which is asynchronous to Zephyr was
calling directly into the Zephyr filesystem code, which resulted quite
often if catastrophic failures or corruption of the Zephyr state.
This is now fixed by having the FUSE thread queue requests to a Zephyr
thread, which will be handled in the embedded side in a coherent way.
This adds a slightly noticeable overhead, but the performance is still
acceptable.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Add missing Copyright from derived files and fix the Copyright year for
some files to keep the original Copyright notice
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
`FLASH_PAGE_LAYOUT` has a hardware dependency on `FLASH_HAS_PAGE_LAYOUT`
which is not present for all boards. Forcing this symbol to `y` when
the hardware doesn't support it results in build errors at the Kconfig
stage.
`FLASH_PAGE_LAYOUT` is enabled by default when `FLASH_HAS_PAGE_LAYOUT`
is true, so this change will not require any user changes.
Signed-off-by: Jordan Yates <jordan@embeint.com>
This resolves some addressed comments in this PR zephyrproject-rtos#77930
as well as this PR zephyrproject-rtos#80407
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
Introduce two new kconfig options in order
to be able to define custom named fatfs
mount points. If activated replace the static
FF_VOLUME_STRS approach with the runtime
generated VolumeStr array containing those
mount points.
Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Cast sector_count and sector_size to uint64_t to prevent potential
integer overflow when calculating total device size in
disk_access_device_size().
Fixes Coverity issue CID-322647
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Update the Kconfig configuration to allow enabling the underlying
filesystems (e.g. exFAT), with only `FILE_SYSTEM_LIB_LINK` enabled.
Signed-off-by: Jordan Yates <jordan@embeint.com>
The compiler is unaware of the `block_size > 0` precondition, so it
outputs warnings of uninitialized `reclen`. Explicitly initialize the
variable to suppress this.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Fix incorrect nbytes_to_read calculation in ext2_inode_read() function.
Previously nbytes_to_read was decremented by read value which caused
incorrect calculation of bytes to read in subsequent iterations.
Now nbytes_to_read is decremented by to_read value which represents
the actual number of bytes read in current iteration.
This fixes potential data corruption issues when reading files from
ext2 filesystem.
Signed-off-by: Chen Shu <751541594@qq.com>
Previously, filesystems could not be mounted at '/' because
mount points were restricted to being at least 2 characters.
Since '/' corresponds to the standard POSIX root filesystem
location, reduce the minimum length of a mount point to
1 character.
With that, we can mount a POSIX root filesystem.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The lookahead buffer is a bitmap containing info on free blocks and does
not have a minimum size or an alignment requirement.
This fixes the arbitrary 4 * block_size requirement for block devices
and fixes Kconfig documentation to remove a reference to nonexistent
8 byte alignment requirement.
Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
Instead of picking a set of safe block multiple sized values for caches,
round down to the nearest block multiple, increasing static buffer usage
determined by Kconfig variables.
Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
When all sectors have non-zero data, NVS would fail to init.
Add recovery path option to erase the all sectors and reinitialize.
This could occur due to non-empty sectors, or corrupted data.
Signed-off-by: Cory Andrew Mayer <corymayer@meta.com>
when performing a write ZMS checks if the data exists in the storage to
avoid double writing the same data and save some memory cycle life time.
However this downgrades the write performance.
Enable this feature only when CONFIG_ZMS_NO_DOUBLE_WRITE is enabled.
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
Add the ability to select littlefs disk version
to maintain backward compatibility
with existing littlefs
with the same major disk version.
Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
This fixes an issue where wrong values were checked against block device
defaults. Kconfig values are used when no filesystem config values are
provided, and the buffers are sized according to the Kconfig values,
but the checks were only performed against filesystem config variables.
Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
The mp pointer is in fs_file_t and fs_dir_t so if the fs pointer is made
NULL then subsequent file I/O operations will cause a NULL pointer
exception. Removing the mount point from the list is threadsafe and
should be sufficient.
Signed-off-by: Chris Desjardins <chris@arch-embedded.com>
Remove CONFIG_MMC_VOLUME_NAME, and set the disk name based on the
``disk-name`` property. This aligns with other disk drivers, and allows
for multiple instances of the mmc_subsys disk driver to be registered.
Add disk-name properties for all in tree definitions for the
mmc-subsys disk driver, and change all in tree usage of the disk name
Fixes#75004
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
Remove CONFIG_SDMMC_VOLUME_NAME, and set the disk name based on the
``disk-name`` property. This aligns with other disk drivers, and allows
for multiple instances of the sdmmc_subsys disk driver to be registered.
Add disk-name properties for all in tree definitions for the
sdmmc-subsys disk driver, and change all in tree usage of the disk name
Fixes#75004
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This resolves some addressed comments in this PR
https://github.com/zephyrproject-rtos/zephyr/pull/77930
It adds as well a section in the documentation about some
recommendations to increase ZMS performance.
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
The cache_size and lookahead_size are set at compile time using the
CONFIG_FS_LITTLEFS_CACHE_SIZE and CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE values
from Kconfig, or from the cache-size and lookahead-size properties in a
'zephyr,fstab,littlefs' compatible in the devicetree. Those values are
also used to statically allocate buffers that are pointed at by the
read_buffer, prog_buffer, and lookahead_buffer members of the lfs_config
structure.
At runtime, when using a block device, the cache_size and lookahead_size
are updated to be multiples of the underlying block device's block_size,
which may make them bigger than the original size used to allocate the
static buffers. Log an error and fail the operation when this occurs.
Signed-off-by: Phil Hindman <phindman@xes-inc.com>
ZMS is the abreviation of Zephyr Memory Storage.
It is a storage developed to target especially the non erasable devices.
The new memory storage system inherit from the NVS storage multiple
features and introduce new ones :
* Inherited features :
- light key-value based storage
- cache for entries
- Wear Leveling of flash memory
- Resilience to power failures
* New features :
- cycle counter for non erasable devices (instead of erase emulation)
- Keys up to 32-bit
- Built-in support of CRC32 for data
- Small size data (<= 8 bytes) integrated within entries
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
Clean up if the mount command fails, such as due to a typo in the mount
point name, so that it can be retried.
Signed-off-by: Phil Hindman <phindman@xes-inc.com>
Streamline the `rc` return logic in `nvs_flash_wrt_entry()`, `nvs_gc()`
by directly returning `rc`, as the redundant conditional check and
explicit return of 0 were unnecessary.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Property "block-cycles" is required for node "zephyr,fstab,littlefs",
but source code did not get the value from dts file, now add it.
Additionally correct the wrong description of property "block-cycles"
in binding file.
Signed-off-by: Paul He <pawpawhe@gmail.com>
Add an option that links in the underlying file system libraries as
usual, but doesn't compile in the Zephyr file system abstraction layer.
This can be useful to avoid linking in the entire filesystem
implementation through the `fs_file_system_t` API struct if only a
subset of the functions are used.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Reading superblock didn't work with DMAs that only support aligned reads
(e.g. STM32 DMA).
Co-authored-by: Maciej Sobkowski <msobkowski@antmicro.com>
Signed-off-by: Dominik Lau <dlau@internships.antmicro.com>
There is asignment from size_t variable to uint8_t variable in
nvs_al_size function that can trigger static analysis error.
The problem is fixed by changing the variable to size_t type
instead of uint8_t.
Signed-off-by: Andrej Trnkóci <andrej.trnkoci@nxp.com>