[Crosstoolchain-logs] [device-tree-compiler] 204/357: dtc: Fix some lexical problems with references

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit 7c44c2f9cb1cc2df7aacd13decfc4e64b73d1730
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Thu Nov 22 17:10:07 2007 +1100

    dtc: 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 at 10000/somedevice at 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.
    
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 dtc-lexer.l                                   | 31 +++++++++++++++++++++------
 tests/nonexist-node-ref.dts                   |  4 ++--
 tests/references.dts                          |  6 +++---
 tests/{references.dts => references_dts0.dts} |  6 ++----
 tests/run_tests.sh                            |  3 +++
 5 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index eec6527..109661d 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -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 @@ static int dts_version; /* = 0 */
 			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 @@ static int dts_version; /* = 0 */
 			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 @@ static int dts_version; /* = 0 */
 			return ']';
 		}
 
-<PROPNODENAME>{PROPCHAR}+(@{UNITCHAR}+)? {
+<PROPNODENAME>{PROPNODECHAR}+ {
 			yylloc.filenum = srcpos_filenum;
 			yylloc.first_line = yylineno;
 			DPRINT("PropNodeName: %s\n", yytext);
diff --git a/tests/nonexist-node-ref.dts b/tests/nonexist-node-ref.dts
index fa35891..efd4140 100644
--- a/tests/nonexist-node-ref.dts
+++ b/tests/nonexist-node-ref.dts
@@ -1,8 +1,8 @@
 /dts-v1/;
 
 / {
-	ref = < &/node >;
-	badref = < &/nosuchnode >;
+	ref = < &{/node} >;
+	badref = < &{/nosuchnode} >;
 	label: node {
 	};
 };
diff --git a/tests/references.dts b/tests/references.dts
index fc032f8..36b6f51 100644
--- a/tests/references.dts
+++ b/tests/references.dts
@@ -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 {
diff --git a/tests/references.dts b/tests/references_dts0.dts
similarity index 82%
copy from tests/references.dts
copy to tests/references_dts0.dts
index fc032f8..df82c23 100644
--- a/tests/references.dts
+++ b/tests/references_dts0.dts
@@ -1,14 +1,12 @@
-/dts-v1/;
-
 / {
 	/* Explicit phandles */
 	n1: node1 {
-		linux,phandle = <0x2000>;
+		linux,phandle = <2000>;
 		ref = <&/node2>; /* reference precedes target */
 		lref = <&n2>;
 	};
 	n2: node2 {
-		linux,phandle = <0x1>;
+		linux,phandle = <1>;
 		ref = <&/node1>; /* reference after target */
 		lref = <&n1>;
 	};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index a8f6e10..d8bedca 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -144,6 +144,9 @@ dtc_tests () {
     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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list