overlay-notes.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. Device Tree Overlay Notes
  2. -------------------------
  3. This document describes the implementation of the in-kernel
  4. device tree overlay functionality residing in drivers/of/overlay.c and is a
  5. companion document to Documentation/devicetree/dynamic-resolution-notes.txt[1]
  6. How overlays work
  7. -----------------
  8. A Device Tree's overlay purpose is to modify the kernel's live tree, and
  9. have the modification affecting the state of the kernel in a way that
  10. is reflecting the changes.
  11. Since the kernel mainly deals with devices, any new device node that result
  12. in an active device should have it created while if the device node is either
  13. disabled or removed all together, the affected device should be deregistered.
  14. Lets take an example where we have a foo board with the following base tree:
  15. ---- foo.dts -----------------------------------------------------------------
  16. /* FOO platform */
  17. / {
  18. compatible = "corp,foo";
  19. /* shared resources */
  20. res: res {
  21. };
  22. /* On chip peripherals */
  23. ocp: ocp {
  24. /* peripherals that are always instantiated */
  25. peripheral1 { ... };
  26. }
  27. };
  28. ---- foo.dts -----------------------------------------------------------------
  29. The overlay bar.dts, when loaded (and resolved as described in [1]) should
  30. ---- bar.dts -----------------------------------------------------------------
  31. /plugin/; /* allow undefined label references and record them */
  32. / {
  33. .... /* various properties for loader use; i.e. part id etc. */
  34. fragment@0 {
  35. target = <&ocp>;
  36. __overlay__ {
  37. /* bar peripheral */
  38. bar {
  39. compatible = "corp,bar";
  40. ... /* various properties and child nodes */
  41. }
  42. };
  43. };
  44. };
  45. ---- bar.dts -----------------------------------------------------------------
  46. result in foo+bar.dts
  47. ---- foo+bar.dts -------------------------------------------------------------
  48. /* FOO platform + bar peripheral */
  49. / {
  50. compatible = "corp,foo";
  51. /* shared resources */
  52. res: res {
  53. };
  54. /* On chip peripherals */
  55. ocp: ocp {
  56. /* peripherals that are always instantiated */
  57. peripheral1 { ... };
  58. /* bar peripheral */
  59. bar {
  60. compatible = "corp,bar";
  61. ... /* various properties and child nodes */
  62. }
  63. }
  64. };
  65. ---- foo+bar.dts -------------------------------------------------------------
  66. As a result of the overlay, a new device node (bar) has been created
  67. so a bar platform device will be registered and if a matching device driver
  68. is loaded the device will be created as expected.
  69. Overlay in-kernel API
  70. --------------------------------
  71. The API is quite easy to use.
  72. 1. Call of_overlay_fdt_apply() to create and apply an overlay changeset. The
  73. return value is an error or a cookie identifying this overlay.
  74. 2. Call of_overlay_remove() to remove and cleanup the overlay changeset
  75. previously created via the call to of_overlay_fdt_apply(). Removal of an
  76. overlay changeset that is stacked by another will not be permitted.
  77. Finally, if you need to remove all overlays in one-go, just call
  78. of_overlay_remove_all() which will remove every single one in the correct
  79. order.
  80. In addition, there is the option to register notifiers that get called on
  81. overlay operations. See of_overlay_notifier_register/unregister and
  82. enum of_overlay_notify_action for details.
  83. Note that a notifier callback is not supposed to store pointers to a device
  84. tree node or its content beyond OF_OVERLAY_POST_REMOVE corresponding to the
  85. respective node it received.
  86. Overlay DTS Format
  87. ------------------
  88. The DTS of an overlay should have the following format:
  89. {
  90. /* ignored properties by the overlay */
  91. fragment@0 { /* first child node */
  92. target=<phandle>; /* phandle target of the overlay */
  93. or
  94. target-path="/path"; /* target path of the overlay */
  95. __overlay__ {
  96. property-a; /* add property-a to the target */
  97. node-a { /* add to an existing, or create a node-a */
  98. ...
  99. };
  100. };
  101. }
  102. fragment@1 { /* second child node */
  103. ...
  104. };
  105. /* more fragments follow */
  106. }
  107. Using the non-phandle based target method allows one to use a base DT which does
  108. not contain a __symbols__ node, i.e. it was not compiled with the -@ option.
  109. The __symbols__ node is only required for the target=<phandle> method, since it
  110. contains the information required to map from a phandle to a tree location.