2019-06-20 23:19:38 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-06-08 09:18:34 +02:00
|
|
|
/*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
|
|
*/
|
|
|
|
|
2010-04-30 07:27:32 +02:00
|
|
|
%option noyywrap nounput noinput never-interactive
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
%x BYTESTRING
|
2007-11-07 01:16:19 +01:00
|
|
|
%x PROPNODENAME
|
2007-11-07 01:17:17 +01:00
|
|
|
%s V1
|
2005-06-08 09:18:34 +02:00
|
|
|
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
|
|
|
|
PATHCHAR ({PROPNODECHAR}|[/])
|
|
|
|
LABEL [a-zA-Z_][a-zA-Z0-9_]*
|
dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include. We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.
This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code. This is mildly irritating.
However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE. For
example the following strange dts file:
/include/ /dts-v1/;
/ {
/* ... */
};
Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack. Or
for another example this construct:
foo /include/ = "somefile.dts"
will be parsed as though it were:
foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.
And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.
This patch, therefore, cleans up the lexical handling of the /include/
directive. Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token. This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above. It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-06-26 09:08:57 +02:00
|
|
|
STRING \"([^\\"]|\\.)*\"
|
2011-09-09 21:16:30 +02:00
|
|
|
CHAR_LITERAL '([^']|\\')*'
|
dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include. We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.
This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code. This is mildly irritating.
However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE. For
example the following strange dts file:
/include/ /dts-v1/;
/ {
/* ... */
};
Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack. Or
for another example this construct:
foo /include/ = "somefile.dts"
will be parsed as though it were:
foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.
And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.
This patch, therefore, cleans up the lexical handling of the /include/
directive. Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token. This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above. It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-06-26 09:08:57 +02:00
|
|
|
WS [[:space:]]
|
|
|
|
COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
|
|
|
|
LINECOMMENT "//".*\n
|
2005-06-08 09:18:34 +02:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include "dtc.h"
|
2007-03-29 00:05:33 +02:00
|
|
|
#include "srcpos.h"
|
2005-06-16 06:36:37 +02:00
|
|
|
#include "dtc-parser.tab.h"
|
2007-03-23 21:18:41 +01:00
|
|
|
|
2010-01-29 17:31:51 +01:00
|
|
|
YYLTYPE yylloc;
|
2014-01-03 10:00:01 +01:00
|
|
|
extern bool treesource_error;
|
2009-12-08 04:24:42 +01:00
|
|
|
|
|
|
|
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
|
2008-10-03 18:46:43 +02:00
|
|
|
#define YY_USER_ACTION \
|
|
|
|
{ \
|
2009-12-08 04:24:42 +01:00
|
|
|
srcpos_update(&yylloc, yytext, yyleng); \
|
2008-10-03 18:46:43 +02:00
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2005-06-16 09:04:00 +02:00
|
|
|
/*#define LEXDEBUG 1*/
|
|
|
|
|
|
|
|
#ifdef LEXDEBUG
|
|
|
|
#define DPRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DPRINT(fmt, ...) do { } while (0)
|
|
|
|
#endif
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2008-08-15 00:19:37 +02:00
|
|
|
static int dts_version = 1;
|
2005-10-19 08:00:31 +02:00
|
|
|
|
2008-08-15 00:19:37 +02:00
|
|
|
#define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
|
2007-11-07 01:17:17 +01:00
|
|
|
BEGIN(V1); \
|
2008-03-06 02:45:41 +01:00
|
|
|
|
|
|
|
static void push_input_file(const char *filename);
|
2013-10-28 11:06:53 +01:00
|
|
|
static bool pop_input_file(void);
|
2017-03-06 02:06:15 +01:00
|
|
|
static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
|
2017-02-28 00:09:45 +01:00
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
%}
|
|
|
|
|
2005-07-04 05:53:14 +02:00
|
|
|
%%
|
dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include. We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.
This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code. This is mildly irritating.
However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE. For
example the following strange dts file:
/include/ /dts-v1/;
/ {
/* ... */
};
Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack. Or
for another example this construct:
foo /include/ = "somefile.dts"
will be parsed as though it were:
foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.
And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.
This patch, therefore, cleans up the lexical handling of the /include/
directive. Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token. This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above. It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-06-26 09:08:57 +02:00
|
|
|
<*>"/include/"{WS}*{STRING} {
|
|
|
|
char *name = strchr(yytext, '\"') + 1;
|
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
push_input_file(name);
|
2007-03-23 21:18:41 +01:00
|
|
|
}
|
|
|
|
|
2013-05-31 20:33:04 +02:00
|
|
|
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
|
2016-01-04 12:56:39 +01:00
|
|
|
char *line, *fnstart, *fnend;
|
|
|
|
struct data fn;
|
2012-09-28 01:11:05 +02:00
|
|
|
/* skip text before line # */
|
|
|
|
line = yytext;
|
2013-12-25 05:26:03 +01:00
|
|
|
while (!isdigit((unsigned char)*line))
|
2012-09-28 01:11:05 +02:00
|
|
|
line++;
|
2016-01-04 12:56:39 +01:00
|
|
|
|
|
|
|
/* regexp ensures that first and list "
|
|
|
|
* in the whole yytext are those at
|
|
|
|
* beginning and end of the filename string */
|
|
|
|
fnstart = memchr(yytext, '"', yyleng);
|
|
|
|
for (fnend = yytext + yyleng - 1;
|
|
|
|
*fnend != '"'; fnend--)
|
|
|
|
;
|
|
|
|
assert(fnstart && fnend && (fnend > fnstart));
|
|
|
|
|
|
|
|
fn = data_copy_escape_string(fnstart + 1,
|
|
|
|
fnend - fnstart - 1);
|
|
|
|
|
|
|
|
/* Don't allow nuls in filenames */
|
|
|
|
if (memchr(fn.val, '\0', fn.len - 1))
|
|
|
|
lexical_error("nul in line number directive");
|
|
|
|
|
2012-09-28 01:11:05 +02:00
|
|
|
/* -1 since #line is the number of the next line */
|
2016-01-04 12:56:39 +01:00
|
|
|
srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
|
|
|
|
data_free(fn);
|
2012-09-28 01:11:05 +02:00
|
|
|
}
|
|
|
|
|
2007-11-07 01:16:19 +01:00
|
|
|
<*><<EOF>> {
|
2007-03-23 21:18:41 +01:00
|
|
|
if (!pop_input_file()) {
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include. We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.
This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code. This is mildly irritating.
However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE. For
example the following strange dts file:
/include/ /dts-v1/;
/ {
/* ... */
};
Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack. Or
for another example this construct:
foo /include/ = "somefile.dts"
will be parsed as though it were:
foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.
And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.
This patch, therefore, cleans up the lexical handling of the /include/
directive. Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token. This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above. It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-06-26 09:08:57 +02:00
|
|
|
<*>{STRING} {
|
2005-06-16 09:04:00 +02:00
|
|
|
DPRINT("String: %s\n", yytext);
|
2005-06-08 09:18:34 +02:00
|
|
|
yylval.data = data_copy_escape_string(yytext+1,
|
|
|
|
yyleng-2);
|
|
|
|
return DT_STRING;
|
|
|
|
}
|
|
|
|
|
2007-11-07 01:17:17 +01:00
|
|
|
<*>"/dts-v1/" {
|
|
|
|
DPRINT("Keyword: /dts-v1/\n");
|
|
|
|
dts_version = 1;
|
|
|
|
BEGIN_DEFAULT();
|
|
|
|
return DT_V1;
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:48:18 +01:00
|
|
|
<*>"/plugin/" {
|
|
|
|
DPRINT("Keyword: /plugin/\n");
|
|
|
|
return DT_PLUGIN;
|
|
|
|
}
|
|
|
|
|
2007-11-07 01:16:19 +01:00
|
|
|
<*>"/memreserve/" {
|
2005-07-15 09:14:24 +02:00
|
|
|
DPRINT("Keyword: /memreserve/\n");
|
2007-11-07 01:17:17 +01:00
|
|
|
BEGIN_DEFAULT();
|
2007-11-07 01:16:19 +01:00
|
|
|
return DT_MEMRESERVE;
|
2005-07-15 09:14:24 +02:00
|
|
|
}
|
2007-07-07 08:18:50 +02:00
|
|
|
|
2011-10-11 19:22:29 +02:00
|
|
|
<*>"/bits/" {
|
|
|
|
DPRINT("Keyword: /bits/\n");
|
|
|
|
BEGIN_DEFAULT();
|
|
|
|
return DT_BITS;
|
|
|
|
}
|
|
|
|
|
2012-08-08 06:50:15 +02:00
|
|
|
<*>"/delete-property/" {
|
|
|
|
DPRINT("Keyword: /delete-property/\n");
|
|
|
|
DPRINT("<PROPNODENAME>\n");
|
|
|
|
BEGIN(PROPNODENAME);
|
|
|
|
return DT_DEL_PROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
<*>"/delete-node/" {
|
|
|
|
DPRINT("Keyword: /delete-node/\n");
|
|
|
|
DPRINT("<PROPNODENAME>\n");
|
|
|
|
BEGIN(PROPNODENAME);
|
|
|
|
return DT_DEL_NODE;
|
|
|
|
}
|
|
|
|
|
dtc: add ability to make nodes conditional on them being referenced
A number of platforms have a need to reduce the number of DT nodes,
mostly because of two similar constraints: the size of the DT blob, and
the time it takes to parse it.
As the DT is used in more and more SoCs, and by more projects, some
constraints start to appear in bootloaders running from SRAM with an
order of magnitude of 10kB. A typical DT is in the same order of
magnitude, so any effort to reduce the blob size is welcome in such an
environment.
Some platforms also want to reach very fast boot time, and the time it
takes to parse a typical DT starts to be noticeable.
Both of these issues can be mitigated by reducing the number of nodes in
the DT. The biggest provider of nodes is usually the pin controller and
its subnodes, usually one for each valid pin configuration in a given
SoC.
Obviously, a single, fixed, set of these nodes will be used by a given
board, so we can introduce a node property that will tell the DT
compiler to drop the nodes when they are not referenced in the tree, and
as such wouldn't be useful in the targetted system.
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-05-03 22:27:26 +02:00
|
|
|
<*>"/omit-if-no-ref/" {
|
|
|
|
DPRINT("Keyword: /omit-if-no-ref/\n");
|
|
|
|
DPRINT("<PROPNODENAME>\n");
|
|
|
|
BEGIN(PROPNODENAME);
|
|
|
|
return DT_OMIT_NO_REF;
|
|
|
|
}
|
|
|
|
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
<*>{LABEL}: {
|
2007-07-07 08:18:50 +02:00
|
|
|
DPRINT("Label: %s\n", yytext);
|
2008-10-03 18:12:33 +02:00
|
|
|
yylval.labelref = xstrdup(yytext);
|
2007-11-07 01:16:19 +01:00
|
|
|
yylval.labelref[yyleng-1] = '\0';
|
2007-07-07 08:18:50 +02:00
|
|
|
return DT_LABEL;
|
|
|
|
}
|
|
|
|
|
2012-04-04 04:56:00 +02:00
|
|
|
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
|
2014-01-03 10:00:01 +01:00
|
|
|
char *e;
|
|
|
|
DPRINT("Integer Literal: '%s'\n", yytext);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
yylval.integer = strtoull(yytext, &e, 0);
|
|
|
|
|
2016-01-03 12:54:37 +01:00
|
|
|
if (*e && e[strspn(e, "UL")]) {
|
|
|
|
lexical_error("Bad integer literal '%s'",
|
|
|
|
yytext);
|
|
|
|
}
|
2014-01-03 10:00:01 +01:00
|
|
|
|
|
|
|
if (errno == ERANGE)
|
|
|
|
lexical_error("Integer literal '%s' out of range",
|
|
|
|
yytext);
|
|
|
|
else
|
|
|
|
/* ERANGE is the only strtoull error triggerable
|
|
|
|
* by strings matching the pattern */
|
|
|
|
assert(errno == 0);
|
2007-11-07 01:16:19 +01:00
|
|
|
return DT_LITERAL;
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 21:16:30 +02:00
|
|
|
<*>{CHAR_LITERAL} {
|
2014-01-04 00:03:55 +01:00
|
|
|
struct data d;
|
|
|
|
DPRINT("Character literal: %s\n", yytext);
|
|
|
|
|
|
|
|
d = data_copy_escape_string(yytext+1, yyleng-2);
|
|
|
|
if (d.len == 1) {
|
|
|
|
lexical_error("Empty character literal");
|
|
|
|
yylval.integer = 0;
|
2016-12-11 21:13:16 +01:00
|
|
|
} else {
|
|
|
|
yylval.integer = (unsigned char)d.val[0];
|
2014-01-04 00:03:55 +01:00
|
|
|
|
2016-12-11 21:13:16 +01:00
|
|
|
if (d.len > 2)
|
|
|
|
lexical_error("Character literal has %d"
|
|
|
|
" characters instead of 1",
|
|
|
|
d.len - 1);
|
|
|
|
}
|
2014-01-04 00:03:55 +01:00
|
|
|
|
2016-12-11 21:13:16 +01:00
|
|
|
data_free(d);
|
2011-09-09 21:16:30 +02:00
|
|
|
return DT_CHAR_LITERAL;
|
|
|
|
}
|
|
|
|
|
2010-09-21 00:33:34 +02:00
|
|
|
<*>\&{LABEL} { /* label reference */
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
DPRINT("Ref: %s\n", yytext+1);
|
2008-10-03 18:12:33 +02:00
|
|
|
yylval.labelref = xstrdup(yytext+1);
|
2018-09-24 13:27:27 +02:00
|
|
|
return DT_LABEL_REF;
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
}
|
|
|
|
|
2014-05-09 12:48:49 +02:00
|
|
|
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
yytext[yyleng-1] = '\0';
|
|
|
|
DPRINT("Ref: %s\n", yytext+2);
|
2008-10-03 18:12:33 +02:00
|
|
|
yylval.labelref = xstrdup(yytext+2);
|
2018-09-24 13:27:27 +02:00
|
|
|
return DT_PATH_REF;
|
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@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.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-22 07:10:07 +01:00
|
|
|
}
|
|
|
|
|
2005-06-08 09:18:34 +02:00
|
|
|
<BYTESTRING>[0-9a-fA-F]{2} {
|
|
|
|
yylval.byte = strtol(yytext, NULL, 16);
|
2005-06-16 09:04:00 +02:00
|
|
|
DPRINT("Byte: %02x\n", (int)yylval.byte);
|
2005-06-08 09:18:34 +02:00
|
|
|
return DT_BYTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
<BYTESTRING>"]" {
|
2005-06-16 09:04:00 +02:00
|
|
|
DPRINT("/BYTESTRING\n");
|
2007-11-07 01:17:17 +01:00
|
|
|
BEGIN_DEFAULT();
|
2005-06-08 09:18:34 +02:00
|
|
|
return ']';
|
|
|
|
}
|
|
|
|
|
2012-09-28 01:11:04 +02:00
|
|
|
<PROPNODENAME>\\?{PROPNODECHAR}+ {
|
2007-11-07 01:16:19 +01:00
|
|
|
DPRINT("PropNodeName: %s\n", yytext);
|
2012-09-28 01:11:04 +02:00
|
|
|
yylval.propnodename = xstrdup((yytext[0] == '\\') ?
|
|
|
|
yytext + 1 : yytext);
|
2007-11-07 01:17:17 +01:00
|
|
|
BEGIN_DEFAULT();
|
2007-11-07 01:16:19 +01:00
|
|
|
return DT_PROPNODENAME;
|
2005-06-08 09:18:34 +02:00
|
|
|
}
|
|
|
|
|
dtc: Add support for binary includes.
On Wed, Jun 04, 2008 at 09:26:23AM -0500, Jon Loeliger wrote:
> David Gibson wrote:
>
>> But as I said that can be dealt with in the future without breaking
>> compatibility. Objection withdrawn.
>>
>
> And on that note, I officially implore Scott to
> re-submit his binary include patch!
Scott's original patch does still have some implementation details I
didn't like. So in the interests of saving time, I've addressed some
of those, added a testcase, and and now resubmitting my revised
version of Scott's patch.
dtc: Add support for binary includes.
A property's data can be populated with a file's contents
as follows:
node {
prop = /incbin/("path/to/data");
};
A subset of a file can be included by passing start and size parameters.
For example, to include bytes 8 through 23:
node {
prop = /incbin/("path/to/data", 8, 16);
};
As with /include/, non-absolute paths are looked for in the directory
of the source file that includes them.
Implementation revised, and a testcase added by David Gibson
Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Scott Wood <scottwood@freescale.com>
2008-06-11 03:58:39 +02:00
|
|
|
"/incbin/" {
|
|
|
|
DPRINT("Binary Include\n");
|
|
|
|
return DT_INCBIN;
|
|
|
|
}
|
|
|
|
|
dtc: Clean up lexing of include files
Currently we scan the /include/ directive as two tokens, the
"/include/" keyword itself, then the string giving the file name to
include. We use a special scanner state to keep the two linked
together, and use the scanner state stack to keep track of the
original state while we're parsing the two /include/ tokens.
This does mean that we need to enable the 'stack' option in flex,
which results in a not-easily-suppressed warning from the flex
boilerplate code. This is mildly irritating.
However, this two-token scanning of the /include/ directive also has
some extremely strange edge cases, because there are a variety of
tokens recognized in all scanner states, including INCLUDE. For
example the following strange dts file:
/include/ /dts-v1/;
/ {
/* ... */
};
Will be processed successfully with the /include/ being effectively
ignored: the '/dts-v1/' and ';' are recognized even in INCLUDE state,
then the ';' transitions us to PROPNODENAME state, throwing away
INCLUDE, and the previous state is never popped off the stack. Or
for another example this construct:
foo /include/ = "somefile.dts"
will be parsed as though it were:
foo = /include/ "somefile.dts"
Again, the '=' is scanned without leaving INCLUDE state, then the next
string triggers the include logic.
And finally, we use a different regexp for the string with the
included filename than the normal string regexpt, which is also
potentially weird.
This patch, therefore, cleans up the lexical handling of the /include/
directive. Instead of the INCLUDE state, we instead scan the whole
include directive, both keyword and filename as a single token. This
does mean a bit more complexity in extracting the filename out of
yytext, but I think it's worth it to avoid the strageness described
above. It also means it's no longer possible to put a comment between
the /include/ and the filename, but I'm really not very worried about
breaking files using such a strange construct.
2008-06-26 09:08:57 +02:00
|
|
|
<*>{WS}+ /* eat whitespace */
|
|
|
|
<*>{COMMENT}+ /* eat C-style comments */
|
|
|
|
<*>{LINECOMMENT}+ /* eat C++-style comments */
|
2005-06-08 09:18:34 +02:00
|
|
|
|
2012-04-04 04:56:00 +02:00
|
|
|
<*>"<<" { return DT_LSHIFT; };
|
|
|
|
<*>">>" { return DT_RSHIFT; };
|
|
|
|
<*>"<=" { return DT_LE; };
|
|
|
|
<*>">=" { return DT_GE; };
|
|
|
|
<*>"==" { return DT_EQ; };
|
|
|
|
<*>"!=" { return DT_NE; };
|
|
|
|
<*>"&&" { return DT_AND; };
|
|
|
|
<*>"||" { return DT_OR; };
|
|
|
|
|
2005-07-15 09:14:24 +02:00
|
|
|
<*>. {
|
2007-12-04 23:50:25 +01:00
|
|
|
DPRINT("Char: %c (\\x%02x)\n", yytext[0],
|
|
|
|
(unsigned)yytext[0]);
|
2007-11-07 01:16:19 +01:00
|
|
|
if (yytext[0] == '[') {
|
|
|
|
DPRINT("<BYTESTRING>\n");
|
|
|
|
BEGIN(BYTESTRING);
|
|
|
|
}
|
|
|
|
if ((yytext[0] == '{')
|
|
|
|
|| (yytext[0] == ';')) {
|
|
|
|
DPRINT("<PROPNODENAME>\n");
|
|
|
|
BEGIN(PROPNODENAME);
|
|
|
|
}
|
2005-06-08 09:18:34 +02:00
|
|
|
return yytext[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|
2007-03-29 00:05:33 +02:00
|
|
|
|
2008-03-06 02:45:41 +01:00
|
|
|
static void push_input_file(const char *filename)
|
2007-03-29 00:05:33 +02:00
|
|
|
{
|
2008-02-26 06:44:29 +01:00
|
|
|
assert(filename);
|
2007-03-29 00:05:33 +02:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
srcfile_push(filename);
|
2007-03-29 00:05:33 +02:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
yyin = current_srcfile->f;
|
|
|
|
|
|
|
|
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
|
2007-03-29 00:05:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-28 11:06:53 +01:00
|
|
|
static bool pop_input_file(void)
|
2007-03-29 00:05:33 +02:00
|
|
|
{
|
2009-12-08 04:24:42 +01:00
|
|
|
if (srcfile_pop() == 0)
|
2013-10-28 11:06:53 +01:00
|
|
|
return false;
|
2007-03-29 00:05:33 +02:00
|
|
|
|
2009-12-08 04:24:42 +01:00
|
|
|
yypop_buffer_state();
|
|
|
|
yyin = current_srcfile->f;
|
2007-03-29 00:05:33 +02:00
|
|
|
|
2013-10-28 11:06:53 +01:00
|
|
|
return true;
|
2007-03-29 00:05:33 +02:00
|
|
|
}
|
2014-01-03 10:00:01 +01:00
|
|
|
|
|
|
|
static void lexical_error(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
treesource_error = true;
|
|
|
|
}
|