Commit graph

113 commits

Author SHA1 Message Date
Ederson de Souza 967168a536 subsys/llext: Generate syscalls stubs for EDK exclusively for userspace
A new Kconfig option which generates syscall stubs assuming that
extensions will always run on userspace, thus simplifying linking
them, as there's no need for z_impl_ stubs (used for direct syscalls),
CONFIG_LLEXT_EDK_USERSPACE_ONLY.

While defining __ZEPHYR_USER__ could have the same effect for optmised
builds, people building extensions on debug environments - thus
non-optimised - would suffer, as they'd need to somehow make the stubs
available (by either exporting the symbol or implementing dummy stubs).

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-05-17 16:21:48 +01:00
Peter Johanson b064a2cfcc scripts: Update uf2conv.py from upstream git.
Pull in the latest uf2conv.py and newly needed uf2families.json file
to address Python warning on Python 3.12 and keep us in sync.

Signed-off-by: Peter Johanson <peter@peterjohanson.com>
2024-05-08 09:31:07 -04:00
Pieter De Gendt 947906de7e scripts: build: gen_kobject_list.py check _driver_api suffix
Raise an exceptionif _driver_api suffix is missing from subsystem name.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-05-03 14:44:41 +01:00
Pieter De Gendt 65fb99a844 scripts: build: check_init_priorities.py: Add missing raise for error
An error was not raised.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-04-30 16:20:12 +02:00
Nick Goote 0b8714bcde scripts: Improve gen_kobject_list.py variable address determination
The gen_kobject_list.py script looks at DWARF debug information in the
elf file to determine the address of variables. Make sure that when
looking at DW_FORM_exprloc, it looks at both DW_OP_addr and
DW_OP_plus_uconst.

Signed-off-by: Nick Goote <ngoote@gmail.com>
2024-04-22 15:21:47 -04:00
Daniel Leung f05111dea0 kernel: rename Z_KERNEL_STACK_LEN to K_KERNEL_STACK_LEN
Since there is a K_THREAD_STACK_LEN, its kernel counterpart
should also be prefixed with K_ for consistency.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-03-27 19:27:10 -04:00
Ederson de Souza 62b19ef65c syscalls: llext: Export z_impl symbols so they are available to kernel
commit 67bb6db3f8 ("syscall: Export all emitted syscalls, enabling
them for extensions") exports all emitted syscalls, however, it does
that only for the `z_mrsh` symbols, effectively only available for
userspace. If an extension running at kernel level tries to use a
syscall, it will fail to load.

This patch fixes that by exposing the `z_impl` symbols instead. However,
this is not as straightforward as the `z_mrsh` ones. As, in their
signatures, they can basically contain any type, it's not just a matter
of emitting `EXPORT_SYMBOL(z_impl_<syscall>)`, as the compiler will
complain about the undefined types. Here, there are a few approaches.

One of them is to have the `EXPORT_SYMBOL` being generated on the same
files where the syscall is implemented - injecting it there would allow
it to access all known symbols. But changing a lot of files is
undesirable, and it was one of the nice points of first patch.

Another one would be to reconstruct - or simply use the absolute path -
for the includes where the syscalls are defined. Reconstruct the paths
seems fragile and I'm not sure using absolute paths is portable.

Finally, the approach used in this patch is to declare, on a different
generated file, all `z_impl_` symbols as `void *` - after all, only the
address (and the name) to the function is relevant to EXPORT_SYMBOL. By
living in an compilation unit that doesn't include any header which
would expose any of the syscalls, there shouldn't be any conflicts. And
to account for the possibility that a syscall is not compiled - due
being configured out via Kconfig - all those symbols are also weak
aliases to a pointer to NULL. This file is then included in
`llext_export.c` (which should naturally not include any conflicting
header).

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-03-26 19:31:56 -04:00
Ederson de Souza 67bb6db3f8 syscall: Export all emitted syscalls, enabling them for extensions
Linkable loadable extensions can only use syscalls if they are exported
via EXPORT_SYSCALL (or EXPORT_SYMBOL). Instead of enabling used syscalls
one by one, this patch exports all of them automatically via
`gen_syscalls.py`. If CONFIG_LLEXT=n, the section where the exported
symbols live is discarded, so it should be a non-op when llext is not
enabled.

This patch also removes the now redundant EXPORT_SYSCALL macro. Note
that EXPORT_SYMBOL is still useful on different situations (and is
indeed used by the code generated by `gen_syscalls.py`).

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-03-20 16:26:54 +00:00
Benjamin Cabé 9d1df132b1 script: gen_isr_tables: remove unnecessary warning log
Remove a message that had a typo in it but, more importantly that was
not needed.
The CONFIG_ISR_TABLES_LOCAL_DECLARATION already selects EXPERIMENTAL so
a user is properly alerted about the consequences just like any other
EXPERIMENTAL features if they enable WARN_EXPERIMENTAL.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-02-26 11:55:59 +00:00
Laurentiu Mihalcea 89a2a147a9 build: gen_isr_tables.py: fix bad IRQ index computation for L3 interrupts
According to the Zephyr documentation, the multi-level interrupts
are encoded as follows:

`L1_ID | ((L2_ID + 1) << L2_BITS) | ((L3_ID + 1) << (L3_BITS + L2_BITS))`

This means that when L3 interrupts are enabled, the gen_isr_table.py
script will receive the value of L2_ID + 1. Currently, the script
takes this value and directly compares it with the offsets set via
`CONFIG_3RD_LVL_INTR_xx_OFFSET`. This is wrong because the values from
said configurations are the same as L2_ID and because of that the
script will generate an error. To fix this, use the value of L2_ID
instead of L2_ID + 1.

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
2024-02-14 22:57:29 +01:00
Radoslaw Koppel 0ae48ecb58 scripts: build: gen_isr_tables: Implement local ISR generation
This commit moves all the functionality related to the current
interrupt parser into gen_isr_tables_parser_carrays.py file.
The new parser file gen_isr_tables_parser_local.py file is
implemented with the new parser that.
Additional information added to the generated interrupt header
that contains data required by the new parser.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2024-02-02 19:49:36 +01:00
Radoslaw Koppel 568cced14f scripts: gen_isr_tables: Break code into classes
This commit breaks the code into functional classes.
This way the functionality is visibly splitted into
functional parts and it is easier to replace the
specific parser part to implement new code generators.

There is also common functionality to handle multi level interrupts
moved to configuration class.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2024-02-02 19:49:36 +01:00
Radoslaw Koppel 4360acb27e scripts: gen_isr_tables: Code cleanup
This commit cleans up the gen_isr_tables code for better clarity
and easier modification.
Changes include:
- Separate functions to load intList section.
- Replace spurious handlers in internal data with None.
  Now it is the output generator work to choose right function.
- All the work to generate vt and swt separated into its own functions.
- Remove the need for internal shared array - all the information
  is here in swt array.
- The update_masks function - more functionality moved here.
- Simplify bit_mask function.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2024-02-02 19:49:36 +01:00
Yong Cong Sin 89fb8f8b98 gen_isr_tables: print index number at the end of each entry as comment
Make it easier to debug by printing the index number at the
end, this is especially helpful when there's a lot of
interrupts.

Before:

```c
/* build/zephyr/isr_tables.c */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)},
```

After:

```c
/* build/zephyr/isr_tables.c */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 0 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 1 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 2 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 3 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 4 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 5 */
{(const void *)0x0, (ISR)((uintptr_t)&z_irq_spurious)}, /* 6 */
```

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-01-23 06:40:32 -05:00
Greter Raffael 7bcd0699e6 gen_isr_tables: Add meaningful error message
When using direct isrs, a vector table is needed. However, if none is
present , i.e. `CONFIG_GEN_IRQ_VECTOR_TABLE=n`, this script failed. The
given error message was not helpful (`'NoneType' has no len()`).
This change makes it clearer, where to look for the problem.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2024-01-22 15:28:39 +01:00
Grzegorz Swiderski 460b6ef122 code_relocation: Add NOKEEP option
When using the code and data relocation feature, every relocated symbol
would be marked with `KEEP()` in the generated linker script. Therefore,
if any input files contained unused code, then it wouldn't be discarded
by the linker, even when invoked with `--gc-sections`.

This can cause unexpected bloat, or other link-time issues stemming from
some symbols being discarded and others not.

On the other hand, this behavior has been present since the feature's
introduction, so it should remain default for the users who rely on it.

This patch introduces support for `zephyr_code_relocate(... NOKEEP)`.
This will suppress the generation of `KEEP()` statements for all symbols
in a particular library or set of files.

Much like `NOCOPY`, the `NOKEEP` flag is passed to `gen_relocate_app.py`
in string form. The script is now equipped to handle multiple such flags
when passed from CMake as a semicolon-separated list, like so:

   "SRAM2:NOCOPY;NOKEEP:/path/to/file1.c;/path/to/file2.c"

Documentation and tests are updated here as well.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-01-15 13:20:17 +01:00
Yong Cong Sin 0884a33ee3 scripts: build: gen_isr_tables: add some debug prints
Add some debug prints for the interrupts bits and bitmasks
in each level.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-18 15:09:19 -05:00
Yong Cong Sin b4db285c1f scripts: build: gen_isr_tables: change naming of bitmask variables
Rename the bitmask variables from `*_LVL_INTERRUPTS` to
`INTERRUPT_LVL_BITMASK[]` array to be consistent with
`INTERRUPT_BITS`, making it easier to loop over the bitmasks.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-18 15:09:19 -05:00
Yong Cong Sin 56570cc8c1 scripts: build: gen_isr_tables: fix calculation of THIRD_LVL_INTERRUPTS
The calculation of `THIRD_LVL_INTERRUPTS` bitmask in the
`update_masks()` function is wrong, the number of bits to shift
should be the sum of the first two levels.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-12-18 15:09:19 -05:00
Marc Herbert 352980be98 scripts/build: make struct_tags.json deterministic
It's not good to see struct_tags.json change from one build to the next
when nothing changes.

Python's sets are not deterministic, see long story for older commit
f896fc2306 ("scripts: gen_handles: Sort the device handles")

Simply convert multiple_directories to a sorted list before using it.

Fixes commit 80e78208e6 ("kernel: syscalls: no need to include all
syscalls in binary")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-12-11 09:51:22 +01:00
Marc Herbert fb8d41b123 scripts/build/elf_parser.py: make dependency graph output deterministic
Python's sets are not deterministic.

`devices` were already sorted but `dev_supports` is still a
non-deterministic set. Sort dev_supports to make the graph output
deterministic.

Fixes commit 29942475c5 ("scripts: gen_handles: output dependency graph")

It is quite ironic that this initial and non-deterministic graph commit
was concurrent with and slightly delayed other commit
f896fc2306 ("scripts: gen_handles: Sort the device handles") which
fixed another, similar non-determinism issue in the same area. A true
"whack-a-mole"!

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-12-04 14:24:32 +01:00
Marc Herbert eea56d2080 scripts/build/elf_parser.py: add __lt__() method to base class
This allows sorting objects consistently without having to specific a
key.

No functional change yet.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-12-04 14:24:32 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif c25d0804f0 syscall: rename z_object_find -> k_object_find
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 27d74e95c9 syscall: rename z_object_wordlist_foreach -> k_object_wordlist_foreach
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif a6b490073e kernel: object: rename z_object -> k_object
Do not use z_ for internal structures and rename to k_object instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Fabio Baltieri dd178ce311 scripts: check_init_priorities: rework the error messages
The current error messages are a bit cryptic, rework them to make them
more meaningful:

- add an extra message on the first error to explain what the errors
  refer to.
- rework the error message to be more explicit.
- rework the priority string print to use a LEVEL+offset format to
  somehow highlight that the number is the offset from the level, not
  the actual priority.
- print the init function name in addition to the devicetree path.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-03 11:45:23 +01:00
Fabio Baltieri 2a70c31945 scripts: check_init_priorities: drop the same priority check
Since bb590b5b6e introduced ordinals in the priority sequence, the "same
priority" case cannot happen anymore, furthermore the priority value in
the script is now the position of the function in the init sequence, so
if two devices have the same priority there's something real bad going
on.

Drop all the "same priority" handling code and tests, convert the case
into ane exception instead. Drop the init stubs as well from the test,
they are not required anymore.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-03 11:45:23 +01:00
Fabio Baltieri 73d5ecc0c5 scripts: check_init_priorities: drop recursive child parsing
Now that child nodes are handled by edtlib there's no need to parse
child nodes in check_init_priorities anymore.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-10-25 18:39:31 -07:00
Anas Nashif 996c8457d7 ztest: remove old ztest api
Remove old Ztest API entirely. New API is the now the default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Radoslaw Koppel 48b93ee0aa scripts: build: gen_isr_tables: Cleanup access to ".intList"
This commit removes the needs or generating isrList.bin temporary file.
Now gen_isr_tables.py script access the required section directly in
elf file, that was accessed by the script anyway.
It simplifies the building removing one step.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
2023-10-20 14:58:55 +02:00
Fabio Baltieri 5212a4c619 scripts: check_init_priorities: use the Zephyr executable file
Rework check_init_priorities to use the main executable file instead of
the individual object files for discovering the devices.

This should make the script more robust in case of stale files in the
build directory, and also makes it work with LTO object files.

Additionally, keep track of the detected init calls, and add a handy
"-i" option to produce a human readable print of the initcalls in the
call sequence, which can be useful for debugging initialization problems
due to odd SYS_INIT and DEVICE interactions.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-09-20 20:24:46 +01:00
Pieter De Gendt ae8c72444e scripts: build: file2hex: Add optional offset and length parameters
Add optional offset and length parameters to generate partial hex files.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-09-15 13:23:30 +02:00
Laurentiu Mihalcea 017cf89a83 arch: Add support for static shared interrupts
This commit introduces all the necessary changes for
enabling the usage of shared interrupts.

This works by using a second interrupt table: _shared_sw_isr_table
which keeps track of all of the ISR/arg pairs sharing the same
interrupt line. Whenever a second ISR/arg pair is registered
on the same interrupt line using IRQ_CONNECT(), the entry in
_sw_isr_table will be overwriten by a
(shared_isr, _shared_sw_isr_table[irq]) pair. In turn, shared_isr()
will invoke all of the ISR/arg pairs registered on the same
interrupt line.

This feature only works statically, meaning you can only make use
of shared interrupts using IRQ_CONNECT(). Attempting to dynamically
register a ISR/arg pair will overwrite the hijacked _sw_isr_table
entry.

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
2023-09-14 08:35:12 +02:00
Jonathan Rico db52d27eb5 scripts: Update CFB font generator
Update CFB font generator so it works with Pillow version 10. They
deprecated some methods, with no direct replacements, so the generated
fonts might be slightly different.

Signed-off-by: Jonathan Rico <jonathan@rico.live>
2023-09-13 14:40:00 -07:00
Fabio Baltieri fb003d1aa8 scripts: check_init_priorities: add priority to the file debug print
Log the device priority on the file debug output print, this is
convenient to list out all the defined devices and their priority, even
if they don't depend on each other.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-09-07 09:49:55 +02:00
Gerard Marull-Paretas a4858c40ec scripts: build: elf_parser: _DEVICE_STRUCT_HANDLES_OFFSET is optional
It is only available if CONFIG_DEVICE_DEPS=y, so the ZephyrElf class
would fail to load if it does not treat _DEVICE_STRUCT_HANDLES_OFFSET as
optional.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-01 15:50:32 +02:00
Daniel Leung d90cbc79d9 scripts: gen_syscalls: rename shadow variables
The generated stubs use retval for function return value.
However, this is too generic and is going to collide with
other code. So rename those to be more specific. Note
that the double underscore is intentional to minimize
chance of being shadow variables.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 17:30:56 -04:00
Christopher Friedt 09e4f8fada syscalls: include stdarg.h for va_list type
Include the standard `<stdarg.h>` header to get the
correct definition for `va_list`, etc.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-22 09:59:44 +02:00
Joshua Lilly cce530cae4 scripts: build: gen_isr_tables: make bit masks configurable
Some architectures such as RISC-v support more than 255 interrupts
per aggrigator. This diff adds the ability to forgo the aggrigator
pattern and use a configurable number of bits for multilevel
interruts.

Signed-off-by: Joshua Lilly <jgl@meta.com>
2023-08-10 10:55:41 -04:00
Carles Cufi 623fb0ee81 build: relocation: Fix long command-line invocations
For applications relocating big parts of the code with many sections,
builds were failing on Windows due to hitting the max command-line
length on that platform.
Fix this by using a file to store the dictionary passed to the python
script.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/60994.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-08-01 09:47:57 -07:00
Jordan Yates 50d42dcdb2 scripts: build: check_init_priorities_test: fix
Fix the test script for the changes made to section naming.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-07-25 15:58:06 +00:00
Jordan Yates 23280f4a54 scripts: build: check_init_priorities: parse new naming
Update the script to parse the new section naming. The ordering type
is converted from an integer to a tuple, which still compares correctly
due to the elementwise behaviour of tuple comparison.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-07-25 15:58:06 +00:00
Fabio Baltieri 6d99e38a84 scripts: check_init_priorities: ignore zephyr,cdc-acm-uart
The new stack zephyr,cdc-acm-uart driver has two separate init path, one
of which kicks in before the USB stack to start buffering log messages.

This generates a false positive in the build time priority checking,
adding a check to ignore that compatible entirely.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-07-25 09:10:26 +02:00
Yong Cong Sin 335acf817d posix: signal: implement strsignal
Implementation and ztest for strsignal.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Gerard Marull-Paretas b6d5d246b7 scripts: build: gen_device_deps: s/--dynamic-handles/--dynamic-deps
Align naming of the CLI option with recent changes in handles naming.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00
Gerard Marull-Paretas d93586f831 device: s/__devicehdl_/__devicedeps_/
Rename the device dependencies array variable to use the "deps" name, in
line with latest renamings in device.h

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-21 09:32:05 +02:00