Commit graph

108 commits

Author SHA1 Message Date
Jamie McCrae 12e8de71b1 scripts: build: parse_syscalls: Fix duplicate paths on windows
Fixes an issue on windows where there would be many permutations
of paths with different folder separators by converting to
posix-style path separators.

Issue was introduced by
https://github.com/zephyrproject-rtos/zephyr/pull/58351

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-06-19 14:57:39 +02:00
Daniel Leung 80e78208e6 kernel: syscalls: no need to include all syscalls in binary
The syscall generation phase parses all header files to look
for potential syscalls, and emits all the relevant files to
enable syscalls. However, this results in all the syscall
marshalling functions being included in the final binary.
This is due to these functions being referred to inside
the dispatch list, resulting in ineffective garbage
collection during linking. Previous commits allows each
drivers and subsystems to specify which header files
containing syscalls are relevant. So this commit changes
the syscall generation to only include the syscalls needed
for the build in the syscall dispatch list and removing
various bits related to that. This allows the linker to
garbage collect unused syscall related function, and thus
reducing final binary size.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Gerard Marull-Paretas e5335f345a device: dynamic device handles were declared as const
When CONFIG_HAS_DYNAMIC_DEVICE_HANDLES is selected, devices handles are
placed in RAM region so that they can be modified at runtime. However,
the gen_handles.py script added the `const` attribute to the device
handle arrays regardless of this setting, leading to faults when running
the application. This may be an indicator that this feature is not
actively used.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-14 13:48:02 -04:00
Jordan Yates 86dd23e1eb scripts: build: gen_handles: exit on relocatable files
Print a clean error message when provided a relocatable file, instead
of generating a source file which will cause compilation errors further
away from the source.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-02 18:53:06 -04:00
Jordan Yates 60aa9e1857 scripts: build: elf_parser: fix relocatable data offsets
Based on investigations with relocatable `.elf` files, the symbol table
data in relocatable files is not shifted by the section address. Remove
the shift from these files to ensure that data can be pulled from the
symbol table.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-02 18:53:06 -04:00
Jordan Yates 4d181d6395 scripts: build: elf_parser: retrieve section directly
Retrieve the section holding the symbol data directly from the symbol
information, instead of trying to find a section that contains data at
the correct address. The later approach does not work for relocatable
files, which contain multiple sections all containing data in
overlapping temporary memory addresses (usually starting at 0).

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-02 18:53:06 -04:00
Fabio Baltieri 44e691e20e scripts: check_init_priorities: add extra verbose output
Add support for more verbose output enabling debugging output and add a
first debug print to output the file to device path mapping. Found this
to be extremely useful to find what file is instantiating a specific
device for non obvious cases.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-06-02 04:47:24 -04:00
Yuval Peress ca5bf10143 sensor_shell: Update to new sensor_read API
Update the sensor shell logic to use the new sensor_read() APIs and
make triggers an option of the sensor_shell sample (this avoids the
trigger stealing the interrupt status from one-shot reads).

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-26 11:04:54 -05:00
Yuval Peress ed380de152 sensors: Add new async one-shot reading API
Add a new async API based on the RTIO subsystem. This new API allows:
1. Users to create sampling configs (telling the sensor which channels
   they want to sample together).
2. Sample data in an asynchronous manner which provides greater control
   over the data processing priority.
3. Fully backwards compatible API with no driver changes needed for
   functionality (they are needed to improve performance).
4. Helper functions for processing loop.

Signed-off-by: Yuval Peress <peress@google.com>
2023-05-26 11:04:54 -05:00
Fabio Baltieri 8412cb32ce scripts: build: add a test suite for check_init_priorities
Add a bunch of unit tests for the various check_init_priorities classes.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-05-25 15:40:07 +02:00
Fabio Baltieri ef1bd08823 scripts: build: add a script for build time init priority validation
Add a check_init_priorities.py scripts. This goes through all the object
files looking for known initialization sections and building a map of
device ordinals and their effective initialization priority. Then
compares that with the list of dependencies generated based on the
device tree and reports any warning (dependent devices, same priority)
or error (incorrect priority).

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-05-25 15:40:07 +02:00
Aurelien Jarno bdb3fd0ae9 scripts: gen_isr_tables: fix pylint issues
pylint reports the following issues on the
scripts/build/gen_isr_tables.py:

 C0325:Unnecessary parens after '=' keyword (superfluous-parens)
File:scripts/build/gen_isr_tables.py
Line:16
Column:0
 C0325:Unnecessary parens after '=' keyword (superfluous-parens)
File:scripts/build/gen_isr_tables.py
Line:316
Column:0

Fix that so that unrelated PR touching the same file have a chance to
pass the compliance checks.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2023-04-26 12:58:13 +02:00
Marc Herbert 16880cc381 scripts: gen_handles: silence "should it be static?" warnings
Some compilers and static analyzers warn when non-static (globals) are
not declared in some .h file. Tweak the generated code and add an
`extern` declaration before each device handle definition to make it
look it was declared in a (non-existent) .h file.

This makes the code a bit longer but it is already generated and very
repetitive anyway.

In the typical SOF configuration this silences about 150 sparse
warnings; as many as device handles.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-04-25 12:19:33 +02:00
Carlo Caione de90dfccbc syscall: Introduce __syscall_always_inline
Sometimes we want to force the inlining of a __syscall. Introduce a new
__syscall_always_inline symbol to do that.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-04-20 14:56:09 -04:00
Keith Short 23433d89e5 scripts: gen_handles: cleanup edt loading
An explicit import of edtlib is not required when using
pickle.load() and creates a duplicate module object.

Signed-off-by: Keith Short <keithshort@google.com>
2023-04-07 13:37:51 +02:00
Peter Marheine 5773862844 gen_relocate_app: avoid hard-coding section name fragments
This refactors the script to introduce a SectionKind enum that
represents each of the kinds of sections handled by this system (text,
data, rodata or bss), using that to improve the code structure by
reducing the use of strings in favor of indicating the use of values by
their types.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2023-04-07 13:12:13 +02:00
Peter Marheine 12c6dda9e2 gen_relocate_app: restrict relocations to listed files
When using code_data_relocation the script identifies sections that
should be relocated, but cannot guarantee that section names are unique
across all linked files. If a section name is not unique then matching
all sections with that name across all input files will relocate more
data than intended.

As a simple example, if both file1 and file2 contain .rodata.strings
sections, then if gen_relocate_app inspects only file1 it will generate
a linker script fragment `*(.rodata.strings)` that matches both object
files.

This commit changes gen_relocate_app to make the linker match on object
files as well (`*file1.o(.rodata.strings)`) to ensure unwanted sections
don't get relocated.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2023-04-07 13:12:13 +02:00
Yuval Peress 36c8b433c8 scripts: Print file causing error for syscalls
I was using a source file provided by TDK for a sensor driver
and the file was (originally) not encoded as UTF-8. When the read()
function was called, the build would fail but I had no idea why.

This change wrapps the 'read()' call and prints the error with
the file name as context.

Signed-off-by: Yuval Peress <peress@google.com>
2023-03-17 11:48:36 +01:00
Daniel Leung 751de22ca4 syscalls: skip generating mrsh.c if not userspace
There is no need to generate all the *_mrsh.c files for
marshalling syscall arguments when userspace is not enabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-11 19:45:23 +01:00
Carlo Caione 16248180c5 code_relocation: Fix Warning
The script is generatinga void instead of return. Fix it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-02-08 12:11:14 +01:00
Jamie McCrae ec7044437e treewide: Disable automatic argparse argument shortening
Disables allowing the python argparse library from automatically
shortening command line arguments, this prevents issues whereby
a new command is added and code that wrongly uses the shortened
command of an existing argument which is the same as the new
command being added will silently change script behaviour.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-01-26 20:12:36 +09:00
Daniel DeGrasse ca14626120 scripts: build: update gen_relocate_app.py to use new argument separators
Update gen_relocate_app.py to use "|" to separate code relocation
directives, and ";" to separate multiple files in a relocation directive.
This will enable multiple files to be passed to zephyr_code_relocate,
as well as multiple files to be passed from a CMake generator expression.
The script will then seperate these files and relocate each according to
the arguments given to zephyr_code_relocate.

Note! This commit will break support for zephyr_code_relocate until
the CMake function is updated

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2023-01-17 18:08:37 +01:00
Andrzej Głąbek 6c21c9635d scripts: gen_relocate_app: Fix a typo in parse_input_string()
This is a follow-up to commit b1a3ce4016.

`parse_input_string()` needs to use `:NOCOPY:`, not `:NOCOPY`, when
partitioning input lines, otherwise, when a line contains the NOCOPY
flag, the file name returned by the function starts with `:` and the
file cannot be then found by the script.
Such problem can be observed in the code_relocation_nocopy sample,
which without this fix does not actually relocate code from ext_code.c.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-11-23 16:49:03 -05:00
Daniel DeGrasse a766e4c4fb scripts: Fix header ifdef guard for gen_image_info.py
gen_image_info.py was generating invalid include guard. Properly strip
all special characters from filename to generate include guard #ifdef

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-11-15 14:46:02 +01:00
Tom Burdick e3d877f811 rtio: Userspace support
Add support for userspace with RTIO by making rtio and rtio_iodev
k_objects. As well as adding three syscalls for copying in submissions,
copying out completions, and starting tasks with submit.

For the small devices Zephyr typically runs on one of the most important
attributes tends to be low memory usage. To maintain the low footprint of
RTIO and its current executor implementations the rings are not shared with
userspace. Sharing the rings it turns out would require copying submissions
before working with them to avoid TOCTOU issues.

The API could still support shared rings in the future so that a
kernel thread could directly poll, copy, verify, and start the submitted
work. This would require a third executor implementation that maintains its
own copy of submissions similiar to how io_uring in Linux works.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-11-08 10:44:03 +01:00
Ederson de Souza b1a3ce4016 scripts/build: Add program header support for gen_relocate_app.py
Some linker scripts also associate memory regions with program headers
(PHDRS [1]). This patch adds support on gen_relocate_app.py to also
place a phdr alongside the memory region.

To keep things simple (and more natural), the format is basically the
same used in linker scripts - an space followed by ':<phdr_name>', like:

  SRAM2\ :phdr0:COPY:/home/xyz/zephyr/samples/hello_world/src/main.c

(Note the escape char before the space.)

[1] https://sourceware.org/binutils/docs/ld/PHDRS.html

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2022-11-03 10:25:07 +01:00
Gerard Marull-Paretas 882162357c scripts: build: gen_handles: use Z_DECL_ALIGN
Instead of hardcoding alignment size for pass 2 device handles, use
Z_DECL_ALIGN. This makes sure gen_handles.py is always in sync with the
type defined in device.h. The build assert in device.h can be removed as
a result, since we do not hardcode handles size anywhere else.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:11:47 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Peter Marheine d400b8135c arch/riscv: support CONFIG_CODE_DATA_RELOCATION
This implements support for relocating code to chosen memory regions via
the `zephyr_code_relocate` CMake function for RISC-V SoCs. ARM-specific
assumptions that were made by gen_relocate_app.py need to be corrected,
in particular not assuming any particular name for the default RAM
section (which is 'SRAM' for most ARM pltaforms) and not assuming 32-bit
pointers (so the test works on RV64).

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2022-08-24 10:08:06 +02:00
Peter Marheine 9bd46852a3 build: don't assume FLASH is the ROM region
Most ARM platforms name their ROM region `FLASH`, but this assumption is
not portable. Have gen_relocate_app refer to ROMABLE_REGION instead of
hard-coding the platform-specific memory region name.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2022-08-24 10:08:06 +02:00
Peter Marheine 3a8c20d849 build: don't assume .symtab section type
Only the elftools SymbolTableSection section type provides an
iter_symbols() method, and compilers are free to emit sections that
include the substring '.symtab' in their name which causes errors if
gen_relocate_app examines only the section name. Instead check whether a
section is a symbol table to skip attempting to inspect sections that
are not actually symbol tables.

Signed-off-by: Peter Marheine <pmarheine@chromium.org>
2022-08-24 10:08:06 +02:00
Christoph A Schnetzler 6fc4bb9486 kernel: Prevent Wundef
prevent `Wundef` warnings from occurring due to
missing CONFIG_ symbols and __cplusplus.

Signed-off-by: Christoph A Schnetzler <Christoph.Schnetzler@husqvarnagroup.com>
2022-08-15 14:36:47 +02:00
Keith Short f896fc2306 scripts: gen_handles: Sort the device handles
Replicate the devicetree dependencies into a sorted list. This ensures
that the structures added to the .__device_handles_pass2 section are
reproducible from build to build.

Tested with: west build -b native_posix tests/drivers/build_all/sensor

Without this change, two consecutive builds do not compare.

Signed-off-by: Keith Short <keithshort@google.com>
2022-08-05 13:00:35 +02:00
Gerard Marull-Paretas 7007451955 scripts: build: elf_parser: use node name for Graphviz diagrams
The elf_parser library now generates a dot file with device dependencies
that can be later rendered using Graphviz. Each node in the diagram
contains the device label (taken from DT node). In some cases the label
property can be None, leading to build failures like:

```
line 273, in device_dependency_graph
text = '{:s}\\nOrdinal: {:d} | Handle: {:d}\\n{:s}'.format(
TypeError: unsupported format string passed to NoneType.__format__
```

This patch switches to node name instead, which will always be set to
some value. This value is actually what devices get now as a name if
they do not have a label set.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-04 18:36:35 +02:00
Jordan Yates 13f2494f4c device: symetric injected dependencies
If a device manually specifies that it depends on a second DT device,
add the first device to the second devices list of supported devices.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-30 08:29:29 -05: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
Jordan Yates 8d17e857a1 scripts: gen_handles: use elf_parser.py
Use the new elf_parser module to simplify the process of generating the
final device handle arrays.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-30 08:29:29 -05:00
Jordan Yates 06b0d5a4fb scripts: elf_parser: added
Adds a python module intended to simplify other scripts that need to
work with device information compiled into the first pass `.elf` file.

Scripts utilizing this module can focus on iterating over dependency
graphs to generate the desired output, instead of also needing to
extract and build the graphs in the first place.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-30 08:29:29 -05:00
Jordan Yates cfb8c5e70f pm: device: rename placeholder variable
Rename the placeholder variable generated for PM slots so that the
prefix doesn't colide with the PM structs declared by devices. This
simplifies the process of searching for symbols in `.elf` files.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-30 08:29:29 -05:00
Anas Nashif 01582f80b7 scripts: move gen_cfb_font_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 61f672607a scripts: move file2hex.py to scripts/build/file2hex.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 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 98ab67d7dc scripts: move user_wordsize.py to scripts/build/user_wordsize.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 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 967f9b437b scripts: move dir_is_writeable.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 4f65bf6412 scripts: move gen_strerror_table.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 d589e7f04e scripts: move gen_relocate_app.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