Variable sized cell support
cover Variable sized cell support
This patch set adds, tests, and documents support for variable sized cells in cell arrays. The new syntax is:
property = /size/ [8|16|32|64] <0x00 .... 0x12>;
So cell arrays of 8, 16, 32, or 64-bits can now be created. No padding is done on the resulting cell array. So if three 8-bit cells are specified the resulting property will contain three bytes.
This patch set assumes that the character literals in cell lists patch has already been applied to your tree as it uses them in it's test case and the diff will not apply cleanly to TOT without the character literals patch because both patch sets modify the same locations in the parser. You do not need to apply the character literal support in bytestrings patch however.
Anton Staaf (3):
libfdt: Add fdt16_to_cpu utility function
dtc: Add data_append_literal function
dtc: Add support for variable sized cells
Documentation/dts-format.txt | 18 +++++++- data.c | 33 ++++++++++++++++ dtc-lexer.l | 6 +++ dtc-parser.y | 59 +++++++++++++++++++---------- dtc.h | 5 ++ libfdt/libfdt_env.h | 6 +++ tests/.gitignore | 1 + tests/Makefile.tests | 1 + tests/run_tests.sh | 3 + tests/sized_cells.c | 84 ++++++++++++++++++++++++++++++++++++++++++ tests/sized_cells.dts | 11 +++++ tests/testdata.h | 2 + 12 files changed, 205 insertions(+), 24 deletions(-) create mode 100644 tests/sized_cells.c create mode 100644 tests/sized_cells.dts
Signature · 1 line
1.7.3.1
PATCH 1/3 libfdt: Add fdt16_to_cpu utility function
In reply to a message not in the archiveThis utility routine will be used in the variable size cell literal append code. It is a straightforward adaptation of the fdt32_to_cpu function.
--- libfdt/libfdt_env.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
libfdt/libfdt_env.h +6 -0
@@ -6,6 +6,12 @@#include <string.h> #define _B (n) ((unsigned long long)((uint8_t *)&x)[n]) +static inline uint16_t fdt16_to_cpu (uint16_t x) +{ +return (_B (0 ) <<8 ) |_B (1 ); +} +#define cpu_to_fdt16 (x) fdt16_to_cpu(x) +static inline uint32_t fdt32_to_cpu (uint32_t x) {return (_B (0 ) <<24 ) | (_B (1 ) <<16 ) | (_B (2 ) <<8 ) |_B (3 );
Signature · 1 line
1.7.3.1
PATCH 2/3 dtc: Add data_append_literal function
In reply to a message not in the archiveThis function deals with appending literals of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given literal is not larger than the specified size.
--- data.c | 33 +++++++++++++++++++++++++++++++++ dtc.h | 1 + 2 files changed, 34 insertions(+), 0 deletions(-)
data.c +33 -0
@@ -175,6 +175,39 @@ struct data data_append_cell(struct data d, cell_t word)return data_append_data (d, &beword,sizeof (beword)); } +struct data data_append_literal (struct data d,uint64_t value,int len) +{ +uint8_t value_8; +uint16_t be_value_16; +uint32_t be_value_32; +uint64_t be_value_64; + +if ((len <64 ) && (value >= (1ULL << len))) +die ("Literal value 0x%x too large to fit in %d-bit cell\n" , + value, len); + +switch (len) { +case 8 : + value_8 = value; +return data_append_data (d, &value_8,1 ); + +case 16 : + be_value_16 =cpu_to_fdt16 (value); +return data_append_data (d, &be_value_16,2 ); + +case 32 : + be_value_32 =cpu_to_fdt32 (value); +return data_append_data (d, &be_value_32,4 ); + +case 64 : + be_value_64 =cpu_to_fdt64 (value); +return data_append_data (d, &be_value_64,8 ); + +default : +die ("Invalid literal size (%d)\n" , len); + } +} +struct data data_append_re (struct data d,const struct fdt_reserve_entry *re) {struct fdt_reserve_entry bere;
dtc.h +1 -0
@@ -109,6 +109,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m, const void *p, int len);struct data data_merge (struct data d1,struct data d2);struct data data_append_cell (struct data d,cell_t word); +struct data data_append_literal (struct data d,uint64_t word,int len);struct data data_append_re (struct data d,const struct fdt_reserve_entry *re);struct data data_append_addr (struct data d,uint64_t addr);struct data data_append_byte (struct data d,uint8_t byte);
Signature · 1 line
1.7.3.1
PATCH 3/3 dtc: Add support for variable sized cells
In reply to a message not in the archiveCells of size 8, 16, 32, and 64 bits are supported. The new /size/ syntax was selected so as to not pollute the reserved keyword space with uint8/uint16/... type names.
With this patch the following property assignment:
property = /size/ 16 <0x1234 0x5678 0x0 0xffff>;
is equivalent to:
property = <0x12345678 0x0000ffff>;
It is now also possible to directly specify a 64 bit literal in a cell list using:
property = /size/ 64 <0xdeadbeef00000000>;
It is an error to attempt to store a literal into a cell that is too small to hold the literal, and the compiler will generate an error when it detects this. For instance:
property = /size/ 8 <256>;
Will fail to compile. It is also an error to attempt to place a reference in a non 32-bit cell.
The sized_cells test tests the creation and access of 8, 16, 32, and 64-bit sized cells. It also tests that the creation of two properties, one with 16 bit cells and one with 32 bit cells result in the same property contents.
--- Documentation/dts-format.txt | 18 +++++++- dtc-lexer.l | 6 +++ dtc-parser.y | 59 +++++++++++++++++++---------- dtc.h | 4 ++ tests/.gitignore | 1 + tests/Makefile.tests | 1 + tests/run_tests.sh | 3 + tests/sized_cells.c | 84 ++++++++++++++++++++++++++++++++++++++++++ tests/sized_cells.dts | 11 +++++ tests/testdata.h | 2 + 10 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 tests/sized_cells.c create mode 100644 tests/sized_cells.dts
Documentation/dts-format.txt +15 -3
@@ -29,18 +29,27 @@ except for properties with empty (zero length) value which have the form: [label:] property-name; -Property values may be defined as an array of 32-bit integer cells, as -NUL-terminated strings, as bytestrings or a combination of these. +Property values may be defined as an array of 8, 16, 32, or 64-bit integer +cells, as NUL-terminated strings, as bytestrings or a combination of these. * Arrays of cells are represented by angle brackets surrounding a space separated list of C-style integers or character literals. + Cells default to 32-bits in size. e.g. interrupts = <17 0xc>; -* A 64-bit value is represented with two 32-bit cells. +* A 64-bit value can be represented with two 32-bit cells. e.g. clock-frequency = <0x00000001 0x00000000>; +* The storage size of a cell can be changed using the /size/ prefix. The + /size/ prefix allows for the creation of 8, 16, 32, and 64-bit cells. + The resulting cell array will not be padded to a multiple of the default + 32-bit cell size. + + e.g. interrupts = /size/ 8 <17 0xc>; + e.g. clock-frequenct = /size/ 64 <0x0000000100000000>; + * A NUL-terminated string value is represented using double quotes (the property value is considered to include the terminating NUL character).
@@ -65,6 +74,8 @@ NUL-terminated strings, as bytestrings or a combination of these. e.g. interrupt-parent = < &mpic >; or they may be '&' followed by a node's full path in braces: e.g. interrupt-parent = < &{/soc/interrupt-controller@40000} >; + References are only permitted in cell arrays that have a cell size of + 32-bits. * Outside a cell array, a reference to another node will be expanded to that node's full path.
@@ -109,3 +120,4 @@ Version 1 DTS files have the overall layout: -- David Gibson <[email protected]> -- Yoder Stuart <[email protected]> + -- Anton Staaf <[email protected]>
dtc-lexer.l +6 -0
@@ -97,6 +97,12 @@ static int pop_input_file(void); return DT_MEMRESERVE; } +<*>"/size/" { + DPRINT("Keyword: /size/\n"); + BEGIN_DEFAULT(); + return DT_SIZE; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref = xstrdup(yytext);
dtc-parser.y +38 -21
103 lines not on this page · raw message
dtc.h +4 -0
@@ -87,6 +87,10 @@ struct data {struct marker *markers; }; +struct sized_data { +struct data data; +int size; +}; #define empty_data ((struct data){ /* all .members = 0 or NULL */ })
tests/.gitignore +1 -0
@@ -40,6 +40,7 @@ /set_name /setprop /setprop_inplace +/sized_cells /string_escapes /subnode_offset /supernode_atdepth_offset
tests/Makefile.tests +1 -0
@@ -6,6 +6,7 @@ LIB_TESTS_L = get_mem_rsv \ node_check_compatible node_offset_by_compatible \ get_alias \ char_literal \ + sized_cells \ notfound \ setprop_inplace nop_property nop_node \ sw_tree1 \
tests/run_tests.sh +3 -0
@@ -209,6 +209,9 @@ dtc_tests () { run_dtc_test -I dts -O dtb -o dtc_char_literal.test.dtb char_literal.dts run_test char_literal dtc_char_literal.test.dtb + run_dtc_test -I dts -O dtb -o dtc_sized_cells.test.dtb sized_cells.dts + run_test sized_cells dtc_sized_cells.test.dtb + run_dtc_test -I dts -O dtb -o dtc_extra-terminating-null.test.dtb extra-terminating-null.dts run_test extra-terminating-null dtc_extra-terminating-null.test.dtb
tests/sized_cells.c new file +84 -0
84 lines not on this page · raw message
tests/sized_cells.dts new file +11 -0
@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + cells-8b = /size/ 8 <'\r' 'b' '\0' '\'' '\xff' 0xde>; + cells-16b = /size/ 16 <'\r' 'b' '\0' '\'' '\xff' 0xdead>; + cells-32b = /size/ 32 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef>; + cells-64b = /size/ 64 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef00000000>; + + cells-one-16 = /size/ 16 <0x1234 0x5678 0x0 0xffff>; + cells-one-32 = <0x12345678 0x0000ffff>; +};
tests/testdata.h +2 -0
@@ -11,6 +11,8 @@#define TEST_VALUE_1 0xdeadbeef#define TEST_VALUE_2 123456789 +#define TEST_VALUE_3 0xde +#define TEST_VALUE_4 0xdead#define PHANDLE_1 0x2000#define PHANDLE_2 0x2001
Signature · 1 line
1.7.3.1
David Gibson
Acked-byRe: [PATCH 1/3] libfdt: Add fdt16_to_cpu utility function
In reply to a message not in the archiveQuoted 5 lines · Anton Staaf
This utility routine will be used in the variable size cell literal append code. It is a straightforward adaptation of the
fdt32_to_cpufunction.Signed-off-by Anton Staaf <[email protected]>
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 9 lines · Anton Staaf
This patch set adds, tests, and documents support for variable sized cells in cell arrays. The new syntax is:
property = /size/ [8|16|32|64] <0x00 .... 0x12>;So cell arrays of 8, 16, 32, or 64-bits can now be created. No padding is done on the resulting cell array. So if three 8-bit cells are specified the resulting property will contain three bytes.
Quoted 5 lines
This patch set assumes that the character literals in cell lists patch has already been applied to your tree as it uses them in it's test case and the diff will not apply cleanly to TOT without the character literals patch because both patch sets modify the same locations in the parser. You do not need to apply the character literal support in bytestrings patch however.
Nice.
Still wants a little polish, I think. And some time to sit around in case we have a better idea on the syntax, but a very good start.
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
Re: [PATCH 2/3] dtc: Add data_append_literal function
In reply to a message not in the archiveQuoted 19 lines · Anton Staaf
This function deals with appending literals of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given literal is not larger than the specified size.
Signed-off-by Anton Staaf <[email protected]>Cc David Gibson <[email protected]>Cc Jon Loeliger <jdl-CYoMK+44s/[email protected]>Cc Grant Likely <grant.likely-s3s/[email protected]>--- data.c | 33 +++++++++++++++++++++++++++++++++ dtc.h | 1 + 2 files changed, 34 insertions(+), 0 deletions(-)data.c +0
-0
data.c struct data data_append_cell(struct data d, cell_t word) · line 178
Quoted 4 lines
data.c +1
-0@@ -175,6 +175,39 @@ struct data data_append_cell(struct data d, cell_t word)return data_append_data (d, &beword,sizeof (beword)); } +struct data data_append_literal (struct data d,uint64_t value,int len)
I'd prefer to call this data_append_integer() since there are string and character literals too. Plus by the time we get to the struct data level, it's not really relevant any more that this came from a literal in the parser.
And perhaps call it 'bits' or 'size' rather than 'len'. 'len' to me suggests a byte size rather than a bit size.
data.c struct data data_append_cell(struct data d, cell_t word) · line 183
Quoted 5 lines
data.c +5
-0+{ +uint8_t value_8; +uint16_t be_value_16; +uint32_t be_value_32; +uint64_t be_value_64;
I'd remove the 'be_', it doesn't really add anything of value. Plus I've mostly avoided explicit references to BE (hence fdtXX_to_cpu() on the off chance that someone one day is stupid enough to use an LE variant of the fdt format.
data.c struct data data_append_cell(struct data d, cell_t word) · line 187
Quoted 4 lines
data.c +4
-0+ +if ((len <64 ) && (value >= (1ULL << len))) +die ("Literal value 0x%x too large to fit in %d-bit cell\n" , + value, len);
This really shouldn't be a die(). In general bad input should not directly trigger a die() during parse - it should give an error but continue parse as best it can and only drop out afterwards.
In this case, I think the semantics of an overflow are clear enough that it shouldn't even be an error per se. Just print a warning, and mask the number down to the relevant size.
Quoted 10 lines
data.c +10
-0+ +switch (len) { +case 8 : + value_8 = value; +return data_append_data (d, &value_8,1 ); + +case 16 : + be_value_16 =cpu_to_fdt16 (value); +return data_append_data (d, &be_value_16,2 ); +
data.c struct data data_append_cell(struct data d, cell_t word) · line 207
Quoted 10 lines
data.c +10
-0+case 32 : + be_value_32 =cpu_to_fdt32 (value); +return data_append_data (d, &be_value_32,4 ); + +case 64 : + be_value_64 =cpu_to_fdt64 (value); +return data_append_data (d, &be_value_64,8 ); + +default : +die ("Invalid literal size (%d)\n" , len);
This on the other hand is fine to be a die(), since it's essentially an assertion that should only be triggered by bad code elsewhere in dtc itself, not by bad input.
Quoted 18 lines
data.c +3
-0+ } +} +struct data data_append_re (struct data d,const struct fdt_reserve_entry *re) {struct fdt_reserve_entry bere;dtc.h +1
-0@@ -109,6 +109,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m, const void *p, int len);struct data data_merge (struct data d1,struct data d2);struct data data_append_cell (struct data d,cell_t word); +struct data data_append_literal (struct data d,uint64_t word,int len);struct data data_append_re (struct data d,const struct fdt_reserve_entry *re);struct data data_append_addr (struct data d,uint64_t addr);struct data data_append_byte (struct data d,uint8_t byte);
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
Re: [PATCH 3/3] dtc: Add support for variable sized cells
In reply to a message not in the archiveQuoted 7 lines · Anton Staaf
Cells of size 8, 16, 32, and 64 bits are supported. The new /size/ syntax was selected so as to not pollute the reserved keyword space with uint8/uint16/... type names.
With this patch the following property assignment:
property = /size/ 16 <0x1234 0x5678 0x0 0xffff>;
I'm now thinking that just plain "/size/" is maybe a bit too generic for this keyword. But I'm not sure what would be better. Maybe /cellsize/ or /intsize/ or /arraysize/.
Quoted 143 lines
is equivalent to:
property = <0x12345678 0x0000ffff>;It is now also possible to directly specify a 64 bit literal in a cell list using:
property = /size/ 64 <0xdeadbeef00000000>;It is an error to attempt to store a literal into a cell that is too small to hold the literal, and the compiler will generate an error when it detects this. For instance:
property = /size/ 8 <256>;Will fail to compile. It is also an error to attempt to place a reference in a non 32-bit cell.
The
sized_cellstest tests the creation and access of 8, 16, 32, and 64-bit sized cells. It also tests that the creation of two properties, one with 16 bit cells and one with 32 bit cells result in the same property contents.Signed-off-by Anton Staaf <[email protected]>Cc Jon Loeliger <jdl-CYoMK+44s/[email protected]>Cc David Gibson <[email protected]>Cc Grant Likely <grant.likely-s3s/[email protected]>--- Documentation/dts-format.txt | 18 +++++++- dtc-lexer.l | 6 +++ dtc-parser.y | 59 +++++++++++++++++++---------- dtc.h | 4 ++ tests/.gitignore | 1 + tests/Makefile.tests | 1 + tests/run_tests.sh | 3 + tests/sized_cells.c | 84 ++++++++++++++++++++++++++++++++++++++++++ tests/sized_cells.dts | 11 +++++ tests/testdata.h | 2 + 10 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 tests/sized_cells.c create mode 100644 tests/sized_cells.dtsDocumentation/dts-format.txt +15
-3@@ -29,18 +29,27 @@ except for properties with empty (zero length) value which have the form: [label:] property-name; -Property values may be defined as an array of 32-bit integer cells, as -NUL-terminated strings, as bytestrings or a combination of these. +Property values may be defined as an array of 8, 16, 32, or 64-bit integer +cells, as NUL-terminated strings, as bytestrings or a combination of these. * Arrays of cells are represented by angle brackets surrounding a space separated list of C-style integers or character literals. + Cells default to 32-bits in size. e.g. interrupts = <17 0xc>; -* A 64-bit value is represented with two 32-bit cells. +* A 64-bit value can be represented with two 32-bit cells. e.g. clock-frequency = <0x00000001 0x00000000>; +* The storage size of a cell can be changed using the /size/ prefix. The + /size/ prefix allows for the creation of 8, 16, 32, and 64-bit cells. + The resulting cell array will not be padded to a multiple of the default + 32-bit cell size. + + e.g. interrupts = /size/ 8 <17 0xc>; + e.g. clock-frequenct = /size/ 64 <0x0000000100000000>; + * A NUL-terminated string value is represented using double quotes (the property value is considered to include the terminating NUL character).@@ -65,6 +74,8 @@ NUL-terminated strings, as bytestrings or a combination of these. e.g. interrupt-parent = < &mpic >; or they may be '&' followed by a node's full path in braces: e.g. interrupt-parent = < &{/soc/interrupt-controller@40000} >; + References are only permitted in cell arrays that have a cell size of + 32-bits. * Outside a cell array, a reference to another node will be expanded to that node's full path.@@ -109,3 +120,4 @@ Version 1 DTS files have the overall layout: -- David Gibson <[email protected]> -- Yoder Stuart <[email protected]> + -- Anton Staaf <[email protected]>dtc-lexer.l +6
-0@@ -97,6 +97,12 @@ static int pop_input_file(void); return DT_MEMRESERVE; } +<*>"/size/" { + DPRINT("Keyword: /size/\n"); + BEGIN_DEFAULT(); + return DT_SIZE; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref = xstrdup(yytext);dtc-parser.y +3
-3@@ -44,9 +44,9 @@ static unsigned char eval_char_literal(const char *s); unsigned int cbase; uint8_t byte; struct data data; + struct sized_data sized_data; uint64_t addr; - cell_t cell; struct property *prop; struct property *proplist; struct node *node;@@ -56,6 +56,7 @@ static unsigned char eval_char_literal(const char *s); %token DT_V1 %token DT_MEMRESERVE +%token DT_SIZE %token <propnodename> DT_PROPNODENAME %token <literal> DT_LITERAL %token <literal> DT_CHAR_LITERAL@@ -71,8 +72,7 @@ static unsigned char eval_char_literal(const char *s); %type <re> memreserve %type <re> memreserves %type <addr> addr -%type <data> celllist -%type <cell> cellval +%type <sized_data> celllist %type <data> bytestring %type <prop> propdef %type <proplist> proplist
dtc-parser.y propdata: · line 185
Quoted 5 lines
dtc-parser.y +1
-1@@ -182,9 +182,9 @@ propdata: { $$ = data_merge($1, $2); } - | propdataprefix '<' celllist '>' + | propdataprefix celllist '>'
I'd rename celllist to cellistprefix or something, or this looks decidedly odd.
Quoted 54 lines
dtc-parser.y +24
-14{ - $$ = data_merge($1, $3); + $$ = data_merge($1, $2.data); } | propdataprefix '[' bytestring ']' {@@ -243,33 +243,50 @@ propdataprefix: ; celllist: - /* empty */ + DT_SIZE DT_LITERAL '<' { - $$ = empty_data; + $$.data = empty_data; + $$.size = eval_literal($2, 0, 7); + + if (($$.size != 8) && + ($$.size != 16) && + ($$.size != 32) && + ($$.size != 64)) + { + print_error("Only 8, 16, 32 and 64-bit cell" + " sizes are currently supported"); + $$.size = 32; + } } - | celllist cellval + | '<' { - $$ = data_append_cell($1, $2); + $$.data = empty_data; + $$.size = 32; } - | celllist DT_REF + | celllist DT_LITERAL { - $$ = data_append_cell(data_add_marker($1, REF_PHANDLE, - $2), -1); + uint64_t val = eval_literal($2, 0, $1.size); + + $$.data = data_append_literal($1.data, val, $1.size); } - | celllist DT_LABEL + | celllist DT_CHAR_LITERAL { - $$ = data_add_marker($1, LABEL, $2); - } - ; + uint64_t val = eval_char_literal($2); -cellval: - DT_LITERAL + $$.data = data_append_literal($1.data, val, $1.size);
dtc-parser.y propdataprefix: · line 285
Quoted 10 lines
dtc-parser.y +8
-1+ } + | celllist DT_REF { - $$ = eval_literal($1, 0, 32); + if ($1.size != 32) + print_error("References only allowed in 32-bit" + " cell lists"); + + $$.data = data_add_marker($1.data, REF_PHANDLE, $2); + $$.data = data_append_cell($$.data, -1);
Ouch, this is kind of nasty. If you get a REF in a celllist of the wrong size, you print an error, but then insert the ref as a 32-bit quantity, regardless of the actual cell size. While you can argue that correct behaviour is undefined in this error case, I think this is a fair way from least-surprise.
I'd suggest instead that in the error case, you insert either a 0 or -1 of the correct cell size instead of the reference.
Quoted 14 lines
dtc-parser.y +2
-2} - | DT_CHAR_LITERAL + | celllist DT_LABEL { - $$ = eval_char_literal($1); + $$.data = data_add_marker($1.data, LABEL, $2); } ;dtc.h +0
-0
dtc.h struct data { · line 93
Quoted 7 lines
dtc.h +4
-0@@ -87,6 +87,10 @@ struct data {struct marker *markers; }; +struct sized_data { +struct data data; +int size; +};
This is only used internal to the parser, so the definition can just go in dtc-parser.y. And maybe call it cellarray or something more specific to its usage. "sized_data" suggests it holds the size of the whole of the data, which doesn't make sense, since a struct data does that already.
Quoted 152 lines
dtc.h +0
-0#define empty_data ((struct data){ /* all .members = 0 or NULL */ })tests/.gitignore +1
-0@@ -40,6 +40,7 @@ /set_name /setprop /setprop_inplace +/sized_cells /string_escapes /subnode_offset /supernode_atdepth_offsettests/Makefile.tests +1
-0@@ -6,6 +6,7 @@ LIB_TESTS_L = get_mem_rsv \ node_check_compatible node_offset_by_compatible \ get_alias \ char_literal \ + sized_cells \ notfound \ setprop_inplace nop_property nop_node \ sw_tree1 \tests/run_tests.sh +3
-0@@ -209,6 +209,9 @@ dtc_tests () { run_dtc_test -I dts -O dtb -o dtc_char_literal.test.dtb char_literal.dts run_test char_literal dtc_char_literal.test.dtb + run_dtc_test -I dts -O dtb -o dtc_sized_cells.test.dtb sized_cells.dts + run_test sized_cells dtc_sized_cells.test.dtb + run_dtc_test -I dts -O dtb -o dtc_extra-terminating-null.test.dtb extra-terminating-null.dts run_test extra-terminating-null dtc_extra-terminating-null.test.dtbtests/sized_cells.c new file +84
-0@@ -0,0 +1,84 @@ +/* +* libfdt - Flat Device Tree manipulation +* Testcase for variable sized cells in dtc +* Copyright (C) 2006 David Gibson, IBM Corporation. +* Copyright (C) 2011 The Chromium Authors. All rights reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdint.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +static void check_compare_properties (void *fdt, +char const *name_one, +char const *name_two) +{ +const void *propval; +int proplen; + + propval =fdt_getprop (fdt,0 , name_one, &proplen); + +if (!propval) +FAIL ("fdt_getprop(\"%s\"): %s" , + name_one, +fdt_strerror (proplen)); + +check_getprop (fdt,0 , name_two, proplen, propval); +} + +int main (int argc,char *argv[]) +{ +void *fdt; +uint8_t expected_8[6 ] = {TEST_CHAR1 , +TEST_CHAR2 , +TEST_CHAR3 , +TEST_CHAR4 , +TEST_CHAR5 , +TEST_VALUE_3 }; +uint16_t expected_16[6 ]; +uint32_t expected_32[6 ]; +uint64_t expected_64[6 ]; +int i; + +for (i =0 ; i <5 ; ++i) { + expected_16[i] =cpu_to_fdt16 (expected_8[i]); + expected_32[i] =cpu_to_fdt32 (expected_8[i]); + expected_64[i] =cpu_to_fdt64 (expected_8[i]); + } + + expected_16[5 ] =cpu_to_fdt16 (TEST_VALUE_4 ); + expected_32[5 ] =cpu_to_fdt32 (TEST_VALUE_1 ); + expected_64[5 ] =cpu_to_fdt64 (TEST_ADDR_1 ); + +test_init (argc, argv); + fdt =load_blob_arg (argc, argv); + +check_getprop (fdt,0 ,"cells-8b" ,sizeof (expected_8), expected_8); +check_getprop (fdt,0 ,"cells-16b" ,sizeof (expected_16), expected_16); +check_getprop (fdt,0 ,"cells-32b" ,sizeof (expected_32), expected_32); +check_getprop (fdt,0 ,"cells-64b" ,sizeof (expected_64), expected_64); + +check_compare_properties (fdt,"cells-one-16" ,"cells-one-32" ); + +PASS (); +}tests/sized_cells.dts new file +11
-0@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + cells-8b = /size/ 8 <'\r' 'b' '\0' '\'' '\xff' 0xde>; + cells-16b = /size/ 16 <'\r' 'b' '\0' '\'' '\xff' 0xdead>; + cells-32b = /size/ 32 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef>; + cells-64b = /size/ 64 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef00000000>; + + cells-one-16 = /size/ 16 <0x1234 0x5678 0x0 0xffff>; + cells-one-32 = <0x12345678 0x0000ffff>; +};tests/testdata.h +0
-0
tests/testdata.h line 15
Quoted 5 lines
tests/testdata.h +2
-0@@ -11,6 +11,8 @@#define TEST_VALUE_1 0xdeadbeef#define TEST_VALUE_2 123456789 +#define TEST_VALUE_3 0xde +#define TEST_VALUE_4 0xdead
I think it would be better to use masked versions of the existing constants, rather than defining new short ones.
Quoted 3 lines
tests/testdata.h +0
-0#define PHANDLE_1 0x2000#define PHANDLE_2 0x2001
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 10 lines · David Gibson
Quoted 9 lines · Anton Staaf
This patch set adds, tests, and documents support for variable sized cells in cell arrays. The new syntax is:
property = /size/ [8|16|32|64] <
0x00....0x12>;So cell arrays of 8, 16, 32, or 64-bits can now be created. No padding is done on the resulting cell array. So if three 8-bit cells are specified the resulting property will contain three bytes.
Quoted 7 lines
Quoted 5 lines
This patch set assumes that the character literals in cell lists patch has already been applied to your tree as it uses them in it's test case and the diff will not apply cleanly to TOT without the character literals patch because both patch sets modify the same locations in the parser. You do not need to apply the character literal support in bytestrings patch however.
Nice.
Thanks.
Quoted 2 lines
Still wants a little polish, I think. And some time to sit around in case we have a better idea on the syntax, but a very good start.
Yup, makes sense. I'll submit a v2 today that addresses your other comments.
-Anton
Quoted 6 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
Re: [PATCH 2/3] dtc: Add data_append_literal function
In reply to a message not in the archiveQuoted 23 lines · David Gibson
Quoted 22 lines · Anton Staaf
This function deals with appending literals of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given literal is not larger than the specified size.
Signed-off-by Anton Staaf <[email protected]>Cc David Gibson <[email protected]>Cc Jon Loeliger <jdl-CYoMK+44s/[email protected]>Cc Grant Likely <grant.likely-s3s/[email protected]>---
data.c | 33 +++++++++++++++++++++++++++++++++
dtc.h | 1 +2 files changed, 34 insertions(+), 0 deletions(-)data.c +0
-0@@ -175,6 +175,39 @@ struct data data_append_cell(struct data d, cell_t word) return data_append_data(d, &beword, sizeof(beword)); }
Quoted 6 lines
data.c struct data data_append_cell(struct data d, cell_t word) · line 178
Quoted 1 line
data.c +1
-0+struct data data_append_literal (struct data d,uint64_t value,int len)I'd prefer to call this
data_append_integer()since there are string and character literals too. Plus by the time we get to the struct data level, it's not really relevant any more that this came from a literal in the parser.
Done
Quoted 2 lines
And perhaps call it 'bits' or 'size' rather than 'len'. 'len' to me suggests a byte size rather than a bit size.
Done
Quoted 10 lines
data.c struct data data_append_cell(struct data d, cell_t word) · line 183
Quoted 5 lines
data.c +5
-0+{ + uint8_t value_8; + uint16_t be_value_16; + uint32_t be_value_32; + uint64_t be_value_64;I'd remove the '
be_', it doesn't really add anything of value. Plus I've mostly avoided explicit references to BE (hencefdtXX_to_cpu()on the off chance that someone one day is stupid enough to use an LE variant of the fdt format.
Done
Quoted 8 lines
data.c struct data data_append_cell(struct data d, cell_t word) · line 187
Quoted 4 lines
data.c +4
-0+ + if ((len < 64) && (value >= (1ULL << len))) + die("Literal value 0x%x too large to fit in %d-bit cell\n", + value, len);This really shouldn't be a
die(). In general bad input should not directly trigger adie()during parse - it should give an error but continue parse as best it can and only drop out afterwards.
Hmm, so this check should never happen when called from the parser because the parser uses eval_literal to read the cell values and that function also checks this.
Quoted 3 lines
In this case, I think the semantics of an overflow are clear enough that it shouldn't even be an error per se. Just print a warning, and mask the number down to the relevant size.
To do this I would have to duplicate the functionality of eval_literal, or add a flag that tells it to warn instead of error on overflow. Do you have a preference?
Quoted 17 lines
Quoted 17 lines
data.c +16
-0+ + switch (len) { + case 8: + value_8 = value; + return data_append_data(d, &value_8, 1); + + case 16: + be_value_16 = cpu_to_fdt16(value); + return data_append_data(d, &be_value_16, 2); + + case 32: + be_value_32 = cpu_to_fdt32(value); + return data_append_data(d, &be_value_32, 4); + + case 64: + be_value_64 = cpu_to_fdt64(value);
Quoted 8 lines
data.c struct data data_append_cell(struct data d, cell_t word) · line 207
Quoted 4 lines
data.c +4
-0+ return data_append_data(d, &be_value_64, 8); + + default: + die("Invalid literal size (%d)\n", len);This on the other hand is fine to be a
die(), since it's essentially an assertion that should only be triggered by bad code elsewhere in dtc itself, not by bad input.
Yup
Quoted 16 lines
Quoted 16 lines
data.c +3
-0+ } +} + struct data data_append_re(struct data d, const struct fdt_reserve_entry *re) { struct fdt_reserve_entry bere;dtc.h +1
-0@@ -109,6 +109,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m, const void *p, int len); struct data data_merge(struct data d1, struct data d2); struct data data_append_cell(struct data d, cell_t word); +struct data data_append_literal (struct data d,uint64_t word,int len); struct data data_append_re(struct data d, const struct fdt_reserve_entry *re);
Quoted 9 lines
dtc.h struct data data_insert_at_marker(struct data d, struct marker *m, · line 115
Quoted 2 lines
dtc.h +0
-0struct data data_append_addr(struct data d, uint64_t addr); struct data data_append_byte(struct data d, uint8_t byte);--
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
Thanks,
Anton
Re: [PATCH 3/3] dtc: Add support for variable sized cells
In reply to a message not in the archiveQuoted 5 lines · David Gibson
Quoted 4 lines · Anton Staaf
Cells of size 8, 16, 32, and 64 bits are supported. The new /size/ syntax was selected so as to not pollute the reserved keyword space with uint8/uint16/... type names.
Quoted 7 lines
Quoted 3 lines
With this patch the following property assignment:
property = /size/ 16 <
0x12340x56780x00xffff>;I'm now thinking that just plain "/size/" is maybe a bit too generic for this keyword. But I'm not sure what would be better. Maybe /cellsize/ or /intsize/ or /arraysize/.
Also /bits/ or /cellbits/ might make good choices because the size is in bits and not in bytes. I'm not fond of /arraysize/ because we are specifying the size of each element in the array, not the array itself.
Quoted 143 lines
Quoted 143 lines
is equivalent to:
property = <
0x123456780x0000ffff>;It is now also possible to directly specify a 64 bit literal in a cell list using:
property = /size/ 64 <
0xdeadbeef00000000>;It is an error to attempt to store a literal into a cell that is too small to hold the literal, and the compiler will generate an error when it detects this. For instance:
property = /size/ 8 <256>;
Will fail to compile. It is also an error to attempt to place a reference in a non 32-bit cell.
The
sized_cellstest tests the creation and access of 8, 16, 32, and 64-bit sized cells. It also tests that the creation of two properties, one with 16 bit cells and one with 32 bit cells result in the same property contents.Signed-off-by Anton Staaf <[email protected]>Cc Jon Loeliger <jdl-CYoMK+44s/[email protected]>Cc David Gibson <[email protected]>Cc Grant Likely <grant.likely-s3s/[email protected]>---
Documentation/dts-format.txt | 18 +++++++-
dtc-lexer.l | 6 +++
dtc-parser.y | 59 +++++++++++++++++++----------dtc.h| 4 ++
tests/.gitignore | 1 +
tests/Makefile.tests | 1 +
tests/run_tests.sh | 3 +
tests/sized_cells.c | 84 ++++++++++++++++++++++++++++++++++++++++++tests/sized_cells.dts| 11 +++++
tests/testdata.h | 2 +10 files changed, 165 insertions(+), 24 deletions(-)create mode 100644
tests/sized_cells.c
create mode 100644tests/sized_cells.dtsDocumentation/dts-format.txt +0
-0@@ -29,18 +29,27 @@ except for properties with empty (zero length) value which have theform:
[label:] property-name;Documentation/dts-format.txt +2
-2-Property values may be defined as an array of 32-bit integer cells, as -NUL-terminated strings, as bytestrings or a combination of these. +Property values may be defined as an array of 8, 16, 32, or 64-bit integer +cells, as NUL-terminated strings, as bytestrings or a combination of these.* Arrays of cells are represented by angle brackets surrounding a space separated list of C-style integers or character literals.
+ Cells default to 32-bits in size.e.g. interrupts = <17
0xc>;Documentation/dts-format.txt +1
-1-* A 64-bit value is represented with two 32-bit cells. +* A 64-bit value can be represented with two 32-bit cells.e.g. clock-frequency = <
0x000000010x00000000>;Documentation/dts-format.txt +8
-0+* The storage size of a cell can be changed using the /size/ prefix. The + /size/ prefix allows for the creation of 8, 16, 32, and 64-bit cells. + The resulting cell array will not be padded to a multiple of the default + 32-bit cell size. + + e.g. interrupts = /size/ 8 <17 0xc>; + e.g. clock-frequenct = /size/ 64 <0x0000000100000000>; +* A NUL-terminated string value is represented using double quotes (the property value is considered to include the terminating NUL character).
Documentation/dts-format.txt +0
-0@@ -65,6 +74,8 @@ NUL-terminated strings, as bytestrings or a combination of these. e.g. interrupt-parent = < &mpic >;or they may be '&' followed by a node's full path in braces:
e.g. interrupt-parent = < &{/soc/interrupt-controller@40000} >;
+ References are only permitted in cell arrays that have a cell size of
+ 32-bits.* Outside a cell array, a reference to another node will be expanded to that node's full path.
Documentation/dts-format.txt +0
-0@@ -109,3 +120,4 @@ Version 1 DTS files have the overall layout:-- David Gibson <[email protected]> -- Yoder Stuart <[email protected]>
+ -- Anton Staaf <[email protected]>dtc-lexer.l +6
-0@@ -97,6 +97,12 @@ static int pop_input_file(void); return DT_MEMRESERVE; } +<*>"/size/" { + DPRINT("Keyword: /size/\n"); + BEGIN_DEFAULT(); + return DT_SIZE; + } + <*>{LABEL}: { DPRINT("Label: %s\n", yytext); yylval.labelref = xstrdup(yytext);dtc-parser.y +1
-1@@ -44,9 +44,9 @@ static unsigned char eval_char_literal(const char *s); unsigned int cbase; uint8_t byte; struct data data; + struct sized_data sized_data; uint64_t addr; - cell_t cell; struct property *prop; struct property *proplist; struct node *node;@@ -56,6 +56,7 @@ static unsigned char eval_char_literal(const char *s);%token
DT_V1
%tokenDT_MEMRESERVE
+%tokenDT_SIZE
%token <propnodename>DT_PROPNODENAME
%token <literal>DT_LITERAL
%token <literal>DT_CHAR_LITERALdtc-parser.y +0
-0@@ -71,8 +72,7 @@ static unsigned char eval_char_literal(const char *s);%type <re> memreserve
%type <re> memreserves
%type <addr> addr
-%type <data> celllist
-%type <cell> cellval
+%type <sized_data> celllist
%type <data> bytestring
%type <prop> propdef
%type <proplist> proplistdtc-parser.y +0
-0@@ -182,9 +182,9 @@ propdata:
Quoted 8 lines
dtc-parser.y propdata: · line 185
Quoted 5 lines
dtc-parser.y +1
-1{ $$ = data_merge($1, $2); } - | propdataprefix '<' celllist '>' + | propdataprefix celllist '>'I'd rename celllist to cellistprefix or something, or this looks decidedly odd.
Done
Quoted 71 lines
Quoted 51 lines
dtc-parser.y +1
-1{ - $$ = data_merge($1, $3); + $$ = data_merge($1, $2.data); }| propdataprefix '[' bytestring ']'
{dtc-parser.y +0
-0@@ -243,33 +243,50 @@ propdataprefix: ;celllist:
- /* empty */
+DT_SIZEDT_LITERAL'<'
{
- $$ =empty_data;
+ $$.data =empty_data;
+ $$.size =eval_literal($2, 0, 7);
+
+ if (($$.size != 8) &&
+ ($$.size != 16) &&
+ ($$.size != 32) &&
+ ($$.size != 64))
+ {
+ print_error("Only 8, 16, 32 and 64-bit cell"
+ " sizes are currently supported");
+ $$.size = 32;
+ }
}
- | celllist cellval
+ | '<'
{
- $$ =data_append_cell($1, $2);
+ $$.data =empty_data;
+ $$.size = 32;
}
- | celllistDT_REF
+ | celllistDT_LITERAL
{
- $$ = data_append_cell(data_add_marker($1,REF_PHANDLE,
- $2), -1);
+uint64_tval =eval_literal($2, 0, $1.size); +
+ $$.data =data_append_literal($1.data, val, $1.size); }
- | celllistDT_LABEL
+ | celllistDT_CHAR_LITERAL
{
- $$ =data_add_marker($1, LABEL, $2);
- }
- ;
+uint64_tval =eval_char_literal($2);Quoted 13 lines
-cellval:
-DT_LITERAL
+ $$.data =data_append_literal($1.data, val, $1.size);
+ }
+ | celllistDT_REF
{
- $$ =eval_literal($1, 0, 32);
+ if ($1.size != 32)
+ print_error("References only allowed in 32-bit"
+ " cell lists");
+
+ $$.data =data_add_marker($1.data, REF_PHANDLE, $2);
+ $$.data =data_append_cell($$.data, -1);Ouch, this is kind of nasty. If you get a REF in a celllist of the wrong size, you print an error, but then insert the ref as a 32-bit quantity, regardless of the actual cell size. While you can argue that correct behaviour is undefined in this error case, I think this is a fair way from least-surprise.
Quoted 2 lines
I'd suggest instead that in the error case, you insert either a 0 or -1 of the correct cell size instead of the reference.
Done, I opted for 0xffffffffffffffff masked to the right size so the check in data_append_integer wouldn't fail out. And for consistency with the -1 that is stored in the normal 32-bit case.
Quoted 17 lines
Quoted 17 lines
}
- |DT_CHAR_LITERAL
+ | celllistDT_LABEL
{
- $$ =eval_char_literal($1);
+ $$.data =data_add_marker($1.data, LABEL, $2); }
;dtc.h +0
-0@@ -87,6 +87,10 @@ struct data { struct marker *markers; };
Quoted 10 lines
dtc.h struct data { · line 93
Quoted 4 lines
dtc.h +4
-0+struct sized_data { + struct data data; + int size; +};This is only used internal to the parser, so the definition can just go in dtc-parser.y. And maybe call it cellarray or something more specific to its usage. "sized_data" suggests it holds the size of the whole of the data, which doesn't make sense, since a struct data does that already.
Done, I didn't see a simple way to add the definition to the part of the generated header that comes before the definition of the union. So instead I added this as an anonymous struct directly in the union.
Quoted 162 lines
Quoted 152 lines
dtc.h +0
-0#define empty_data ((struct data){ /* all .members = 0 or NULL */ })tests/.gitignore +0
-0@@ -40,6 +40,7 @@/set_name
/setprop
/setprop_inplace
+/sized_cells
/string_escapes
/subnode_offset
/supernode_atdepth_offsettests/Makefile.tests +1
-0@@ -6,6 +6,7 @@ LIB_TESTS_L = get_mem_rsv \ node_check_compatible node_offset_by_compatible \ get_alias \ char_literal \ + sized_cells \ notfound \ setprop_inplace nop_property nop_node \ sw_tree1 \tests/run_tests.sh +0
-0@@ -209,6 +209,9 @@ dtc_tests () {run_dtc_test -I dts -O dtb -o dtc_char_literal.test.dtb
char_literal.dtsrun_testchar_literaldtc_char_literal.test.dtb+ run_dtc_test -I dts -O dtb -o dtc_sized_cells.test.dtb
sized_cells.dts
+ run_testsized_cellsdtc_sized_cells.test.dtb
+
run_dtc_test -I dts -O dtb -o dtc_extra-terminating-null.test.dtbextra-terminating-null.dtsrun_testextra-terminating-null dtc_extra-terminating-null.test.dtbtests/sized_cells.c new file +84
-0@@ -0,0 +1,84 @@ +/* +* libfdt - Flat Device Tree manipulation +* Testcase for variable sized cells in dtc +* Copyright (C) 2006 David Gibson, IBM Corporation. +* Copyright (C) 2011 The Chromium Authors. All rights reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public License +* as published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdint.h> + +#include <fdt.h> +#include <libfdt.h> + +#include "tests.h" +#include "testdata.h" + +static void check_compare_properties (void *fdt, + char const *name_one, + char const *name_two) +{ + const void *propval; + int proplen; + + propval = fdt_getprop(fdt, 0, name_one, &proplen); + + if (!propval) + FAIL("fdt_getprop(\"%s\"): %s", + name_one, + fdt_strerror(proplen)); + + check_getprop(fdt, 0, name_two, proplen, propval); +} + +int main (int argc,char *argv[]) +{ + void *fdt; + uint8_t expected_8[6] = {TEST_CHAR1, + TEST_CHAR2, + TEST_CHAR3, + TEST_CHAR4, + TEST_CHAR5, + TEST_VALUE_3}; + uint16_t expected_16[6]; + uint32_t expected_32[6]; + uint64_t expected_64[6]; + int i; + + for (i = 0; i < 5; ++i) { + expected_16[i] = cpu_to_fdt16(expected_8[i]); + expected_32[i] = cpu_to_fdt32(expected_8[i]); + expected_64[i] = cpu_to_fdt64(expected_8[i]); + } + + expected_16[5] = cpu_to_fdt16(TEST_VALUE_4); + expected_32[5] = cpu_to_fdt32(TEST_VALUE_1); + expected_64[5] = cpu_to_fdt64(TEST_ADDR_1); + + test_init(argc, argv); + fdt = load_blob_arg(argc, argv); + + check_getprop(fdt, 0, "cells-8b", sizeof(expected_8), expected_8); + check_getprop(fdt, 0, "cells-16b", sizeof(expected_16), expected_16); + check_getprop(fdt, 0, "cells-32b", sizeof(expected_32), expected_32); + check_getprop(fdt, 0, "cells-64b", sizeof(expected_64), expected_64); + + check_compare_properties(fdt, "cells-one-16", "cells-one-32"); + + PASS(); +}tests/sized_cells.dts new file +11
-0@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + cells-8b = /size/ 8 <'\r' 'b' '\0' '\'' '\xff' 0xde>; + cells-16b = /size/ 16 <'\r' 'b' '\0' '\'' '\xff' 0xdead>; + cells-32b = /size/ 32 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef>; + cells-64b = /size/ 64 <'\r' 'b' '\0' '\'' '\xff' 0xdeadbeef00000000>; + + cells-one-16 = /size/ 16 <0x1234 0x5678 0x0 0xffff>; + cells-one-32 = <0x12345678 0x0000ffff>; +};tests/testdata.h +0
-0tests/testdata.h line 15
Quoted 5 lines
tests/testdata.h +2
-0@@ -11,6 +11,8 @@ #define TEST_VALUE_1 0xdeadbeef #define TEST_VALUE_2 123456789 +#define TEST_VALUE_3 0xde +#define TEST_VALUE_4 0xdeadI think it would be better to use masked versions of the existing constants, rather than defining new short ones.
Quoted 1 line
Quoted 9 lines
Quoted 2 lines
#define
PHANDLE_10x2000
#definePHANDLE_20x2001--
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
Thanks,
Anton
Re: [PATCH 2/3] dtc: Add data_append_literal function
In reply to a message not in the archiveQuoted 3 lines · Anton Staaf
Quoted 1 line · David Gibson
On Wed, Sep 21, 2011 at 01:42:10PM -0700, Anton Staaf wrote:
[snip]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+
+ if ((len < 64) && (value >= (1ULL << len)))
+ die("Literal value 0x%x too large to fit in %d-bit cell\n",
+ value, len);
Quoted 7 lines
Quoted 3 lines
This really shouldn't be a
die(). In general bad input should not directly trigger adie()during parse - it should give an error but continue parse as best it can and only drop out afterwards.Hmm, so this check should never happen when called from the parser because the parser uses
eval_literalto read the cell values and that function also checks this.
Um.. it checks and prints an error, but it doesn't die() or otherwise stop you from reaching here AFAICT.
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
Re: [PATCH 3/3] dtc: Add support for variable sized cells
In reply to a message not in the archiveQuoted 9 lines · Anton Staaf
Quoted 7 lines · David Gibson
Quoted 6 lines · Anton Staaf
Cells of size 8, 16, 32, and 64 bits are supported. The new /size/ syntax was selected so as to not pollute the reserved keyword space with uint8/uint16/... type names.
With this patch the following property assignment:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
property = /size/ 16 <
0x12340x56780x00xffff>;I'm now thinking that just plain "/size/" is maybe a bit too generic for this keyword. But I'm not sure what would be better. Maybe /cellsize/ or /intsize/ or /arraysize/.
Also /bits/ or /cellbits/ might make good choices because the size is in bits and not in bytes.
True; they are better ideas.
Quoted 3 lines
I'm not fond of /arraysize/ because we are
specifying the size of each element in the array, not the array itself.
Yeah, good point.
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
Re: [PATCH 2/3] dtc: Add data_append_literal function
In reply to a message not in the archiveQuoted 14 lines · David Gibson
Quoted 3 lines · Anton Staaf
Quoted 1 line · David Gibson
On Wed, Sep 21, 2011 at 01:42:10PM -0700, Anton Staaf wrote:
[snip]
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
+
+ if ((len < 64) && (value >= (1ULL << len)))
+ die("Literal value 0x%x too large to fit in %d-bit cell\n",
+ value, len);This really shouldn't be a
die(). In general bad input should not directly trigger adie()during parse - it should give an error but continue parse as best it can and only drop out afterwards.
Quoted 6 lines
Quoted 3 lines
Hmm, so this check should never happen when called from the parser because the parser uses
eval_literalto read the cell values and that function also checks this.Um.. it checks and prints an error, but it doesn't
die()or otherwise stop you from reaching here AFAICT.
Hah, yes, you are correct. The same is true for the other die as well then I think.
I'll take a closer look tomorrow.
Thanks,
Anton
Quoted 6 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
Re: [PATCH 2/3] dtc: Add data_append_literal function
In reply to a message not in the archiveQuoted 20 lines · Anton Staaf
Quoted 18 lines · David Gibson
Quoted 3 lines · Anton Staaf
Quoted 1 line · David Gibson
On Wed, Sep 21, 2011 at 01:42:10PM -0700, Anton Staaf wrote:
[snip]
Quoted 12 lines
Quoted 8 lines
Quoted 4 lines
+
+ if ((len < 64) && (value >= (1ULL << len)))
+ die("Literal value 0x%x too large to fit in %d-bit cell\n",
+ value, len);This really shouldn't be a
die(). In general bad input should not directly trigger adie()during parse - it should give an error but continue parse as best it can and only drop out afterwards.Hmm, so this check should never happen when called from the parser because the parser uses
eval_literalto read the cell values and that function also checks this.
Quoted 7 lines
Quoted 2 lines
Um.. it checks and prints an error, but it doesn't
die()or otherwise stop you from reaching here AFAICT.Hah, yes, you are correct. The same is true for the other die as well then I think.
I'll take a closer look tomorrow.
Yup, you're right, first die has to go, second die can stay because I am forcing the size to a valid size (32-bits) in the parser.
Thanks again,
Anton
Quoted 10 lines
Thanks,
AntonQuoted 6 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