Allow device tree to be modified by additonal device tree sections
PATCH 1/1 Allow device tree to be modified by additonal device tree sections
This patch allows the following construct:
/ {
property-a = "old";
property-b = "does not change";
};/ {
property-a = "changed";
property-c = "new";
node-a {
};
};Where the later device tree overrides the properties found in the earlier tree. This is useful for laying down a template device tree in an include file and modifying it for a specific board without having to clone the entire tree.
Signed-off-by Grant Likely <grant.likely-s3s/[email protected]>
---
dtc-parser.y | 14 +++++++- dtc.h | 1 + livetree.c | 79 +++++++++++++++++++++++++++++++++++++++++++- tests/multilabel.dts | 12 ++++--- tests/multilabel_merge.dts | 69 ++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 7 ++++ tests/test_tree1_merge.dts | 45 +++++++++++++++++++++++++ 7 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 tests/multilabel_merge.dts create mode 100644 tests/test_tree1_merge.dts
dtc-parser.y +13 -1
@@ -75,6 +75,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits); %type <proplist> proplist %type <node> devicetree +%type <node> devicetrees %type <node> nodedef %type <node> subnode %type <nodelist> subnodes
@@ -82,7 +83,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits); %% sourcefile: - DT_V1 ';' memreserves devicetree + DT_V1 ';' memreserves devicetrees { the_boot_info = build_boot_info($3, $4, guess_boot_cpuid($4));
@@ -119,6 +120,17 @@ addr: } ; +devicetrees: + devicetree + { + $$ = $1; + } + | devicetrees devicetree + { + $$ = merge_nodes($1, $2); + } + ; + devicetree: '/' nodedef {
dtc.h +1 -0
@@ -174,6 +174,7 @@ struct property *reverse_properties(struct property *first);struct node *build_node (struct property *proplist,struct node *children);struct node *name_node (struct node *node,char *name);struct node *chain_node (struct node *first,struct node *list); +struct node *merge_nodes (struct node *old_node,struct node *new_node);void add_property (struct node *node,struct property *prop);void add_child (struct node *parent,struct node *child);
livetree.c +78 -1
92 lines not on this page · raw message
tests/multilabel.dts +8 -4
@@ -3,26 +3,27 @@ m1: mq: /memreserve/ 0 0x1000; / { - p1: px: prop = "foo"; + p0: pw: prop = "foo"; /* Explicit phandles */ n1: nx: node1 { linux,phandle = <0x2000>; ref = <&{/node2}>; /* reference precedes target */ - lref = <&ny>; + p1: px: lref = <&ny>; }; ny: n2: node2 { - phandle = <0x1>; + p2: py: phandle = <0x1>; ref = <&{/node1}>; /* reference after target */ lref = <&nx>; }; /* Implicit phandles */ n3: node3 { - ref = <&{/node4}>; + p3: ref = <&{/node4}>; lref = <&n4>; }; n4: node4 { + p4: prop = "bar"; }; /* Explicit phandle with implicit value */
@@ -34,5 +35,8 @@ m1: mq: /memreserve/ 0 0x1000; n5: nz: node5 { linux,phandle = <&n5>; phandle = <&nz>; + n1 = &n1; + n2 = &n2; + n3 = &n3; }; };
tests/multilabel_merge.dts new file +69 -0
69 lines not on this page · raw message
tests/run_tests.sh +7 -0
@@ -297,6 +297,13 @@ dtc_tests () { done done + # Check merge/overlay functionality + run_dtc_test -I dts -O dtb -o dtc_tree1_merge.test.dtb test_tree1_merge.dts + tree1_tests dtc_tree1_merge.test.dtb test_tree1.dtb + run_dtc_test -I dts -O dtb -o multilabel_merge.test.dtb multilabel_merge.dts + run_test references multilabel.test.dtb + run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb + # Check some checks check_tests dup-nodename.dts duplicate_node_names check_tests dup-propname.dts duplicate_property_names
tests/test_tree1_merge.dts new file +45 -0
45 lines not on this page · raw message