overlay-notes.txt 3.8 KB

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