-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
llext: export DT devices to extensions #78508
llext: export DT devices to extensions #78508
Conversation
The error message for Z_DEVICE_NAME_CHECK was needlessly calling DEVICE_NAME_GET() on the "name" string, resulting in a confusing message being displayed. Remove the DEVICE_NAME_GET call so that the error message shown by the compiler contains the actual name. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
031a747
to
0d1c9a1
Compare
The comment for Z_DEVICE_DT_DEV_ID() is misleading: device_get_binding() compares its inputs with values generated by the DEVICE_DT_NAME() macro, which expands to the node's DT label or to the node's full name. This patch updates the comment to reflect the actual behavior of Z_DEVICE_DT_DEV_ID(). Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
0d1c9a1
to
14fb69f
Compare
@gmarull can you take a look? |
include/zephyr/device.h
Outdated
@@ -197,7 +207,8 @@ typedef int16_t device_handle_t; | |||
DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \ | |||
level, prio, api, \ | |||
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \ | |||
__VA_ARGS__) | |||
__VA_ARGS__); \ | |||
Z_DEVICE_EXPORT(node_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, (EXPORT_SYMBOL(DEVICE_DT_NAME_GET(node_id))))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but the separate macro is easier to extend in the (short) future; I have a draft of a more complex proposal (#77799) where there are two different implementations for Z_DEVICE_EXPORT
.
For this reason I'm proposing to keep the separate macro, but included within an IF_ENABLED
in the parent.
include/zephyr/device.h
Outdated
#if defined(CONFIG_LLEXT_EXPORT_DEVICES) | ||
/* Export device identifiers using the builtin name */ | ||
#define Z_DEVICE_EXPORT(node_id) EXPORT_SYMBOL(DEVICE_DT_NAME_GET(node_id)) | ||
#else | ||
/* Do not export device identifiers */ | ||
#define Z_DEVICE_EXPORT(node_id) | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my other comment
include/zephyr/device.h
Outdated
@@ -197,7 +207,8 @@ typedef int16_t device_handle_t; | |||
DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \ | |||
level, prio, api, \ | |||
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \ | |||
__VA_ARGS__) | |||
__VA_ARGS__); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't trailing ;
be conditioned to the next statement? if not, move export above.
This patch adds an indirection level moving the current code from inside the EXPORT_SYMBOL and LL_EXTENSION_SYMBOL macros to private Z_* macros. This is done to allow for the official APIs to properly expand more complex arguments, such as the DT function-like macros. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This change adds a new configuration option, LLEXT_EXPORT_DEVICES, which enables exporting all devices defined in the device tree to llext extensions. When enabled, all devices are made available to extensions via the standard DT_ / DEVICE_* macros. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Add a new test to the simple llext test suite that verifies that DT devices are properly exported to extensions. This is done by obtaining a device handle from the DT and then trying to get the same handle at runtime using the device_get_binding() API. This test is optional because the current qemu_xtensa platform does not have any usable DT devices to test with. The LLEXT heap size is also increased to 64 kbytes to avoid heap exhaustion when running the new test on mps2_an385. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
14fb69f
to
689da27
Compare
v2:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack device changes
This PR adds support for automatic export of all Zephyr devices to extensions via a new Kconfig option,
CONFIG_LLEXT_EXPORT_DEVICES
. When this option is enabled, all Devicetree macros inzephyr/device.h
can be used in extensions as well to inspect and interact with the devices configured in the current build.Calling
EXPORT_SYMBOL
with anything more complicated than a simple identifier resulted in macro expansion issues. This has been fixed by adding a level of indirection, moving the actual symbol definition code to privateZ_
macros. A number of related comments have been updated.New test code has been added to properly verify the new support. The test retrieves the device object associated with the Zephyr console via
DT_CHOSEN
macros and verifies it matches with the one obtained at runtime by callingdevice_get_binding()
. This check is currently unsupported on Xtensa since theqemu_xtensa
platform defines no usable DT devices.Also fixes 2 minor issues in
device.h
:Z_DEVICE_NAME_CHECK
included a call toDEVICE_NAME_GET
, but the argument was already a string. This resulted in a confusing error message being displayed when the check failed.Z_DEVICE_DT_DEV_ID
was used indevice_get_binding()
instead of the DT path, and must thus be limited toZ_DEVICE_MAX_NAME_LEN
chars.This is not the case (anymore?):
device_get_binding()
matches neither paths nor identifiers, but either DT labels or DT full names as returned by theDEVICE_DT_NAME
macro here.