diff --git a/include/zephyr/device.h b/include/zephyr/device.h index aa91a7d8e9f5..8328ace40e99 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -18,6 +18,10 @@ #include #include +#ifdef CONFIG_LLEXT +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -99,6 +103,11 @@ typedef int16_t device_handle_t; */ #define Z_DEVICE_DT_DEV_ID(node_id) _CONCAT(dts_ord_, DT_DEP_ORD(node_id)) +#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)) +#endif + /** * @brief Create a device object and set it up for boot time initialization. * @@ -171,8 +180,9 @@ typedef int16_t device_handle_t; * * The device is declared with extern visibility, so a pointer to a global * device object can be obtained with `DEVICE_DT_GET(node_id)` from any source - * file that includes ``. Before using the pointer, the - * referenced object should be checked using device_is_ready(). + * file that includes `` (even from extensions, when + * @kconfig{CONFIG_LLEXT_EXPORT_DEVICES} is enabled). Before using the + * pointer, the referenced object should be checked using device_is_ready(). * * @param node_id The devicetree node identifier. * @param init_fn Pointer to the device's initialization function, which will be @@ -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__) \ + IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, (; Z_DEVICE_EXPORT(node_id))) \ /** * @brief Like DEVICE_DT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT` diff --git a/subsys/llext/Kconfig b/subsys/llext/Kconfig index 17135a6a3034..53eaf9f98314 100644 --- a/subsys/llext/Kconfig +++ b/subsys/llext/Kconfig @@ -67,6 +67,12 @@ config LLEXT_STORAGE_WRITABLE Select if LLEXT storage is writable, i.e. if extensions are stored in RAM and can be modified in place +config LLEXT_EXPORT_DEVICES + bool "Export all DT devices to llexts" + help + When enabled, all Zephyr devices defined in the device tree are + made available to llexts via the standard DT_ / DEVICE_* macros. + config LLEXT_EXPORT_BUILTINS_BY_SLID bool "Export built-in symbols to llexts via SLIDs" help