2020-04-15 14:45:22 +00:00
|
|
|
.. SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
2021-03-25 16:47:09 +00:00
|
|
|
========================
|
|
|
|
Devicetree Overlay Notes
|
|
|
|
========================
|
2014-10-28 20:35:58 +00:00
|
|
|
|
|
|
|
This document describes the implementation of the in-kernel
|
|
|
|
device tree overlay functionality residing in drivers/of/overlay.c and is a
|
2020-04-15 14:45:20 +00:00
|
|
|
companion document to Documentation/devicetree/dynamic-resolution-notes.rst[1]
|
2014-10-28 20:35:58 +00:00
|
|
|
|
|
|
|
How overlays work
|
|
|
|
-----------------
|
|
|
|
|
2021-03-25 16:47:09 +00:00
|
|
|
A Devicetree's overlay purpose is to modify the kernel's live tree, and
|
2015-01-02 13:54:39 +00:00
|
|
|
have the modification affecting the state of the kernel in a way that
|
2014-10-28 20:35:58 +00:00
|
|
|
is reflecting the changes.
|
|
|
|
Since the kernel mainly deals with devices, any new device node that result
|
|
|
|
in an active device should have it created while if the device node is either
|
|
|
|
disabled or removed all together, the affected device should be deregistered.
|
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
Lets take an example where we have a foo board with the following base tree::
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
---- foo.dts ---------------------------------------------------------------
|
2014-10-28 20:35:58 +00:00
|
|
|
/* FOO platform */
|
2020-01-28 00:37:18 +00:00
|
|
|
/dts-v1/;
|
2014-10-28 20:35:58 +00:00
|
|
|
/ {
|
|
|
|
compatible = "corp,foo";
|
|
|
|
|
|
|
|
/* shared resources */
|
|
|
|
res: res {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* On chip peripherals */
|
|
|
|
ocp: ocp {
|
|
|
|
/* peripherals that are always instantiated */
|
|
|
|
peripheral1 { ... };
|
2020-01-28 00:37:18 +00:00
|
|
|
};
|
2014-10-28 20:35:58 +00:00
|
|
|
};
|
2020-04-15 14:45:22 +00:00
|
|
|
---- foo.dts ---------------------------------------------------------------
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-01-28 00:37:18 +00:00
|
|
|
The overlay bar.dts,
|
2020-04-15 14:45:22 +00:00
|
|
|
::
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
---- bar.dts - overlay target location by label ----------------------------
|
2020-01-28 00:37:18 +00:00
|
|
|
/dts-v1/;
|
|
|
|
/plugin/;
|
|
|
|
&ocp {
|
|
|
|
/* bar peripheral */
|
|
|
|
bar {
|
|
|
|
compatible = "corp,bar";
|
|
|
|
... /* various properties and child nodes */
|
2014-10-28 20:35:58 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-15 14:45:22 +00:00
|
|
|
---- bar.dts ---------------------------------------------------------------
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
when loaded (and resolved as described in [1]) should result in foo+bar.dts::
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
---- foo+bar.dts -----------------------------------------------------------
|
2014-10-28 20:35:58 +00:00
|
|
|
/* FOO platform + bar peripheral */
|
|
|
|
/ {
|
|
|
|
compatible = "corp,foo";
|
|
|
|
|
|
|
|
/* shared resources */
|
|
|
|
res: res {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* On chip peripherals */
|
|
|
|
ocp: ocp {
|
|
|
|
/* peripherals that are always instantiated */
|
|
|
|
peripheral1 { ... };
|
|
|
|
|
|
|
|
/* bar peripheral */
|
|
|
|
bar {
|
|
|
|
compatible = "corp,bar";
|
|
|
|
... /* various properties and child nodes */
|
2020-01-28 00:37:18 +00:00
|
|
|
};
|
|
|
|
};
|
2014-10-28 20:35:58 +00:00
|
|
|
};
|
2020-04-15 14:45:22 +00:00
|
|
|
---- foo+bar.dts -----------------------------------------------------------
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2015-01-02 13:54:39 +00:00
|
|
|
As a result of the overlay, a new device node (bar) has been created
|
2014-10-28 20:35:58 +00:00
|
|
|
so a bar platform device will be registered and if a matching device driver
|
|
|
|
is loaded the device will be created as expected.
|
|
|
|
|
2020-01-28 00:37:18 +00:00
|
|
|
If the base DT was not compiled with the -@ option then the "&ocp" label
|
|
|
|
will not be available to resolve the overlay node(s) to the proper location
|
|
|
|
in the base DT. In this case, the target path can be provided. The target
|
|
|
|
location by label syntax is preferred because the overlay can be applied to
|
|
|
|
any base DT containing the label, no matter where the label occurs in the DT.
|
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
The above bar.dts example modified to use target path syntax is::
|
2020-01-28 00:37:18 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
---- bar.dts - overlay target location by explicit path --------------------
|
2020-01-28 00:37:18 +00:00
|
|
|
/dts-v1/;
|
|
|
|
/plugin/;
|
|
|
|
&{/ocp} {
|
|
|
|
/* bar peripheral */
|
|
|
|
bar {
|
|
|
|
compatible = "corp,bar";
|
|
|
|
... /* various properties and child nodes */
|
|
|
|
}
|
|
|
|
};
|
2020-04-15 14:45:22 +00:00
|
|
|
---- bar.dts ---------------------------------------------------------------
|
2020-01-28 00:37:18 +00:00
|
|
|
|
|
|
|
|
2014-10-28 20:35:58 +00:00
|
|
|
Overlay in-kernel API
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
The API is quite easy to use.
|
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
1) Call of_overlay_fdt_apply() to create and apply an overlay changeset. The
|
|
|
|
return value is an error or a cookie identifying this overlay.
|
2014-10-28 20:35:58 +00:00
|
|
|
|
2020-04-15 14:45:22 +00:00
|
|
|
2) Call of_overlay_remove() to remove and cleanup the overlay changeset
|
|
|
|
previously created via the call to of_overlay_fdt_apply(). Removal of an
|
|
|
|
overlay changeset that is stacked by another will not be permitted.
|
2014-10-28 20:35:58 +00:00
|
|
|
|
|
|
|
Finally, if you need to remove all overlays in one-go, just call
|
2017-10-17 23:36:23 +00:00
|
|
|
of_overlay_remove_all() which will remove every single one in the correct
|
2014-10-28 20:35:58 +00:00
|
|
|
order.
|
|
|
|
|
2018-04-26 11:00:30 +00:00
|
|
|
In addition, there is the option to register notifiers that get called on
|
|
|
|
overlay operations. See of_overlay_notifier_register/unregister and
|
|
|
|
enum of_overlay_notify_action for details.
|
|
|
|
|
|
|
|
Note that a notifier callback is not supposed to store pointers to a device
|
|
|
|
tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the
|
|
|
|
respective node it received.
|