dtc: parser: Add label while overriding nodes
PATCH v2 1/1 dtc: parser: Add label while overriding nodes
This patch changes the dtc grammar to allow following syntax
i2cexp: &i2c2 {
...
};Current device tree compiler allows to define multiple labels when defining the device node the first time. Typically device nodes are defined in DTSI files. Now these nodes can be overwritten for updating some of the properties. Typically, device nodes are overridden in DTS files.
When working with adapter boards, most of the time adapter board can fit to multiple base boards. But depending on which base board it is connected to, the devices on the adapter board would be children of different devices.
e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas on dra72-evm.dts, i2c5 is exported for expansion connector. This causes a problem when writing a generic device tree file for the adapter board. Because, you cannot know whether all the devices on adapter board are present on i2c or i2c5.
The problem can be solved by adding a common label (e.g. i2cexp) in both of the DTS files when overriding the device nodes for i2c2 or i2c5. This way, generic adapter board file would override the i2cexp. And depending on which base board you use the adapter board, all the devices are automatically added for correct device nodes.
--- dtc-parser.y | 12 ++++++++ tests/run_tests.sh | 2 ++ tests/test_tree1_label_noderef.dts | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/test_tree1_label_noderef.dts
dtc-parser.y +12 -0
@@ -140,6 +140,18 @@ devicetree: { $$ = merge_nodes($1, $3); } + + | devicetree DT_LABEL DT_REF nodedef + { + struct node *target = get_node_by_ref($1, $3); + + add_label(&target->labels, $2); + if (target) + merge_nodes(target, $4); + else + ERROR(&@3, "Label or path %s not found", $3); + $$ = $1; + } | devicetree DT_REF nodedef { struct node *target = get_node_by_ref($1, $2);
tests/run_tests.sh +2 -0
@@ -399,6 +399,8 @@ dtc_tests () { tree1_tests dtc_tree1_merge.test.dtb test_tree1.dtb run_dtc_test -I dts -O dtb -o dtc_tree1_merge_labelled.test.dtb test_tree1_merge_labelled.dts tree1_tests dtc_tree1_merge_labelled.test.dtb test_tree1.dtb + run_dtc_test -I dts -O dtb -o dtc_tree1_label_noderef.test.dtb test_tree1_label_noderef.dts + tree1_tests dtc_tree1_label_noderef.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
tests/test_tree1_label_noderef.dts new file +55 -0
55 lines not on this page · raw message
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
David Gibson
AppliedQuoted 21 lines · Nikhil Devshatwar
This patch changes the dtc grammar to allow following syntax
i2cexp: &i2c2 { ... };Current device tree compiler allows to define multiple labels when defining the device node the first time. Typically device nodes are defined in DTSI files. Now these nodes can be overwritten for updating some of the properties. Typically, device nodes are overridden in DTS files.
When working with adapter boards, most of the time adapter board can fit to multiple base boards. But depending on which base board it is connected to, the devices on the adapter board would be children of different devices.
e.g. On
dra7-evm.dts, i2c2 is exported for expansion connector whereas ondra72-evm.dts, i2c5 is exported for expansion connector. This causes a problem when writing a generic device tree file for the adapter board. Because, you cannot know whether all the devices on adapter board are present on i2c or i2c5.
Quoted 7 lines
The problem can be solved by adding a common label (e.g. i2cexp) in both of the DTS files when overriding the device nodes for i2c2 or i2c5. This way, generic adapter board file would override the i2cexp. And depending on which base board you use the adapter board, all the devices are automatically added for correct device nodes.
Signed-off-by Nikhil Devshatwar <[email protected]>
Applied, thanks.
I did tweak the testcase to use dtbs_unordered_equal instead of going through the set of tree1 tests.
The fact that you can only apply a single label by this method is a bit of a wart, but it's something we can fix later. I had a look at it and (as I suspect you already discovered) it's surprisingly complicated to do so.
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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 37 lines
-----Original Message-----
From: David Gibson [mailto:[email protected]]
Sent: Monday, February 23, 2015 7:18 AM
To: Devshatwar, Nikhil
Cc: jdl-CYoMK+44s/[email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH v2] dtc: parser: Add label while overriding nodesQuoted 9 lines · Nikhil Devshatwar
This patch changes the dtc grammar to allow following syntax
i2cexp: &i2c2 { ... };Current device tree compiler allows to define multiple labels when defining the device node the first time. Typically device nodes are defined in DTSI files. Now these nodes can be overwritten for
updating
Quoted 1 line
some of the properties. Typically, device nodes are overridden in DTS
files.
Quoted 4 lines
When working with adapter boards, most of the time adapter board can fit to multiple base boards. But depending on which base board it is connected to, the devices on the adapter board would be children of
different devices.
Quoted 2 lines
e.g. On
dra7-evm.dts, i2c2 is exported for expansion connectorwhereas
Quoted 7 lines
on
dra72-evm.dts, i2c5 is exported for expansion connector. This causes a problem when writing a generic device tree file for the adapter board. Because, you cannot know whether all the devices on adapter board are present on i2c or i2c5.The problem can be solved by adding a common label (e.g. i2cexp) in both of the DTS files when overriding the device nodes for i2c2 or
Quoted 9 lines
i2c5.
Quoted 5 lines
This way, generic adapter board file would override the i2cexp. And depending on which base board you use the adapter board, all the devices are automatically added for correct device nodes.
Signed-off-by Nikhil Devshatwar <[email protected]>Applied, thanks.
OK, thanks, that's first upstream contribution!
Quoted 7 lines
I did tweak the testcase to use
dtbs_unordered_equalinstead of going through the set of tree1 tests.The fact that you can only apply a single label by this method is a bit of a wart, but it's something we can fix later. I had a look at it and (as I suspect you already discovered) it's surprisingly complicated to do so.
Yes, but for now even one label can suffice the needs of the problem
Quoted 7 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_!
--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html