Skip to content

Commit db451f2

Browse files
pillo79carlescufi
authored andcommitted
llext: export DT devices to extensions
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 <[email protected]>
1 parent 38722ec commit db451f2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

include/zephyr/device.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <zephyr/sys/util.h>
1919
#include <zephyr/toolchain.h>
2020

21+
#ifdef CONFIG_LLEXT
22+
#include <zephyr/llext/symbol.h>
23+
#endif
24+
2125
#ifdef __cplusplus
2226
extern "C" {
2327
#endif
@@ -99,6 +103,11 @@ typedef int16_t device_handle_t;
99103
*/
100104
#define Z_DEVICE_DT_DEV_ID(node_id) _CONCAT(dts_ord_, DT_DEP_ORD(node_id))
101105

106+
#if defined(CONFIG_LLEXT_EXPORT_DEVICES)
107+
/* Export device identifiers using the builtin name */
108+
#define Z_DEVICE_EXPORT(node_id) EXPORT_SYMBOL(DEVICE_DT_NAME_GET(node_id))
109+
#endif
110+
102111
/**
103112
* @brief Create a device object and set it up for boot time initialization.
104113
*
@@ -171,8 +180,9 @@ typedef int16_t device_handle_t;
171180
*
172181
* The device is declared with extern visibility, so a pointer to a global
173182
* device object can be obtained with `DEVICE_DT_GET(node_id)` from any source
174-
* file that includes `<zephyr/device.h>`. Before using the pointer, the
175-
* referenced object should be checked using device_is_ready().
183+
* file that includes `<zephyr/device.h>` (even from extensions, when
184+
* @kconfig{CONFIG_LLEXT_EXPORT_DEVICES} is enabled). Before using the
185+
* pointer, the referenced object should be checked using device_is_ready().
176186
*
177187
* @param node_id The devicetree node identifier.
178188
* @param init_fn Pointer to the device's initialization function, which will be
@@ -197,7 +207,8 @@ typedef int16_t device_handle_t;
197207
DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
198208
level, prio, api, \
199209
&Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
200-
__VA_ARGS__)
210+
__VA_ARGS__) \
211+
IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, (; Z_DEVICE_EXPORT(node_id))) \
201212

202213
/**
203214
* @brief Like DEVICE_DT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT`

subsys/llext/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ config LLEXT_STORAGE_WRITABLE
6767
Select if LLEXT storage is writable, i.e. if extensions are stored in
6868
RAM and can be modified in place
6969

70+
config LLEXT_EXPORT_DEVICES
71+
bool "Export all DT devices to llexts"
72+
help
73+
When enabled, all Zephyr devices defined in the device tree are
74+
made available to llexts via the standard DT_ / DEVICE_* macros.
75+
7076
config LLEXT_EXPORT_BUILTINS_BY_SLID
7177
bool "Export built-in symbols to llexts via SLIDs"
7278
help

0 commit comments

Comments
 (0)