dtc: RFC: Fix some lexical problems with references
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.
- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.
- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.
This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
dtc-lexer.l +24 -7
@@ -25,12 +25,12 @@ %x PROPNODENAME %s V1 -PROPCHAR [a-zA-Z0-9,._+*#?-] -UNITCHAR [0-9a-f,] +PROPNODECHAR [a-zA-Z0-9,._+*#?@-] +PATHCHAR ({PROPNODECHAR}|[/]) +LEGACYPATHCHAR [a-zA-Z0-9_@/] +LABEL [a-zA-Z_][a-zA-Z0-9_]* WS [[:space:]] -REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) - %{ #include "dtc.h" #include "srcpos.h"
@@ -102,7 +102,7 @@ return DT_MEMRESERVE; } -<*>[a-zA-Z_][a-zA-Z0-9_]*: { +<*>{LABEL}: { yylloc.filenum = srcpos_filenum; yylloc.first_line = yylineno; DPRINT("Label: %s\n", yytext);
@@ -142,7 +142,24 @@ return DT_LITERAL; } -\&{REFCHAR}* { +\&{LABEL} { /* label reference */ + yylloc.filenum = srcpos_filenum; + yylloc.first_line = yylineno; + DPRINT("Ref: %s\n", yytext+1); + yylval.labelref = strdup(yytext+1); + return DT_REF; + } + +"&{/"{PATHCHAR}+\} { /* new-style path reference */ + yylloc.filenum = srcpos_filenum; + yylloc.first_line = yylineno; + yytext[yyleng-1] = '\0'; + DPRINT("Ref: %s\n", yytext+2); + yylval.labelref = strdup(yytext+2); + return DT_REF; + } + +<INITIAL>"&/"{LEGACYPATHCHAR}+ { /* old-style path reference */ yylloc.filenum = srcpos_filenum; yylloc.first_line = yylineno; DPRINT("Ref: %s\n", yytext+1);
@@ -166,7 +183,7 @@ return ']'; } -<PROPNODENAME>{PROPCHAR}+(@{UNITCHAR}+)? { +<PROPNODENAME>{PROPNODECHAR}+ { yylloc.filenum = srcpos_filenum; yylloc.first_line = yylineno; DPRINT("PropNodeName: %s\n", yytext);
tests/nonexist-node-ref.dts +2 -2
@@ -1,8 +1,8 @@ /dts-v1/; / { - ref = < &/node >; - badref = < &/nosuchnode >; + ref = < &{/node} >; + badref = < &{/nosuchnode} >; label: node { }; };
tests/references.dts +3 -3
@@ -4,18 +4,18 @@ /* Explicit phandles */ n1: node1 { linux,phandle = <0x2000>; - ref = <&/node2>; /* reference precedes target */ + ref = <&{/node2}>; /* reference precedes target */ lref = <&n2>; }; n2: node2 { linux,phandle = <0x1>; - ref = <&/node1>; /* reference after target */ + ref = <&{/node1}>; /* reference after target */ lref = <&n1>; }; /* Implicit phandles */ n3: node3 { - ref = <&/node4>; + ref = <&{/node4}>; lref = <&n4>; }; n4: node4 {
tests/references_dts0.dts new file +21 -0
@@ -0,0 +1,21 @@ +/ { + /* Explicit phandles */ + n1: node1 { + linux,phandle = <2000>; + ref = <&/node2>; /* reference precedes target */ + lref = <&n2>; + }; + n2: node2 { + linux,phandle = <1>; + ref = <&/node1>; /* reference after target */ + lref = <&n1>; + }; + + /* Implicit phandles */ + n3: node3 { + ref = <&/node4>; + lref = <&n4>; + }; + n4: node4 { + }; +};
tests/run_tests.sh +3 -0
@@ -145,6 +145,9 @@ run_test dtc.sh -I dts -O dtb -o dtc_references.test.dtb references.dts run_test references dtc_references.test.dtb + run_test dtc.sh -I dts -O dtb -o dtc_references_dts0.test.dtb references_dts0.dts + run_test references dtc_references_dts0.test.dtb + # Check -Odts mode preserve all dtb information for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb ; do run_test dtc.sh -I dtb -O dts -o odts_$tree.test.dts $tree
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 31 lines · David Gibson
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Quoted 5 lines
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
Just to note: we need to do something here, but there are approaches other than the one above (hence the RFC). For example, if we just separate the lexical recognition of refs-to-labels from refs-to-paths then we can continue to recognize full bare path references. However, in some circumstances it might be necessary to add whitespace in the dts to correctly mark the end of the path (in the case '/' and ' ' would essentially take the place of the braces for delimiting the path). That maintains full compatibility, and avoids the arguably ugly &{/foo} syntax, but it does mean there are some odd situations like the fact that (once string references are implemented):
&label1, &label2 and &label1 , &label2 would be equivalent, but the following two: &/node1, &/node2 &/node1 , &/node2
would not be equivalent (depending on context one or both of them could be syntax errors). The first is a reference to the node "/node1," then a reference to the node "/node2", the second is a reference to the node "/node1" then a comma then a reference to the node "/node2".
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
So, like, the other day David Gibson mumbled:
Quoted 31 lines
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Quoted 5 lines
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
This all sounds fine by me. We should take the incompatibility hit once here and now; it shouldn't be a problem to eek in some more still.
Thanks,
jdl
Jon Loeliger
AppliedSo, like, the other day David Gibson mumbled:
Quoted 31 lines
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Quoted 7 lines
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
Signed-off-by David Gibson <[email protected]>
Applied.
jdl
Quoted 31 lines · On Thu, 22 Nov 2007 17:10:07 +1100 David Gibson <[email protected]>…
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Quoted 7 lines
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
Signed-off-by David Gibson <[email protected]>
So this breaks some of the in-kernel DTS files. Example, bamboo.dts on line 19 produces:
bamboo.dts: 19 syntax error
FATAL ERROR: Couldn't read input tree
I tried quoting the path with {} but that didn't seem to work.
josh
Quoted 42 lines · On Wed, 5 Dec 2007 16:34:09 -0600 Josh Boyer <[email protected]> wrote:
Quoted 31 lines · On Thu, 22 Nov 2007 17:10:07 +1100 David Gibson <[email protected]>…
The recent change to the lexer to only recognize property and node names in the appropriate context removed a number of lexical warts in our language that would have gotten ugly as we add expression support and so forth.
But there's one nasty one remaining: references can contain a full path, including the various problematic node name characters (',', '+' and '-', for example). This would cause trouble with expressions, and it also causes trouble with the patch I'm working on to allow expanding references to paths rather than phandles. This patch therefore reworks the lexer to mitigate these problems.
- References to labels cause no problems. These are now
recognized separately from references to full paths. No syntax change here.- References to full paths, including problematic characters
are allowed by "quoting" the path with braces
e.g. &{/pci@10000/somedevice@3,8000}. The braces protect any internal problematic characters from being confused with operators or whatever.- For compatibility with existing dts files, in v0 dts files
we allow bare references to paths as before &/foo/bar/whatever - but *only* if the path contains no troublesome characters. Specifically only [a-zA-Z0-9_@/] are allowed.This is an incompatible change to the dts-v1 format, but since AFAIK no-one has yet switched to dts-v1 files, I think we can get away with it. Better to make the transition when people to convert to v1, and get rid of the problematic old syntax.
Quoted 7 lines
Strictly speaking, it's also an incompatible change to the v0 format, since some path references that were allowed before are no longer allowed. I suspect no-one has been using the no-longer-supported forms (certainly none of the kernel dts files will cause trouble). We might need to think about this harder, though.
Signed-off-by David Gibson <[email protected]>
Quoted 7 lines
So this breaks some of the in-kernel DTS files. Example,
bamboo.dtson line 19 produces:
bamboo.dts: 19 syntax error
FATAL ERROR: Couldn't read input treeI tried quoting the path with {} but that didn't seem to work.
Nevermind, the quoting worked.
josh