@@ -101,9 +101,35 @@ typedef int16_t device_handle_t;
101101 * The ordinal used in this name can be mapped to the path by
102102 * examining zephyr/include/generated/zephyr/devicetree_generated.h.
103103 */
104- #define Z_DEVICE_DT_DEV_ID (node_id ) _CONCAT(dts_ord_, DT_DEP_ORD(node_id))
104+ #define Z_DEVICE_DT_DEP_ORD (node_id ) _CONCAT(dts_ord_, DT_DEP_ORD(node_id))
105105
106- #if defined(CONFIG_LLEXT_EXPORT_DEVICES )
106+ /* Same as above, but uses the hash of the node path instead of the ordinal.
107+ *
108+ * The hash used in this name can be mapped to the path by
109+ * examining zephyr/include/generated/zephyr/devicetree_generated.h.
110+ */
111+ #define Z_DEVICE_DT_HASH (node_id ) _CONCAT(dts_, DT_NODE_HASH(node_id))
112+
113+ /* By default, device identifiers are obtained using the dependency ordinal.
114+ * When LLEXT_EXPORT_DEV_IDS_BY_HASH is defined, the main Zephyr binary exports
115+ * DT identifiers via EXPORT_SYMBOL_NAMED as hashed versions of their paths.
116+ * When matching extensions are built, that is what they need to look for.
117+ *
118+ * The ordinal or hash used in this name can be mapped to the path by
119+ * examining zephyr/include/generated/zephyr/devicetree_generated.h.
120+ */
121+ #if defined(LL_EXTENSION_BUILD ) && defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH )
122+ #define Z_DEVICE_DT_DEV_ID (node_id ) Z_DEVICE_DT_HASH(node_id)
123+ #else
124+ #define Z_DEVICE_DT_DEV_ID (node_id ) Z_DEVICE_DT_DEP_ORD(node_id)
125+ #endif
126+
127+ #if defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH )
128+ /* Export device identifiers by hash */
129+ #define Z_DEVICE_EXPORT (node_id ) \
130+ EXPORT_SYMBOL_NAMED(DEVICE_DT_NAME_GET(node_id), \
131+ DEVICE_NAME_GET(Z_DEVICE_DT_HASH(node_id)))
132+ #elif defined(CONFIG_LLEXT_EXPORT_DEVICES )
107133/* Export device identifiers using the builtin name */
108134#define Z_DEVICE_EXPORT (node_id ) EXPORT_SYMBOL(DEVICE_DT_NAME_GET(node_id))
109135#endif
@@ -175,8 +201,8 @@ typedef int16_t device_handle_t;
175201 *
176202 * This macro defines a @ref device that is automatically configured by the
177203 * kernel during system initialization. The global device object's name as a C
178- * identifier is derived from the node's dependency ordinal. @ref device.name is
179- * set to `DEVICE_DT_NAME(node_id)`.
204+ * identifier is derived from the node's dependency ordinal or hash.
205+ * @ref device.name is set to `DEVICE_DT_NAME(node_id)`.
180206 *
181207 * The device is declared with extern visibility, so a pointer to a global
182208 * device object can be obtained with `DEVICE_DT_GET(node_id)` from any source
0 commit comments