mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
dtc: Switch dtc to C-style literals
dtc: Switch dtc to C-style literals This patch introduces a new version of dts file, distinguished from older files by starting with the special token /dts-v1/. dts files in the new version take C-style literals instead of the old bare hex or OF-style base notation. In addition, the "range" for of memreserve entries (/memreserve/ f0000-fffff) is no longer recognized in the new format. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jon Loeliger <jdl@freescale.com>
This commit is contained in:
parent
9ed27a2aac
commit
9138db565a
5 changed files with 107 additions and 16 deletions
40
dtc-lexer.l
40
dtc-lexer.l
|
@ -23,6 +23,7 @@
|
||||||
%x INCLUDE
|
%x INCLUDE
|
||||||
%x BYTESTRING
|
%x BYTESTRING
|
||||||
%x PROPNODENAME
|
%x PROPNODENAME
|
||||||
|
%s V1
|
||||||
|
|
||||||
PROPCHAR [a-zA-Z0-9,._+*#?-]
|
PROPCHAR [a-zA-Z0-9,._+*#?-]
|
||||||
UNITCHAR [0-9a-f,]
|
UNITCHAR [0-9a-f,]
|
||||||
|
@ -44,12 +45,18 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
#define DPRINT(fmt, ...) do { } while (0)
|
#define DPRINT(fmt, ...) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int dts_version; /* = 0 */
|
||||||
|
|
||||||
|
#define BEGIN_DEFAULT() if (dts_version == 0) { \
|
||||||
|
DPRINT("<INITIAL>\n"); \
|
||||||
|
BEGIN(INITIAL); \
|
||||||
|
} else { \
|
||||||
|
DPRINT("<V1>\n"); \
|
||||||
|
BEGIN(V1); \
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
<*>"/include/" BEGIN(INCLUDE);
|
<*>"/include/" BEGIN(INCLUDE);
|
||||||
|
|
||||||
<INCLUDE>\"[^"\n]*\" {
|
<INCLUDE>\"[^"\n]*\" {
|
||||||
|
@ -58,7 +65,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
/* Some unrecoverable error.*/
|
/* Some unrecoverable error.*/
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
BEGIN(INITIAL);
|
BEGIN_DEFAULT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,11 +85,20 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
return DT_STRING;
|
return DT_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<*>"/dts-v1/" {
|
||||||
|
yylloc.filenum = srcpos_filenum;
|
||||||
|
yylloc.first_line = yylineno;
|
||||||
|
DPRINT("Keyword: /dts-v1/\n");
|
||||||
|
dts_version = 1;
|
||||||
|
BEGIN_DEFAULT();
|
||||||
|
return DT_V1;
|
||||||
|
}
|
||||||
|
|
||||||
<*>"/memreserve/" {
|
<*>"/memreserve/" {
|
||||||
yylloc.filenum = srcpos_filenum;
|
yylloc.filenum = srcpos_filenum;
|
||||||
yylloc.first_line = yylineno;
|
yylloc.first_line = yylineno;
|
||||||
DPRINT("Keyword: /memreserve/\n");
|
DPRINT("Keyword: /memreserve/\n");
|
||||||
BEGIN(INITIAL);
|
BEGIN_DEFAULT();
|
||||||
return DT_MEMRESERVE;
|
return DT_MEMRESERVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +111,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
return DT_LABEL;
|
return DT_LABEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
[bodh]# {
|
<INITIAL>[bodh]# {
|
||||||
yylloc.filenum = srcpos_filenum;
|
yylloc.filenum = srcpos_filenum;
|
||||||
yylloc.first_line = yylineno;
|
yylloc.first_line = yylineno;
|
||||||
if (*yytext == 'b')
|
if (*yytext == 'b')
|
||||||
|
@ -110,7 +126,15 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
return DT_BASE;
|
return DT_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
[0-9a-fA-F]+ {
|
<INITIAL>[0-9a-fA-F]+ {
|
||||||
|
yylloc.filenum = srcpos_filenum;
|
||||||
|
yylloc.first_line = yylineno;
|
||||||
|
yylval.literal = strdup(yytext);
|
||||||
|
DPRINT("Literal: '%s'\n", yylval.literal);
|
||||||
|
return DT_LEGACYLITERAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
<V1>[0-9]+|0[xX][0-9a-fA-F]+ {
|
||||||
yylloc.filenum = srcpos_filenum;
|
yylloc.filenum = srcpos_filenum;
|
||||||
yylloc.first_line = yylineno;
|
yylloc.first_line = yylineno;
|
||||||
yylval.literal = strdup(yytext);
|
yylval.literal = strdup(yytext);
|
||||||
|
@ -138,7 +162,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
yylloc.filenum = srcpos_filenum;
|
yylloc.filenum = srcpos_filenum;
|
||||||
yylloc.first_line = yylineno;
|
yylloc.first_line = yylineno;
|
||||||
DPRINT("/BYTESTRING\n");
|
DPRINT("/BYTESTRING\n");
|
||||||
BEGIN(INITIAL);
|
BEGIN_DEFAULT();
|
||||||
return ']';
|
return ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +171,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
|
||||||
yylloc.first_line = yylineno;
|
yylloc.first_line = yylineno;
|
||||||
DPRINT("PropNodeName: %s\n", yytext);
|
DPRINT("PropNodeName: %s\n", yytext);
|
||||||
yylval.propnodename = strdup(yytext);
|
yylval.propnodename = strdup(yytext);
|
||||||
BEGIN(INITIAL);
|
BEGIN_DEFAULT();
|
||||||
return DT_PROPNODENAME;
|
return DT_PROPNODENAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
38
dtc-parser.y
38
dtc-parser.y
|
@ -48,9 +48,11 @@ extern struct boot_info *the_boot_info;
|
||||||
struct reserve_info *re;
|
struct reserve_info *re;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%token DT_V1
|
||||||
%token DT_MEMRESERVE
|
%token DT_MEMRESERVE
|
||||||
%token <propnodename> DT_PROPNODENAME
|
%token <propnodename> DT_PROPNODENAME
|
||||||
%token <literal> DT_LITERAL
|
%token <literal> DT_LITERAL
|
||||||
|
%token <literal> DT_LEGACYLITERAL
|
||||||
%token <cbase> DT_BASE
|
%token <cbase> DT_BASE
|
||||||
%token <byte> DT_BYTE
|
%token <byte> DT_BYTE
|
||||||
%token <data> DT_STRING
|
%token <data> DT_STRING
|
||||||
|
@ -61,6 +63,8 @@ extern struct boot_info *the_boot_info;
|
||||||
%type <data> propdataprefix
|
%type <data> propdataprefix
|
||||||
%type <re> memreserve
|
%type <re> memreserve
|
||||||
%type <re> memreserves
|
%type <re> memreserves
|
||||||
|
%type <re> v0_memreserve
|
||||||
|
%type <re> v0_memreserves
|
||||||
%type <addr> addr
|
%type <addr> addr
|
||||||
%type <data> celllist
|
%type <data> celllist
|
||||||
%type <cbase> cellbase
|
%type <cbase> cellbase
|
||||||
|
@ -78,7 +82,11 @@ extern struct boot_info *the_boot_info;
|
||||||
%%
|
%%
|
||||||
|
|
||||||
sourcefile:
|
sourcefile:
|
||||||
memreserves devicetree
|
DT_V1 ';' memreserves devicetree
|
||||||
|
{
|
||||||
|
the_boot_info = build_boot_info($3, $4);
|
||||||
|
}
|
||||||
|
| v0_memreserves devicetree
|
||||||
{
|
{
|
||||||
the_boot_info = build_boot_info($1, $2);
|
the_boot_info = build_boot_info($1, $2);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +108,24 @@ memreserve:
|
||||||
{
|
{
|
||||||
$$ = build_reserve_entry($3, $4, $1);
|
$$ = build_reserve_entry($3, $4, $1);
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
v0_memreserves:
|
||||||
|
/* empty */
|
||||||
|
{
|
||||||
|
$$ = NULL;
|
||||||
|
}
|
||||||
|
| v0_memreserve v0_memreserves
|
||||||
|
{
|
||||||
|
$$ = chain_reserve_entry($1, $2);
|
||||||
|
};
|
||||||
|
;
|
||||||
|
|
||||||
|
v0_memreserve:
|
||||||
|
memreserve
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
| label DT_MEMRESERVE addr '-' addr ';'
|
| label DT_MEMRESERVE addr '-' addr ';'
|
||||||
{
|
{
|
||||||
$$ = build_reserve_entry($3, $5 - $3 + 1, $1);
|
$$ = build_reserve_entry($3, $5 - $3 + 1, $1);
|
||||||
|
@ -108,6 +134,10 @@ memreserve:
|
||||||
|
|
||||||
addr:
|
addr:
|
||||||
DT_LITERAL
|
DT_LITERAL
|
||||||
|
{
|
||||||
|
$$ = eval_literal($1, 0, 64);
|
||||||
|
}
|
||||||
|
| DT_LEGACYLITERAL
|
||||||
{
|
{
|
||||||
$$ = eval_literal($1, 16, 64);
|
$$ = eval_literal($1, 16, 64);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +241,11 @@ cellbase:
|
||||||
;
|
;
|
||||||
|
|
||||||
cellval:
|
cellval:
|
||||||
cellbase DT_LITERAL
|
DT_LITERAL
|
||||||
|
{
|
||||||
|
$$ = eval_literal($1, 0, 32);
|
||||||
|
}
|
||||||
|
| cellbase DT_LEGACYLITERAL
|
||||||
{
|
{
|
||||||
$$ = eval_literal($2, $1, 32);
|
$$ = eval_literal($2, $1, 32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,10 @@ dtc_tests () {
|
||||||
tree1_tests_rw dtc_tree1.test.dtb
|
tree1_tests_rw dtc_tree1.test.dtb
|
||||||
run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb
|
run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb
|
||||||
|
|
||||||
|
run_test dtc.sh -I dts -O dtb -o dtc_tree1_dts0.test.dtb test_tree1_dts0.dts
|
||||||
|
tree1_tests dtc_tree1_dts0.test.dtb
|
||||||
|
tree1_tests_rw dtc_tree1_dts0.test.dtb
|
||||||
|
|
||||||
run_test dtc.sh -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
run_test dtc.sh -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
||||||
run_test string_escapes dtc_escapes.test.dtb
|
run_test string_escapes dtc_escapes.test.dtb
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
/memreserve/ deadbeef00000000-deadbeef000fffff;
|
/dts-v1/;
|
||||||
/memreserve/ 75bcd15 1000;
|
|
||||||
|
/memreserve/ 0xdeadbeef00000000 0x100000;
|
||||||
|
/memreserve/ 123456789 010000;
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
compatible = "test_tree1";
|
compatible = "test_tree1";
|
||||||
prop-int = <deadbeef>;
|
prop-int = <0xdeadbeef>;
|
||||||
prop-str = "hello world";
|
prop-str = "hello world";
|
||||||
|
|
||||||
subnode@1 {
|
subnode@1 {
|
||||||
|
@ -12,16 +14,16 @@
|
||||||
|
|
||||||
subsubnode {
|
subsubnode {
|
||||||
compatible = "subsubnode1", "subsubnode";
|
compatible = "subsubnode1", "subsubnode";
|
||||||
prop-int = <h# deadbeef>;
|
prop-int = <0xdeadbeef>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
subnode@2 {
|
subnode@2 {
|
||||||
prop-int = <d# 123456789>;
|
prop-int = <123456789>;
|
||||||
|
|
||||||
subsubnode@0 {
|
subsubnode@0 {
|
||||||
compatible = "subsubnode2", "subsubnode";
|
compatible = "subsubnode2", "subsubnode";
|
||||||
prop-int = <o# 0726746425>;
|
prop-int = <0726746425>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
27
tests/test_tree1_dts0.dts
Normal file
27
tests/test_tree1_dts0.dts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/memreserve/ deadbeef00000000-deadbeef000fffff;
|
||||||
|
/memreserve/ 75bcd15 1000;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
compatible = "test_tree1";
|
||||||
|
prop-int = <deadbeef>;
|
||||||
|
prop-str = "hello world";
|
||||||
|
|
||||||
|
subnode@1 {
|
||||||
|
compatible = "subnode1";
|
||||||
|
prop-int = [deadbeef];
|
||||||
|
|
||||||
|
subsubnode {
|
||||||
|
compatible = "subsubnode1", "subsubnode";
|
||||||
|
prop-int = <h# deadbeef>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
subnode@2 {
|
||||||
|
prop-int = <d# 123456789>;
|
||||||
|
|
||||||
|
subsubnode@0 {
|
||||||
|
compatible = "subsubnode2", "subsubnode";
|
||||||
|
prop-int = <o# 0726746425>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue