Allow device tree to be modified by additonal device tree sections
PATCH v3 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.
---
Changes since RFC (v1):
- Fix parser to ensure at least one 'devicetree' section
- merge labels too
- Don't change property value if property already has a value and the redefinition is in the form of an empty property
ie: 'label: property;'
- Add test cases
Changes since v2:
- Revert code that doesn't change property value if the redefinition is in the form of an empty property
- Improvements to test cases
dtc-parser.y | 14 ++++++++ dtc.h | 1 + livetree.c | 75 +++++++++++++++++++++++++++++++++++++++++++- tests/multilabel.dts | 12 +++++-- tests/multilabel_merge.dts | 66 +++++++++++++++++++++++++++++++++++++++ tests/run_tests.sh | 7 ++++ tests/test_tree1_merge.dts | 45 ++++++++++++++++++++++++++ 7 files changed, 214 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 +74 -1
88 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; }; /* 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 +66 -0
66 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
Jon Loeliger
AppliedQuoted 14 lines
This patch allows the following construct:
/ { property-a = "old"; property-b = "does not change"; };/ { property-a = "changed"; property-c = "new"; node-a { }; };
Quoted 6 lines
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]>
Applied.
Thanks,
jdl
A message that is not in the archive (sent off-list or not yet received): E1Nkhq1-0001Of-Hb-CYoMK+44s/[email protected]
Quoted 14 lines · Jon Loeliger
Quoted 14 lines
This patch allows the following construct:
/ { property-a = "old"; property-b = "does not change"; };/ { property-a = "changed"; property-c = "new"; node-a { }; };
Quoted 8 lines
Quoted 6 lines
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]>Applied.
Oops, I was hoping to make a few tweaks to that before it was applied. Oh well, it was basically only more thorough testcases, so that can be added later.
Sorry Grant, my work on this stuff has been rather delayed by yak-shaving.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 4 lines
Oops, I was hoping to make a few tweaks to that before it was applied. Oh well, it was basically only more thorough testcases, so that can be added later.
Sorry -- I had no idea about that.
Follow up patches welcome, of course!
jdl