Non-configurable init priority POST_KERNEL/99 might
be too late for certain uses cases (e.g. fetching data from
the file system in driver initialization). Chabge it to
be configurable so that applications can mount the
file systems earlies if they want.
Signed-off-by: Miika Karanki <miika.karanki@vaisala.com>
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
dev_id is used as a pointer at the end of the call chain, so passing it
as an int makes no sense and can cause crashes if the pointer and int
types have different sizes. For example, if we have 64-bit pointers on
a board, the higher part of dev_id will be removed due to an type cast.
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
LittleFS may be used not only for Flash devices, we can use it for
block devices too.
Add possibility of building LittleFS for case when
CONFIG_FLASH_MAP and CONFIG_FLASH_PAGE_LAYOUT are disabled.
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Mark all k_mem_pool APIs deprecated for future code. Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.
Fixes#24358
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Adds various tests for mounting LittleFS with FS_MOUNT_FLAG_NO_FORMAT
and FS_MOUNT_FLAG_READ_ONLY, and operations on read-only mounted
file system.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The flags field has been added to fs_mount_t structure, accompanied
with two new flags:
FS_MOUNT_FLAG_READ_ONLY -- mount fs as read only
FS_MOUNT_FLAG_NO_FORMAT -- do not format volume when system not found
Code supporting the flags has been added to FS layer and drivers for
LittleFS and FAT FS.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The struct fs_file_system_t is only useful when defining file system
drivers and is not required for typical application development,
that is why it has been moved to separate file fs_sys.h.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The fs_open has been extended with support for open flags.
Currently supported flags are:
FS_O_READ -- open for read
FS_O_WRITE -- open for write
FS_O_CREATE -- create file if it does not exist
FS_O_APPEND -- move to the end of file before each write
The FAT FS and LittleFS front-ends within the Zephyr has also been
modified to utilize the flags.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Initialize LittleFS at POST_KERNEL and not at APPLICATION stage.
When using LittleFS as settings backend for OpenThread, LittleFS needs
to be available when net_init is performed.
Arguably, FS is an OS kernel component that should be ready when
applications are starting.
Possibly, the same change should be applied to FAT fs as well.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
The build infrastructure should not be adding the drivers subdirectory
to the include path. Fix the legacy uses that depended on that
addition.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Closes#18392 by asserting and returning an error if the block size is
not positive.
Closes#18458. The diagnosis here was not relevant as an in-range EOS
is written before the buffer is used, but using the non-terminated
length is slightly more clear about intent and may avoid a read overrun
of the mount point.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
There's desire to be able to customize parameters on a per-filesystem
basis, which means we need a way to override the Kconfig defaults which
are global. This also means the littlefs data structure cannot own the
cache and lookahead buffers.
Switch to using a macro to define the littlefs data structure. The
default version uses the Kconfig constants. A custom one takes
arguments providing the most likely partition-specific parameters.
Finally the user is free to bypass the helper macros and set any
parameters desired, though validation is limited and only present when
CONFIG_DEBUG is enabled.
Extend the test suite with a performance module, which confirms that
these settings have an impact proportional to the log of changes to the
cache or IO sizes.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
littlefs is a fail-safe filesystem from ARM Mbed that has wear-leveling
capabilities.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Signed-off-by: Jim Paris <jim@bolt.io>