Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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