1 .. SPDX-License-Identifier: GPL-2.0
3 =========================
4 Device Tree Overlay Notes
5 =========================
7 This document describes the implementation of the in-kernel
8 device tree overlay functionality residing in drivers/of/overlay.c and is a
9 companion document to Documentation/devicetree/dynamic-resolution-notes.rst[1]
14 A Device Tree's overlay purpose is to modify the kernel's live tree, and
15 have the modification affecting the state of the kernel in a way that
16 is reflecting the changes.
17 Since the kernel mainly deals with devices, any new device node that result
18 in an active device should have it created while if the device node is either
19 disabled or removed all together, the affected device should be deregistered.
21 Lets take an example where we have a foo board with the following base tree::
23 ---- foo.dts ---------------------------------------------------------------
27 compatible = "corp,foo";
29 /* shared resources */
33 /* On chip peripherals */
35 /* peripherals that are always instantiated */
39 ---- foo.dts ---------------------------------------------------------------
44 ---- bar.dts - overlay target location by label ----------------------------
50 compatible = "corp,bar";
51 ... /* various properties and child nodes */
54 ---- bar.dts ---------------------------------------------------------------
56 when loaded (and resolved as described in [1]) should result in foo+bar.dts::
58 ---- foo+bar.dts -----------------------------------------------------------
59 /* FOO platform + bar peripheral */
61 compatible = "corp,foo";
63 /* shared resources */
67 /* On chip peripherals */
69 /* peripherals that are always instantiated */
74 compatible = "corp,bar";
75 ... /* various properties and child nodes */
79 ---- foo+bar.dts -----------------------------------------------------------
81 As a result of the overlay, a new device node (bar) has been created
82 so a bar platform device will be registered and if a matching device driver
83 is loaded the device will be created as expected.
85 If the base DT was not compiled with the -@ option then the "&ocp" label
86 will not be available to resolve the overlay node(s) to the proper location
87 in the base DT. In this case, the target path can be provided. The target
88 location by label syntax is preferred because the overlay can be applied to
89 any base DT containing the label, no matter where the label occurs in the DT.
91 The above bar.dts example modified to use target path syntax is::
93 ---- bar.dts - overlay target location by explicit path --------------------
99 compatible = "corp,bar";
100 ... /* various properties and child nodes */
103 ---- bar.dts ---------------------------------------------------------------
106 Overlay in-kernel API
107 --------------------------------
109 The API is quite easy to use.
111 1) Call of_overlay_fdt_apply() to create and apply an overlay changeset. The
112 return value is an error or a cookie identifying this overlay.
114 2) Call of_overlay_remove() to remove and cleanup the overlay changeset
115 previously created via the call to of_overlay_fdt_apply(). Removal of an
116 overlay changeset that is stacked by another will not be permitted.
118 Finally, if you need to remove all overlays in one-go, just call
119 of_overlay_remove_all() which will remove every single one in the correct
122 In addition, there is the option to register notifiers that get called on
123 overlay operations. See of_overlay_notifier_register/unregister and
124 enum of_overlay_notify_action for details.
126 Note that a notifier callback is not supposed to store pointers to a device
127 tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the
128 respective node it received.