Commit graph

386 commits

Author SHA1 Message Date
Flavio Ceolin 02d5290e07 linker: kobject: Handle literal section
Add kobject_data prefix to kobject literals and group it close to
text area to avoid changing .text addresses in the final linkage.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-01-02 11:05:06 +01:00
Madhurima Paruchuri fa738b0f74 usb-c: Generate USB-C connector VIF policies XML file
Generates XML file containing VIF policies by reading the device tree
using EDT.pickle generated during build
This script writes a subset of general and sink-pdo VIF policies in
output file
This script gets invoked during build if enabled through kconfig
The generated XML containing USB-C VIF policies could be used by
USB PD/Type-C analysers/testers to understand USB-C properties and
perform tests accordingly

Signed-off-by: Madhurima Paruchuri <mparuchuri@google.com>
2022-12-02 08:46:04 -06:00
Keith Packard 62bc9bf3e5 cmake: Allow selection of libc API overflow detection mode
This adds a choice of three different libc API buffer overflow detection
modes:

 * None
 * Compile-time
 * Compile-time and Run-time

These correspond with the clang/gcc _FORTIFY_SOURCE modes (0/1/2).
_FORTIFY_SOURCE depends on compiler optimizations and require libc support
which the minimal C library doesn't include, so _FORTIFY_SOURCE is disabled
by default in those cases. Native tooling might also enable
_FORTIFY_SOURCE, so don't enable it by default in that case either.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-10-31 23:23:27 +09:00
Keith Packard b3073f0099 gcc/picolibc: Disable -fprintf-return-value when printf is not complete
GCC will compute expected sprintf (et al) return values internally and use
them in place of the actual return value. When the printf implementation
has reduced functionality, gcc may compute a different value.

For picolibc, this means disabling the optimization unless floating point
output is enabled.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-10-31 17:17:42 +09:00
Torsten Rasmussen 9a12f8b68b cmake: move testing of compile flag in environment to top CMakeLists.txt
This moves the test of compile flags set in environment from generic
toolchain to top-level ${ZEPHYR_BASE}/CMakeLists.txt.

In order to cleanup and make Zephyr CMake modules more generic then
the testing of specific compile flags and warn user is not really a
toolchain module responsible but a implementation detail of the project
itself as to how compile flags should be applied in a project.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Flavio Ceolin 8259931fce xcc-clang: Do not used unavailable options
xcc-clang in based on clan-10 and does not support -fno-pic and
-fno-pie.

clang-10: warning: argument unused during compilation: '-fno-pic'
[-Wunused-command-line-argument]
[147/148] Linking C executable zephyr/zephyr.elf
clang-10: warning: argument unused during compilation: '-no-pie'
[-Wunused-command-line-argument]

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-08-23 10:13:43 +02:00
Stephanos Ioannidis 5af932f6e7 cmake: Set GCC min-pagesize parameter to 0
GCC 11 and above may generate a warning when dereferencing a constant
address pointer whose address is below the value specified by the
`min-pagesize` parameter.

This commit sets the `min-pagesize` parameter to 0 such that GCC never
generates the warnings for any constant address pointers.

For more details, refer to the GCC PR99578.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-16 11:13:40 +02:00
Andy Ross 6cfb18686e app_smem: Correct missing dependency for linker script generation
The app_smem linker script files were being generated by a python
script based on the contents of the cmake-generated
compile_commands.json file.  But it forgot to include a dependency on
the input.  It also has the misfeature of being generated at cmake
interpretation time with a real but empty stub.

This worked for quite a while, because the dependency on "kernel"
(it's not clear to me why this was there but I'm not brave enough to
remove it) forced the file to rebuild any time any of the C code in
the system changed, which was almost always guaranteed.

But then commit 0224f2c508 ("device.h:
rework the device_extern.h mechanism") came along and removed a
generated include from device.h and saved a bunch of build time.  And
it also meant that no kernel code was being compiled anymore.  So now,
a second build picked up that empty stub file and failed with linker
warnings about the orphan sections that didn't find a place in the
link.

But second builds after cmake re-invocations are an obscure edge case,
right?  Well, no.  It turns out that this is exactly what "twister -f"
does in CI, in order to get retries for test cases that fail
spuriously (mostly for unavoidable host timer-related glitches on SMP
platforms).

So the end result was that this problem showed itself as a silent
failure of the retry mechanism in twister/CI, making it look for all
the world like the timer tests had all suddenly gone flaky.

Fun times.

Signed-off-by: Andy Ross <andyross@google.com>
2022-08-12 05:33:12 +01:00
Stephanos Ioannidis 9672858c19 cmake: compiler: Add flag template for disabling strict aliasing rule
This commit adds a template for specifying the C/C++ compiler flag for
disabling the strict aliasing rule.

It also enables this flag globally because the Zephyr codebase does not
strictly adhere to the aliasing rules specified by the C/C++ standards
and the optimisation strategies that assume these rules may end up
generating invalid code.

For instance, GCC 11 and above tend to optimise more aggressively
assuming the strict adherence to the standard aliasing rules and may
generate invalid code, when compiling Zephyr with `-fstrict-aliasing`,
that results in various run-time failures.

Note that the footprint and performance ramifications of disabling the
strict aliasing rule are negligible.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-11 17:45:58 +02:00
Gerard Marull-Paretas b2520b09a7 devicetree: drop support for dts_fixup.h files
Devicetree fixup files existed previous to the current stable Devicetree
API. While they served their purpose, they are no longer necessary nor
used in-tree. This patch drops support for this legacy feature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-11 12:17:02 +02:00
Gerard Marull-Paretas fe35e9f859 cmake: remove check for dts.fixup
dts.fixup was a thing before dts_fixup.h existed. Remove the check as we
have already moved away from dts_fixup.h.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-11 12:17:02 +02:00
Jordan Yates 29942475c5 scripts: gen_handles: output dependency graph
Output the final dependency graph as a `.dot` file, which when rendered
by graphviz can be easier to comprehend than the text descriptions.

This output is optional in that it will not be generated if `graphviz`
is not installed.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-30 08:29:29 -05:00
Anas Nashif c8080d8ecc cmake: also include files from include/<soc_name>
SoCs can have different headers, make the build system include those if
the directory exists for this SoC.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-25 16:50:24 -04:00
Torsten Rasmussen 39a7381bb9 cmake: remove deprecation_warnings.cmake
With support for deprecating Kconfig symbols within the Kconfig tree
itself, there is no reason to have a secondary location to maintain
for information that is based on a Kconfig setting in first place.

Better to directly do `select DEPRECATED` on the symbol itself, than to
maintain a secondary list with messages in CMake.

Hence removing this feature in CMake.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-07-15 09:53:08 -05:00
Anas Nashif 92575fdac8 scripts: move parse_syscalls.py to scripts/build/
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif a8a976647e scripts: move uf2conv.py to scripts/build/uf2conv.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 9ee1e32b57 scripts: move subfolder_list.py to scripts/build/subfolder_list.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif d859997994 scripts: move process_gperf.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 72e7fa8176 scripts: move mergehex.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 09b4becaee scripts: move gen_image_info.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif c74d20e433 scripts: move gen_syscalls.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif e234c21ab2 scripts: move gen_offset_header.py to scripts/build/
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif d5dcf20382 scripts: move gen_kobject_placeholders.py to scripts/build/
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif efbadbb677 scripts: move gen_kobject_list.py to scripts/build/gen_kobject_list.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif c36307ea86 scripts: move gen_isr_tables.py to scripts/build/gen_isr_tables.py
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 80f4b5db21 scripts: move gen_handles.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 6e1a335447 scripts: move gen_app_partitions.py to scripts/build
Move scripts needed by the build system and not designed to be run
individually or standalone into the build subfolder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-12 10:03:45 +02:00
Anas Nashif 47a673f2f4 build: generate symbols file
Optional way for generating symbols file using binutils. This file will
be generated on demand for tests which will then be parsed by twister to
create an accurate test plan from the listed testcase/suites.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-11 11:56:39 +02:00
Carlo Caione 5a4affdcda gen_isr_tables.py: Move to scripts directory
There is no reason to have this script in a different place than all the
other python scripts. Move it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-07-07 17:58:34 +00:00
Jaroslaw Stelter 69913adc80 cmake: filter not supported C++ compilation flags
Compilation warnings appears for C++ files, that following
options are not valid:
-ffrestanding,
-Wno-format-zero-length
-Wno-main
-fgnu89-inline
-std-gnu99
Added checks to filter out unsupported flags.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
2022-07-07 10:26:22 +00:00
Keith Packard d0c75f3b96 lib/libc: Add picolibc support (aarch32, aarch64 and RISC-V) [v21]
Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.

By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).

Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):

void main(void)
{
    printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}

                       FLASH    SRAM
    minimal             8696    3952
    picolibc int        7600    3960
    picolibc float     12304    3960
    newlib-nano int    11696    4128
    newlib-nano float  30516    4496
    newlib             34800    6112

---

v2:
	Include picolibc-tls.ld

v3:
	Document usage in guides/c_library.rst and
	getting_started/toolchain_other_x_compilers.rst

v4:
	Lost the lib/libc/picolibc directory somehow!

v5:
	Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
	Delete PICOLIBC_SEMIHOST option support code

v6:
	Don't allocate static RAM for TLS values; TLS
	values only need to be allocated for each thread.

v7:
	Use arm coprocessor for TLS pointer storage where supported for
	compatibility with the -mtp=cp15 compiler option (or when the
	target cpu type selects this option)

	Add a bunch of tests

	Round TLS segment up to stack alignment so that overall stack
	remains correctly aligned

	Add aarch64 support

	Rebase to upstream head

v8:
	Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
	variables in a single LIBC_PARTITIONS variable instead of
	having separate PICOLIBC_PART and NEWLIB_PART variables.

v9:
	Update docs to reference pending sdk-ng support for picolibc

v10:
	Support memory protection by creating a partition for
	picolibc shared data and any pre-defined picolibc heap.

v11:
	Fix formatting in arch/arm/core/aarch64/switch.S

v12:
	Remove TLS support from this patch now that TLS is upstream
	Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
	that support it.

v13:
	Merge errno changes as they're only needed for picolibc.
	Adapt cmake changes suggested by Torsten Tejlmand Rasmussen

v14:
	Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)

v15:
	Respond to comments from dcpleung:
	* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
          CONFIG_PICOLIBC
	* Add comment to test/lib/sprintf as to why the %n test
	  was disabled for picolibc.

v16:
	Switch picolibc to a module built with Zephyr. This eliminates
	toolchain dependencies and allows compiler settings for Zephyr
	to also be applied to picolibc.

v17:
	Provide Zephyr-specific 'abort' implementation.
	Support systems with MMU

v18:
	Allow use of toolchain picolibc version.

v19:
	Use zephyr/ for zephyr headers

v20:
	Add locking
	Use explicit commit for picolibc module

v21:
	Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
	mips and riscv architectures.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-22 13:15:55 +02:00
Nicolas Pitre 0a386dbe6c build: make Zephyr stdint convention enforcing configurable
There are  few cases where removing this enforcement is desirable:

- linking against binary C++ libs with incompatible type mangling

- linking against system provided headers i.e. native_posix

- compiling with legacy code that assumes a different convention

So let's create a Kconfig symbol for it. This is IMHO a good compromize
compared to using the %"PRId32" abomination everywhere otherwise.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-06-22 12:26:46 +02:00
Nicolas Pitre f00573555b Z_POW2_CEIL: simplify implementation
Avoid potentially calling __builtin_clz() twice with non-constant
values. Also add a test for it.

Clang produces false positive vla warnings so disable them. GCC will
spot real vla's already.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-06-16 10:28:15 +02:00
Martí Bolívar dcec8d028a cmake: add a mechanism for deprecating modules
We currently have mechanisms for deprecating both boards and SoCs.
However, we lack one for deprecating modules. This is inconvenient,
because we would like to do exactly that.

Handle this in a simple way by adding a new CMake file in the modules
directory which is responsible for warning the user about any
deprecated modules they may be using. See the source code comments for
more details about the approach.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-05-27 15:32:31 -07:00
Guennadi Liakhovetski 17eb313a1b sparse: add an address space and a __sparse_force annotation
We want to use a sparse address space to identify invalid conversions
between cached and uncached address aliases. This patch adds a
__sparse_cache sparse annotation for that. Where those conversions
must be done that has to be supported by using the __sparse_force
sparse attribute. To avoid compiler complains about unknown
attributes we add a -Wno-attributes flag when building with sparse
support.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2022-05-03 09:37:08 +02:00
Guennadi Liakhovetski 7a85ff7683 sparse: add sparse support
With this adding "-DSPARSE=y" to the "west build" command line
performs a sparse check of the project build. So far only gcc-based
builds are supported.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2022-04-28 08:54:21 -04:00
Flavio Ceolin 0b13b44a66 pm: device: Dynamically add a device to a power domain
Add API to add devices to a power domain in runtime. The number of
devices that can be added is defined in build time.

The script gen_handles.py will check the number defined in
`CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC` to resize the handles vector,
adding empty slots in the supported sector to be used later.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-04-18 17:25:01 -07:00
Krzysztof Chruscinski 33923014b9 logging: Kconfig cleanup of frontened related options
Cleanup in kconfig options in preparation for adding a
frontend that will use dictionary mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-04-13 13:45:36 -07:00
Yuval Peress 1ec0c6f530 build: make non zephyr/ include prefix configurable
Add a Kconfig to disable non prefixed includes. By setting
`CONFIG_LEGACY_INCLUDE_PATH=n` developers can disable having
`include/zephyr` in the search path. This means that includes such
as `#include <kernel.h>` will no longer work.

Internally, every header should be updated to add the `zephyr/`
prefix to the headers. Only then, will developers be able to use
this config value for their applications.

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Daniel Leung ba488d14d4 logging: syst: add support for catalog messages
MIPI Sys-T catalog messages are similar to dictionary logging
where an ID is emitted instead of the format string. This allows
the format strings to be removed from the final binary to save
a few bytes. This adds the necessary bits to determine to emit
catalog messages when appropriate.

Note that this implementation copies the argument list as-is
with string arguments stitched together since the format strings
are assumed to have been removed and they cannot be examined
to properly convert the argument lists into catalog message
payloads. Because of this, various build asserts are there to
avoid building for configurations where they are known not to
work.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-04-01 13:29:45 +02:00
Daniel Leung 1c9e89cd5e scripts: logging/dictionary: can specify output format
This changes the script to allow output format to be specified.
Currently, only JSON is support. This will allow supporting
other formats in the future.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-04-01 13:29:45 +02:00
Mark Ruvald Pedersen d8df801fe4 cmake: Fix dependencies so builds are sparse again
In cmake we use target_byproducts() to register dependence on the map
file alongside the executable for it - this makes sense.
Thus if the map file is missing, ninja will detect and issue a linker
command again. However after that, cmake was instructed to rename the
map file. Thus a 2nd round of ninja, which should be a no-op, is not as
the registered byproduct file is missing.

To keep this static, and to keep the map file alongside the elf file, we
will instead copy the map file.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2022-03-29 13:04:35 -07: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
Frank Terbeck a85a76d8c0 cmake: Support ZEPHYR_BASE to be a git submodule
In 9170977 build-time version header generation was added. The test
for .git assumes this file to be a directory. In the case of git
submodules, .git is a regular file that in its contents points to
the actual git database for the submodule. This is a way to have
symlink like behaviour even on file systems that do not support
themselves support symlinks.

This consults git as to what the correct git database directory is,
in case the .git file is indeed a regular file, and adjusts the
git_dependency variable accordingly.

Fixes #43503

Signed-off-by: Frank Terbeck <ft@bewatermyfriend.org>
2022-03-15 09:43:40 -07:00
Helge Juul affa68bbad libc: Add newlib math library to libc partition
Add symbols from libm.a or libm_nano.a to z_libc_partition. This fixes
an issue where newlib math functions called from user mode thread would
cause an MPU fault.

Fixes #43661

Signed-off-by: Helge Juul <helge@fastmail.com>
2022-03-11 11:35:13 -08:00
Chen Peng1 8c069c365d cmake: save eh_frame section in output with CONFIG_EXCEPTIONS.
.eh_frame section should not be removed directly in the
hex format and bin format output, it should be based on
whether we need exception handler feature.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
2022-03-10 13:13:03 -05:00
Nicolas Pitre 2cdac33d39 scripts: gen_syscalls: add missing --split-type case
With CONFIG_TIMEOUT_64BIT it is both k_timeout_t and k_ticks_t that
need to be split, otherwise many syscalls returning a number of ticks
are being truncated to 32 bits.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-03-08 11:26:58 +01:00
Anas Nashif a1d1810e54 cmake: emu: allow emulation to be OOT
Some emulation definition might be defined out of tree. Do not try to
include them here, instead they will be included in the module tree
defining them.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-02-21 22:10:42 -05:00
Torsten Rasmussen ea082ac2c9 cmake: only write devicetree files when there are changes.
As part of #40167 is was discovered that devicetree headers are always
generated when CMake re-runs.

This causes all source files that directly or indirectly through
included headers to recompile when CMake re-runs, even if there are no
changes to devicetree.

This commits introduces `zephyr_file_copy(...)` similar to
`file(COPY_FILE ...)` from CMake 3.21.
However, as CMake 3.20 is supported by Zephyr we need a zephyr variant
of this function to allow usage with CMake 3.20.

This ensures that only when there are changes to devicetree headers,
then source files will recompile.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-02-11 15:47:09 +01:00