Commit graph

1973 commits

Author SHA1 Message Date
Iuliana Prodan
bd5e38c6de openamp: add core address translation support
There are SoCs that have different memory maps for device and driver.
Therefore the shared memory between them has different values and we
need to convert the addresses.

This commit introduces address translation support for OpenAMP:
- implements the address translation functions;
- returns the I/O operations used for address translation.
The ops can be used in Libmetal (see metal_io_init()).

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Iuliana Prodan
71f3f7006a openamp: add Kconfig entries for address translation
Add configuration options to enable address translation in OpenAMP
and specify vendor header files for translation tables.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Jukka Rissanen
410afbaf19 lib: zvfs: Add default eventfd count for hostap
hostap needs more eventfd to function so set a proper default value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-27 10:56:49 +02:00
Chris Friedt
c3368f6491 posix: env: use sizeof void ptr instead of char ptr ptr
Coverity regularly raised a CID with every release that it found
`sizeof(char **)` confusing and somehow nonportable.

With every release, it needed to be marked as a false positive.

Change `sizeof(char **)` to `sizeof(void *)` to silence the
CID warnings.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-26 10:50:56 -10:00
Sayooj K Karun
964a832702 lib: min_heap: Refactor heapify_up/down functions
Remove using `swap()` which was using VLA and replace it
with `byteswp()`.
Reduce the scope of local variables in `heapify_up/down` to
the smallest necessary block.
Replace `while(true)` loop in `heapify_down()` with a bounded `for`
loop.

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-26 11:58:05 -04:00
Minh Tang
8ce9e11242 lib: posix: Update attribute packed for posix_thread_attr
Add attributed packed for struct posix_thread_attr when arch is RX

Signed-off-by: Minh Tang <minh.tang.ue@bp.renesas.com>
2025-06-26 14:07:03 +02:00
Iuliana Prodan
b3e4809554 lib: open-amp: Add NXP-specific resource table implementation
Implement NXP-specific support for the remote processor
resource table, including custom definitions and initialization
logic to meet NXP's communication requirements.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
7c82d6c2ab lib: open-amp: Update CMakeLists.txt for vendor resource table
Modify the build system to conditionally compile
vendor-specific resource table support based on configuration.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
9db96e8a04 lib: open-amp: Add vendor-specific config options
Add config options for vendor-specific resource tables.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
222297ee07 lib: open-amp: Add base support for resource table
Introduce macros to define initialization
routines for OpenAMP resource table entries.

This will allow to extend the default OpenAMP
resource table with vendor-specific data structures.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
e8a702026a lib: open-amp: Allow vendor specific resource table definition
Enhance flexibility by allowing vendors to define their own
resource tables. This is achieved by moving the vdev and vring
functions into the source file, requiring each vendor to
implement these functions within their specific resource
table definitions.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
a50ddace58 lib: open-amp: Replace struct fw_resource_table with void
Switching to void allows greater flexibility in supporting
vendor-specific resource tables.

This change reverts commit 39863b66bd, and adds some fixes.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Chris Friedt
8743da2f32 posix: use sys_clock implementation
Use the newly added sys_clock API in lib/os for

* clock_gettime()
* clock_settime()
* clock_nanosleep() and nanosleep()
* gettimeofday()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
49cc01d4b5 libc: common: thrd: use sys_clock_nanosleep() instead of nanosleep()
Reduce the dependency on POSIX by taking advantage of the newly added
sys_clock_nanosleep().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
ff7825b9aa libc: use the common libc time() implementation for most libcs
Use the implementation of time() from the common libc, since there
it no longer pulls in POSIX.

Use is implied for minimal, newlib, and picolibc, and selected
for IAR.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
17964083d3 libc: common: time: use sys_clock api rather than posix
Remove POSIX clock_gettime() from the common libc time implementation,
since POSIX should not be a dependency for ISO C.

Instead, use the newly added lib/os sys_clock API.

Specifically, sys_clock_gettime().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
a3e934f12c sys: clock: additional sys_clock api calls
Additional entries for the sys_clock API, comprised of:

* sys_clock_gettime()
* sys_clock_settime()
* sys_clock_nanosleep()

along with the constants

* SYS_CLOCK_REALTIME
* SYS_CLOCK_MONOTONIC
* SYS_TIMER_ABSTIME

The primary motivation for this API is so that libc and other
libraries have a familiar-enough API to reach to when POSIX
is not available, since POSIX is optional in Zephyr.

By adding this API to lib/os, we also eliminate dependency cycles
between libc and posix, as lib/os is a mutual dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
282b47cf37 posix: cond + mutex: log messages generate warnings for 32-bit timeouts
Previously, log messages would generate warnings (escalated to errors
in CI) when CONFIG_TIMEOUT_64BIT=n.

For example,

```
west build -p auto -b qemu_cortex_m0 -t run tests/posix/timers/ \
  -- -DCONFIG_TIMEOUT_64BIT=n
..
warning: format '%llx' expects argument of type \
  'long long unsigned int', but argument 3 has type 'k_ticks_t' \
  {aka 'unsigned int'}
```

Use portable print specifiers and cast the argument to int64_t.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Anas Nashif
d4a2b7dc57 lib: os: cbprintf_complete: add missing break statement
Add missing break in switch statement.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-18 17:48:03 -04:00
Tim Pambor
3b90ed6122 lib: os: Fix function signature of str_out
Update the str_out function signature to match the expected
cbprintf_cb_local type:
typedef int (*cbprintf_cb_local)(int c, void *ctx);

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-06-18 17:45:06 -04:00
Keith Packard
34a03fb436 posix: Use 'char' for posix_condattr bitfields
Ensure that posix_condattr is smaller than pthread_condattr by keeping it
under one byte.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-17 16:06:21 +02:00
Glenn Andrews
94084e5aba Lib: SMF: Add return code to signal event propagation
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.

Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.

smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.

Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2025-06-17 16:04:04 +02:00
Benjamin Cabé
455280e5aa lib: hex: remove unnecessary defensive programming
The hex2char() calls in bin2hex() can never fail since buf[i] >> 4
and buf[i] & 0xf always produce values in range 0-15.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 10:25:14 -07:00
Jordan Yates
b64fb93d93 lib: posix: dedicated symbol for POSIX system headers
Add a dedicated symbol for including the POSIX system headers path
directly into the include path, enabling (for example)
`#include <time.h>` instead of `#include <zephyr/posix/time.h>`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-06-11 08:19:54 +02:00
Nimish Tambe
936d0278bd posix: fnmatch: fix bugs in fnmatch(), see issue #55186
all tests in tests/posix/c_lib_ext/src/fnmatch.c seem to pass
except one (which is still commented)

Signed-off-by: Nimish Tambe <nimisht@gmail.com>
2025-06-09 17:05:40 -05:00
Sayooj K Karun
cd7c78e92e lib: min_heap: Add min-heap data structure
Introduce a binary min-heap implementation as a generic data structure
for use in kernel and application code. A min-heap always maintains
the smallest element at the root, making insertion and removal of the
minimum element efficient (O(log n)).

The API allows both static and dynamic initialization, supports custom
comparators.

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-07 13:29:24 +01:00
Peter Mitsis
811302e6d2 kernel: sys_heap: Fix chunk size request validation
Updates the heap code to ensure that when converting the requested
number of bytes to chunks, we do not return a value that exceeds
the number of chunks in the heap.

Fixes #90306

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-06-06 10:12:19 +02:00
Anas Nashif
7bbb834deb Revert "posix: rwlock: Refactor locking using k_timepoint_t"
This reverts commit 833eaccfd1.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-30 08:27:19 -04:00
Anas Nashif
0a6e579987 Revert "posix: net: move static inline gethostname() to lib definition"
This reverts commit e60070d91b.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-30 08:27:19 -04:00
Anas Nashif
a649b31cfc Revert "posix: device_io: mark pwrite() buf as const"
This reverts commit c14f97f194.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-30 08:27:19 -04:00
Anas Nashif
da48a04572 Revert "posix: sysconf: match _SC* defines with newlib/picolib"
This reverts commit c5f1c43b8c.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-30 08:27:19 -04:00
Nicholas Lowell
c5f1c43b8c posix: sysconf: match _SC* defines with newlib/picolib
It's possible for newlib/picolib libc libraries to
internally call sysconf() which would execute zephyr's
implementation.  However, if the _SC* defines do not have
matching values, then the incorrect switch case executes.

This issue arises when using newlib/picolib libc that includes
sysconf implementation for ARM.  With current defaults, the
zephyr sysconf() overrides the original libc sysconf() so
we must ensure proper operation.

We will switch to the #define list just like newlib/picolib.
We can't currently use their unistd.h directly due to a domino
of declaration conflicts.
For the "small" macro implementation, we have to drop using
CONCAT to prevent pre-expansion of the new #defines

Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
2025-05-30 10:26:22 +02:00
Nicholas Lowell
c14f97f194 posix: device_io: mark pwrite() buf as const
match standard by having input void *buf parameter
for pwrite() marked as const, and avoid any potential
declaration conflicts

Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
2025-05-30 10:26:22 +02:00
Nicholas Lowell
e60070d91b posix: net: move static inline gethostname() to lib definition
static inline gethostname() in unistd.h can cause declaration collisions.
we should just move it to a normal function definition like the
rest of the network functions.

Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
2025-05-30 10:26:22 +02:00
Cla Mattia Galliard
833eaccfd1 posix: rwlock: Refactor locking using k_timepoint_t
Make use of k_timepoint_t ind the calculation of the remaining time for the
rwlock.

Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
2025-05-30 10:26:02 +02:00
Valerio Setti
31e38c83b3 lib: uuid: do not support UUID_v5 on TF-M platforms
When TF-M is enabled, Mbed TLS's MD module (which is used to generate
v5 UUIDs) will dispacth hash operations to TF-M. Unfortunately TF-M
does not support SHA-1 (because it's a weak algorithm) so the
computation will fail.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-05-27 10:29:34 +02:00
Keith Packard
0adac7cafc libc/minimal: Add stub 'sys/lock.h'
This file is explicitly included by the espressif hal module. It's an
internal file provided by picolibc and newlib. Provide a stub to let
code designed for those to work with the minimal C library.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-23 17:41:40 -04:00
Chris Friedt
8a5c744213 posix: timers: use newly added timespec util functions
Use the newly added timespec util functions to manipulate and
compare timespec structures with overflow detection.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-22 23:57:17 +02:00
Benjamin Cabé
a3f658454a posix: clock: fix maybe-uninitialized warning in z_clock_gettime
Compiler gets confused and thinks base may be used uninitialized. This
shouldn't be possible, but to make the warning go away, initialize it.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-05-14 15:18:57 +02:00
Chris Friedt
ae4a1dbf2c posix: implement the POSIX_CLOCK_SELECTION Option Group
Implement the POSIX_CLOCK_SELECTION Option Group.

This was mostly already done, but compiled / linked in the wrong places.

E.g. pthread_condattr_getclock() and pthread_condattr_setclock() were
in pthread.c and part of POSIX_THREADS_BASE. clock_nanosleep() was in
clock.c and part of POSIX_TIMERS.

This change builds them as part of clock_selection.c with
CONFIG_POSIX_CLOCK_SELECTION.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
cfae041834 posix: implement the XSI_SINGLE_PROCESS Option Group
gettimeofday() was already implemented, but incorrectly lumped into
POSIX_TIMERS.

putenv() is really just a wrapper around setenv().

The only one left to implement was gethostid() which was relatively
trivial.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
0b869efe6a posix: clock: move most implementations to clock_common.c
Move most implementations to clock_common.c in preparation for
moving gettimeofday() and clock_nanosleep() to different compilation
units.

We also take this as an opportunity to switch from using k_spinlock
to sys_sem.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
73ee23e3ad posix: clock: create z_clock_gettime().. convenience functions.
To facilitate moving gettimeofday() and clock_nanosleep() to separate
compilation units, make z_clock_nanosleep(), z_clock_gettime(),
and z_clock_settime() convenience functions.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
5c46fcb1e9 posix: env: move most implementations to env-common.c
Move most implementations to env-common.c in preparation for adding
putenv.c .

We also take this as an opportunity to switch from using k_spinlock
to sys_sem.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
4137c489d8 posix: env: create z_getenv()..z_setenv() convenience functions
To facilitate adding putenv in a separate compilation unit,
make z_getenv(), z_getenv_r(), z_setenv(), and z_unsetenv()
convenience functions.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Alex Fabre
da2ecd3eb8 utils: bitarray: fix comparison of int of different signs
Clang 20.1.0 -Wsign-compare warning on int being compared with size_t
(unsigned int).

Signed-off-by: Alex Fabre <alex.fabre@rtone.fr>
2025-05-13 10:05:52 +02:00
Torsten Rasmussen
c79c4ef9a8 linker: move last section id constant to c-code
Move creation of last section id from ld linker script LONG() usage to
C code with last section attribute.

The use of `LONG()` works correctly with ld but lld emits a warning
because .last_section section is not allocated as there are no matching
input sections and discards the `LONG()` call, meaning the last section
identifier will not be present in the flash.
> ld.lld: warning: ignoring memory region assignment for
>                             non-allocatable section '.last_section'

Placing the last section id in `.last_section` in C code makes lld
allocate the memory for the id and thereby create the output section
with the correct output.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-05-08 15:55:40 +02:00
Daniel Nicoletti
9bbccf39cb include: zephyr: sys: Fix uuid.h usage in C++ code
In uuid.h the function uuid_generate_v5 had a 'namespace'
parameter which is a reserved C++ keywork.
Renamed to 'ns'.

Signed-off-by: Daniel Nicoletti <dantti12@gmail.com>
2025-05-06 02:36:15 +02:00
Chris Friedt
76e1fc7713 tests: posix: move tv_to_ts to posix_clock.h
Move the private static inline function tv_to_ts() to posix_clock.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-04 19:56:02 +02:00
Daniel Leung
d3dcf36897 libc: newlib: heap arean to support Xtensa MPU
This adds the bits to define HEAP_BASE when using Xtensa MPU.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-05-01 18:16:20 +02:00