Variable sized cell support
v2 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.
Changes in v2:
- sized_data renamed to celllist
- celllist definition moved to dtc-parser.y
- celllist non-terminal renamed to celllistprefix
- references always appended as -1 masked to the size of the cell
- smaller test values derived from TEST_VALUE_1
- data_append_literal renamed to data_append_integer
- be_ removed from values in data_append_integer
- len renamed to bits in data_append_integer
Anton Staaf (3):
libfdt: Add fdt16_to_cpu utility function
dtc: Add data_append_integer function
dtc: Add support for variable sized cells
Documentation/dts-format.txt | 18 +++++++- data.c | 33 ++++++++++++++++ dtc-lexer.l | 6 +++ dtc-parser.y | 67 ++++++++++++++++++++++----------- dtc.h | 1 + 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 +++++ 11 files changed, 206 insertions(+), 25 deletions(-) create mode 100644 tests/sized_cells.c create mode 100644 tests/sized_cells.dts
Signature · 1 line
1.7.3.1
A message that is not in the archive (sent off-list or not yet received): 1316715927-11944-1-git-send-email-robotboy-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH v2 1/3 libfdt: Add fdt16_to_cpu utility function
This 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
A message that is not in the archive (sent off-list or not yet received): 1316715927-11944-2-git-send-email-robotboy-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH v2 1/3] libfdt: Add fdt16_to_cpu utility function
Quoted 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
PATCH v2 2/3 dtc: Add data_append_integer function
In reply to a message not in the archiveThis function deals with appending integers of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given integer 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_integer (struct data d,uint64_t value,int bits) +{ +uint8_t value_8; +uint16_t value_16; +uint32_t value_32; +uint64_t value_64; + +if ((bits <64 ) && (value >= (1ULL << bits))) +die ("Literal value 0x%x too large to fit in %d-bit cell\n" , + value, bits); + +switch (bits) { +case 8 : + value_8 = value; +return data_append_data (d, &value_8,1 ); + +case 16 : + value_16 =cpu_to_fdt16 (value); +return data_append_data (d, &value_16,2 ); + +case 32 : + value_32 =cpu_to_fdt32 (value); +return data_append_data (d, &value_32,4 ); + +case 64 : + value_64 =cpu_to_fdt64 (value); +return data_append_data (d, &value_64,8 ); + +default : +die ("Invalid literal size (%d)\n" , bits); + } +} +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_integer (struct data d,uint64_t word,int bits);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
A message that is not in the archive (sent off-list or not yet received): 1316715927-11944-3-git-send-email-robotboy-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
David Gibson
Acked-byRe: [PATCH v2 2/3] dtc: Add data_append_integer function
Quoted 6 lines · Anton Staaf
This function deals with appending integers of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given integer is not larger than the specified size.
Signed-off-by Anton Staaf <[email protected]>
It occurs to me that data_append_cell() could be rewritten in terms of this function.
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
A message that is not in the archive (sent off-list or not yet received): 20110923001917.GD12286-787xzQ0H9iQXU02nzanrWNbf9cGiqdzd@public.gmane.org
Re: [PATCH v2 2/3] dtc: Add data_append_integer function
Quoted 6 lines · David Gibson
Quoted 5 lines · Anton Staaf
This function deals with appending integers of various sizes (8, 16 32, and 64 bit currently). It handles endianess conversions and verifies that the given integer is not larger than the specified size.
Quoted 6 lines
Quoted 1 line
Signed-off-by Anton Staaf <[email protected]>Acked-by David Gibson <[email protected]>It occurs to me that
data_append_cell()could be rewritten in terms of this function.
Good point, I'll send a patch tomorrow if you haven't already.
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
PATCH v2 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 | 67 ++++++++++++++++++++++----------- tests/.gitignore | 1 + tests/Makefile.tests | 1 + tests/run_tests.sh | 3 + tests/sized_cells.c | 84 ++++++++++++++++++++++++++++++++++++++++++ tests/sized_cells.dts | 11 +++++ 8 files changed, 166 insertions(+), 25 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 +45 -22
110 lines not on this page · raw message
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>; +};
Signature · 1 line
1.7.3.1