Commit graph

1200 commits

Author SHA1 Message Date
Anas Nashif 0e0f878ddc picolibc: picolibc support still not complete with many toolchains
Clang support still work in progress in zephyr. So for now enable only
on gcc based toolchains.

We should enable this back for more toolchains once we have full clang
support and are able to verify.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-07 18:16:10 +01:00
Keith Packard 9a0aebc5fd lib/libc: Enable picolibc on qemu_x86_tiny
With all of the test suite issues on this board fixed, qemu_x86_tiny should
now be usable with picolibc.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-30 23:46:55 +00:00
Keith Packard 67ca25467b libc: Add remaining picolibc-supported targets
Picolibc now supports all of the Zephyr SDK target architectures for C.

qemu_x86_tiny needs fixes to get the libc partition linked
into the right spot. See issue #54148

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-27 06:27:43 -05:00
Björn Stenberg 0321ac8dbf json: Increase max number of descriptor elements from 30 to 62
The limiting factor is the output bitmask that says which elements have
been filled in by the parser. This patch changes the bitmask type from int
to int64_t.

Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2023-01-26 09:51:54 +00:00
Henrik Brix Andersen 277f6469f1 lib: os: reboot: include zephyr/cache.h
Include <zephyr/cache.h> in order to use the Zephyr cache APIs.

Fixes: b94ab6e9f1

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-01-24 14:35:49 +00:00
Chris Friedt ed11614a87 posix: mqueue: do not typedef mq_attr
The specification actually requires this to be a plain
`struct mq_attr`, without the typedef.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt 3aff1ff0c2 posix: fs: avoid adding open() alias with newlib and picolibc
Newlib and PicoLibc both already alias `open` to `_open`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt e431cfbbe5 posix: eventfd: select eventfd by default with CONFIG_POSIX_API
Although the eventfd API is not (yet) a part of POSIX,
it's pretty well ubiquitous on POSIX systems now.

Enable it by default when `CONFIG_POSIX_API=y`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt bf5d47a5ce posix: getopt: select getopt by default with CONFIG_POSIX_API
The `getopt()` function is part of POSIX and should be
available when applications choose to enable general POSIX
API support.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt e93f3c9b6d posix: rename posix_sched.h to sched.h
Rename the `posix_sched.h` to conform to the spec.

IEEE Std 1003.1

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt 43110ddb71 lib: posix: standard include paths with CONFIG_POSIX_API
With the `<zephyr/posix/...> prefix, it became
exponentially more difficult to integrate 3rd-party
libraries that depend on the POSIX API.

Standard POSIX headers should be available in standard
include paths - and that should most certainly the case
when `CONFIG_POSIX_API=y`.

With this change:

* When `CONFIG_POSIX_API=y`
  - applications have explicitly chosen to use
    POSIX APIs.
  - all standard POSIX includes are in the default
    include path.
* When `CONFIG_POSIX_API=n`
  - applications *may* include POSIX headers
    explicitly with the namespaced prefix
  - e.g. `#include <zephyr/posix/unistd.h>`
  - individual Kconfig options can be used to
    enable POSIX features selectively, such as
    `getopt` or `eventfd`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Joakim Andersson 22a8af5e63 drivers: timers: Refactor sys_clock_disable not available
Refactor sys_clock_disable not implemented behavior.
This follows the coding guidelines
Rule A.1: Conditional Compilation:
Do not conditionally compile function declarations in header files.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2023-01-20 20:02:20 +01:00
Keith Packard 13dfbaebd1 libc/picolibc: Clean up Picolibc Kconfig for C++
libstdc++ is supported with Picolibc only when the toolchain version of
Picolibc is use -- libstdc++ must be built using a specific Picolibc build
and libstdc++ is included with the toolchain.

Ideally, we'd allow the use of the Picolibc module whenever we weren't
using the GNU libstdc++, including when using the minimal libc++. However,
the obvious dependency settings create a loop:

config PICOLIBC
    depends on PICOLIBC_SUPPORTED

config PICOLIBC_SUPPORTED
    depends on !(GLIBCXX_LIBCPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")

config GLIBCXX_LIBCPP
    depends on NEWLIB_LIBC || PICOLIBC

To break this loop, we replace GLIBCXX_LIBCPP in the second block with
CPP:

config PICOLIBC_SUPPORTED
    depends on !(CPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr")

This means that picolibc cannot be used with any C++ apps when using the
Zephyr SDK, even when not using the GNU libstdc++. However, Zephyr SDK 0.16
will come with an additional Kconfig file that includes:

config PICOLIBC_SUPPORTED
    def_bool y
    depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr"

This will override the Kconfig bits included in Zephyr and allow use of the
Picolibc module with C++ code, including using the minimal libc++ bits.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-20 09:03:25 +01:00
Armin Brauns b94ab6e9f1 lib: os: disable caches before reboot
This ensures that all pending writes are committed. This is relevant for
flags in .noinit SRAM that are read back after reset.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-01-18 16:21:25 +01:00
Stephanos Ioannidis 669a0f5bec lib: cpp: Rework C++ standard library configurations
This commit reworks the C++ standard library configurations such that:

* the separation between the Zephyr minimal C++ library and the fully
  featured C++ standard libraries, such as GNU libstdc++, is clear.
  This is done by deprecating the Kconfig `CONFIG_LIB_CPLUSPLUS`
  symbol, which implies that the minimal C++ library is selected when
  set to `n`, and introducing the `CONFIG_MINIMAL_LIBCPP` symbol.

* the type of the selected C++ standard library is clear. This is done
  by introducing a Kconfig choice, `LIBCPP_IMPLEMENTATION`, for the C++
  standard library type and providing the choice symbols for each
  library type supported, such as `CONFIG_MINIMAL_LIBCPP` and
  `CONFIG_GLIBCXX_LIBCPP`.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 45ba8d5787 lib: cpp: Rename CONFIG_RTTI to CONFIG_CPP_RTTI
The Kconfig `CONFIG_RTTI` symbol enables the C++ Run-Time Type
Information (RTTI) support and is a feature of the standard C++
library; therefore, it should be prefixed with `CPP_` as with the rest
of the C++-specific symbols.

This commit renames the Kconfig `CONFIG_RTTI` symbol to
`CONFIG_CPP_RTTI` in order to better align with the other existing C++
Kconfig symbols, and deprecates the old `CONFIG_RTTI` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 26ede92f84 lib: cpp: Rename CONFIG_EXCEPTIONS to CONFIG_CPP_EXCEPTIONS
`CONFIG_EXCEPTIONS` is ambiguous in that the word "exception" may be
used to refer to many different types of exceptions, from the hardware
generated faults and interrupts (aka. exceptions) to the C++
exceptions.

This commit renames the Kconfig `CONFIG_EXCEPTIONS` symbol to
`CONFIG_CPP_EXCEPTIONS` in order to clarify that the symbol refers to
the C++ exceptions and eliminate any ambiguity, and deprecates the old
`CONFIG_EXCEPTIONS` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 4a64bfe351 treewide: Use CONFIG_CPP instead of CONFIG_CPLUSPLUS
This commit updates all in-tree code to use `CONFIG_CPP` instead of
`CONFIG_CPLUSPLUS`, which is now deprecated.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 05aea1ce58 lib: cpp: Rename CONFIG_CPLUSPLUS to CONFIG_CPP
There is no reason for the top-level C++ Kconfig symbol to be called
`CPLUSPLUS` when the convention used throughout the Zephyr codebase is
to use "cpp" to refer to C++ and the rest of the C++-related Kconfig
symbols are prefixed with `CPP_`.

This commit renames the Kconfig `CPLUSPLUS` symbol to `CPP` in order to
better align with the de-facto standard naming convention used throughout
the Zephyr codebase, and deprecates the old `CPLUSPLUS` symbol.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 96234b15df lib: cpp: Relocate C++ minimal library components to lib/cpp/minimal
This commit relocates the "C++ minimal library" components, that
implement a very limited subset of the standard C++ library, to a
dedicated directory, `lib/cpp/minimal`, in order to provide a clear
separation among the different C++ library components.

After this refactoring, the top `lib/cpp` directory should only contain
the sub-directories for each C++ library (i.e. `abi`, `minimal`). In
the future, a C++ library-specific shim layer implementation may be
added as sub-directories under `lib/cpp` as well (e.g. `libstdc++`
sub-directory containing the shim layer implementation for the GCC
libstdc++ library) -- this is similar to how the libc directories are
structured under `lib/libc`.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis 03879b9e2b lib: cpp: Relocate C++ ABI library components to lib/cpp/abi
This commit relocates the "C++ ABI library" components such as
global constructor/destructor and initialiser handlers to a dedicated
directory, `lib/cpp/abi`, in order to provide a clear separation
between the C++ ABI/runtime library and the standard C++ library
components.

Note that the Zephyr C++ ABI library currently implements the GNU/GCC
C++ ABI, which is the de-facto standard ABI used by many compilers
including Clang -- it may be necessary to sub-divide the `lib/cpp/abi`
into `lib/cpp/abi/gnu` and `lib/cpp/abi/someotherabi` in the future
when adding the support for a C++ compiler that expects an ABI vastly
different from the GNU C++ ABI.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Stephanos Ioannidis feaab27c1b lib: cpp: Relocate subsys/cpp to lib/cpp
This commit moves the files under `subsys/cpp` directory to the
`lib/cpp` directory because the C++ ABI runtime library and the
standard C++ library components are not a "subsystem" (aka. API) in
conventional sense and is better described as a "library."

Classifying the C++ ABI runtime library and the standard C++ library as
"libraries" instead of "subsystems" also better aligns with how the
existing C standard library implementation (`lib/libc`) is handled.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
HaiLong Yang 1c2c254f7c lib: os: Fix note on fdtable.c
After fcntl.h moved to posix, there have a compiler note
on fdtable.c. As suggested in fcntl.h, instead with
zephyr/posix/fcntl.h.

Signed-off-by: HaiLong Yang <hailong.yang@brainco.cn>
2023-01-11 10:54:42 +01:00
Chris Friedt addbec9591 libc: minimal: stdio.h: define SEEK_SET, SEEK_CUR, SEEK_END
The `SEEK_SET`, `SEEK_CUR`, and `SEEK_END` constants are defined
in `<stdio.h>`, not in `<sys/stat.h>`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 0697c7b3fe posix: headers: harmonize remaining types with newlib
The remaining types that needed to be harmonized between
Newlib and Zephyr's POSIX definitions are:

* `struct sched_param`
  - don't re-define if using minimal libc
* `pthread_attr_t`
  - convert to `struct pthread_attr`
  - define type if using minimal libc
  - assert acceptible object size
* `pthread_mutexattr_t`
  - convert to `struct pthread_mutexattr`
  - define type if using minimal libc
  - assert acceptible object size
* `pthred_condattr_t`
  - convert to `struct pthread_condattr`
  - define type if using minimal libc
  - assert acceptible object size
* `pthread_once_t`
  - adopt newlib definition
  - define type if using minimal libc
Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt ecb82784b7 posix: newlib compatible PTHREAD_CREATE_DETACHED and JOINABLE
Define `PTHREAD_CREATE_DETACHED` and
`PTHREAD_CREATE_JOINABLE` to be compatible with the Newlib
definitions.

This is a temporary workaround for #51211 until Newlib
headers are pulled in.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 8659e2f69e libc: minimal: include: move fcntl.h to posix
The `fcntl.h` header has never been a part of ISO C so move it to
`include/zephyr/posix`.

To ensure a smooth migration, a header was left in
`lib/libc/minimal/include` that prints a deprecation warning.

Users should either include `<zephyr/posix/fcntl.h>` or switch to
`CONFIG_POSIX_API=y`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 6f4e96bc24 libc: minimal: include: move sys/stat.h to posix
The `sys/stat.h` header has never been a part of ISO C so move it
to `zephyr/include/posix/sys/`.

To ensure a smooth migration, leave a stub header in
`lib/libc/minimal/include/sys/` that prints a deprecation warning
suggesting developers either include `<zephyr/posix/sys/stat.h>`
or use `CONFIG_POSIX_API=y`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 44b72bf801 posix: clock: fix seconds calculation
The previous method used to calculate seconds in `clock_gettime()`
seemed to have an inaccuracy that grew with time causing the
seconds to be off by an order of magnitude when ticks would roll
over.

This change fixes the method used to calculate seconds.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-04 21:12:58 +01:00
Krzysztof Chruscinski accaebb708 lib: os: mpsc_pbuf: Fix concurrency issues
Fixed issues which were leading to failures when producing
and consuming is preempted at various stages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-29 10:33:29 +01:00
Krzysztof Chruscinski 235ee63233 lib: os: mpsc_pbuf: Use flag for buffer full indication
Use flag instead of word in the buffer. Using this method allows
to dedicate full buffer capacity for data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-29 10:33:29 +01:00
Krzysztof Chruscinski e46efdcd94 lib: os: mpsc_pbuf: Improve debugging
Improved debugging messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-29 10:33:29 +01:00
Nicholas Lowell 51f83185b0 posix: Kconfig for timer_create wait time
should be able to configure the time spent waiting
for available resources when calling timer_create()
to not cause a hiccup in applications that require
faster response times than the original hard-coded 100 ms.

Signed-off-by: Nicholas Lowell <nlowell@lexmark.com>
2022-12-27 15:34:13 +01:00
Carlo Caione d540cf8877 openamp: Add new Kconfig option to enable dcache
Currently OpenAMP is unconditionally compiled with the options to use
the vrings cache operations disabled.

Add a new CONFIG_OPENAMP_WITH_DCACHE Kconfig option to enable the
support for d-cache operations in OpenAMP when needed.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-12 18:41:01 +01:00
Stephanos Ioannidis 997f5edf1a lib: libc: picolibc: Clean up Kconfig configurations
This commit updates the Picolibc configurations to remove any
unnecessary defaults and dependencies and conform to the de-facto
standard convention across the Zephyr repository.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-12-08 15:09:55 -05:00
Stephanos Ioannidis c9c40d9465 lib: libc: Move newlib libc configs to lib/libc/newlib/Kconfig
This commit relocates the newlib libc configurations under the top-
level libc Kconfig to a new Kconfig under `lib/libc/newlib` for
improved organisation of the libc configurations.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-12-08 15:09:55 -05:00
Stephanos Ioannidis 5efc0d51c8 lib: libc: Move minimal libc configs to lib/libc/minimal/Kconfig
This commit relocates the minimal libc configurations under the top-
level libc Kconfig to a new Kconfig under `lib/libc/minimal` for
improved organisation of the libc configurations.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-12-08 15:09:55 -05:00
Stephanos Ioannidis c3db8dc9e7 lib: libc: Clean up CMake script to use add_subdirectory_ifdef
This commit cleans up the top `CMakeLists.txt` for the libc directory
to use `add_subdirectory_ifdef` in order to make the code more
readable.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-12-08 15:09:55 -05:00
Radoslaw Koppel 5a55d53242 spsc_pbuf: Fix cache wb in spsc_pbuf_free
This commit properly writes back cached read pointer in spsc buffer
when freeing the memory.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2022-12-07 10:21:33 +00:00
Stephanos Ioannidis 82a902e5ea lib: newlib: Define _ANSI_SOURCE
This commit updates the Newlib integration to define `_ANSI_SOURCE`
in order to prevent Newlib from defining POSIX primitives in its
headers when GNU dialect is used (`-std=gnu*`).

Newlib `features.h` defines `_DEFAULT_SOURCE` when `__STRICT_ANSI__`
is not defined by GCC (i.e. when `-std=gnu*`), which results in the
Newlib headers defining POSIX primitives that are in conflict with the
POSIX primitives defined by Zephyr.

Newlib must not define POSIX primitives unless the feature test macros
such as `_POSIX_SOURCE`, `_GNU_SOURCE` and `_DEFAULT_SOURCE` are
explicitly defined.

Note that `-std=gnu` does not imply `_GNU_SOURCE` or `_DEFAULT_SOURCE`
because it is only supposed to instruct the compiler to use the GNU C
language dialect (i.e. GNU C language extensions).

Refer to the GitHub issue #52739 for more details.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-12-05 11:02:36 +01:00
Chris Friedt ff3aaa6ef3 posix: getopt: move declarations to unistd.h
Declarations for `getopt()` should be in `<unistd.h>`
according to the spec. The extended versions `getopt_long()`
and `getopt_long_only()` are declared in `<getopt.h>`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-04 14:51:52 +01:00
Chris Friedt 4d906d944b Revert "posix: getopt: move declarations to unistd.h"
This seems to have caused build failures in spite of CI being
green in PR 52653.

This reverts commit fc92eb1b37.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-02 14:09:37 +09:00
Chris Friedt fc92eb1b37 posix: getopt: move declarations to unistd.h
Declarations for `getopt()` should be in `<unistd.h>`
according to the spec. The extended versions `getopt_long()`
and `getopt_long_only()` are declared in `<getopt.h>`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-01 15:52:47 -05:00
Carlo Caione cc427b4bb0 cache: Fix libraries and drivers
Fix the usage to be compliant to the new cache API.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-12-01 13:40:56 -05:00
Chris Friedt 2e36d1f3eb lib: os: add CRC shell command for integrity verification
There are several Zephyr shell commands that are used for
transferring data over a possibly unreliable connection such as a
UART into either memory or flash. For example, `flash load` and
`devmem load`.

Make the CRC functions available so that they can be used to
verify the integrity of data transferred over possibly
unreliable connections.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-29 09:32:28 +01:00
Chris Friedt 7b95428fa0 lib: posix: update usleep() to follow the POSIX spec
The original implementation of `usleep()` was not compliant
to the POSIX spec in 3 ways.
- calling thread may not be suspended (because `k_busy_wait()`
  was previously used for short durations)
- if `usecs` > 1000000, previously we did not return -1 or set
  `errno` to `EINVAL`
- if interrupted, previously we did not return -1 or set
  `errno` to `EINTR`

This change addresses those issues to make `usleep()` more
POSIX-compliant.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 19:31:33 -05:00
Chris Friedt dcfcc6454b lib: posix: sleep() should report unslept time in seconds
In the case that `sleep()` is interrupted, the POSIX spec requires
it to return the number of "unslept" seconds (i.e. the number of
seconds requested minus the number of seconds actually slept).

Since `k_sleep()` already returns the amount of "unslept" time
in ms, we can simply use that.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 19:31:33 -05:00
Chris Friedt f1ececc682 posix: key: abstract pthread_key_t as uint32_t
Consistent with the change of `pthread_t`, `pthread_mutex_t`,
and `pthread_cond_t` to `uint32_t`, we can now also abstract
`pthread_key_t` as `uint32_t` and separate the implementation
detail, hidden from POSIX API consumers.

This change introduces `CONFIG_MAX_PTHREAD_KEY_COUNT`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 04:19:01 +09:00
Chris Friedt 96b9d7cb6d lib: posix: pthread_key: use spinlock instead of semaphore
None of the operations that `pthread_key_sem` protected were
blocking, so simply make it a spinlock.

Also made the lock static.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 04:19:01 +09:00
Chris Friedt 187df899da lib: posix: pthread: rename pthread_key_lock to pthread_once_lock
Since this lock is only used in `pthread_once()` it makes sense
to name it accordingly.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 04:19:01 +09:00