When adding a label, walk to the end of the list since the
label reflects the end of the data.
Since merging data buffers already preserved the order, this
will cause the labels to be emitted in order when writing
assembly output.
It should also aid emiting labels when writing dts output
should that be added in the future (data formatting would
need to break at each label).
Signed-off-by: Milton Miller <miltonm@bga.com>
Extend the parser grammer to allow labels before or after any
property data (string, cell list, or byte list), and any
byte or cell within the property data.
Store the labels using the same linked list structure as node
references, but using a parallel list.
When writing assembly output emit global labels as offsets from
the start of the definition of the data.
Note that the alignment for a cell list is done as part of the
opening < delimiter, not the = or , before it. To label a cell
after a string or byte list put the label inside the cell list.
For example,
prop = zero: [ aa bb ], two: < four: 1234 > eight: ;
will produce labels with offsets 0, 2, 4, and 8 bytes from
the beginning of the data for property prop.
Signed-off-by: Milton Miller <miltonm@bga.com>
Change the lexer to recognise a label in any context. Place
before other celldata and bytestrings to avoid the initial
characters being stolen by other matches.
A label is a character sequence starting with an alphabetic
or underscore optinally followed by the same plus digits and
terminating in a colon.
The included terminating colon will prevent matching hex numbers.
Signed-off-by: Milton Miller <miltonm@bga.com>
Change the grow_data_for function to copy struct data and
modifiy the fields it is updating instead of storing all
fields individually to a stack allocated struct.
This reduces maintence for future enhancements as now all
instances of struct data are created by modifying a copy
of an existing struct data or directly copying empty_data.
Signed-off-by: Milton Miller <miltonm@bga.com>
Allow a label to be placed on a memory reserve entry.
Change the parser to recognize and store them. Emit
them when writing assembly output.
Signed-off-by: Milton Miller <miltonm@bga.com>
Check that strtoul() parsed the complete string.
As with the number overflow case, write a non-fatal error
message to stdout.
Signed-off-by: Milton Miller <miltonm@bga.com>
The version 17 flat device tree format added struct size. When
writing version 17 assembly output the field must be emitted.
Signed-off-by: Milton Miller <miltonm@bga.com>
Commit 0738774fcc introduced some
incorrect indentation / bracketing in unflatten_tree(). By luck, the
extra break statement intended to be within an if block, but actually
afterwards has no semantic effect. Still, this patch gets rid of it
for cleanliness.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch substantially revamps the dtc Makefiles, in particular
better integrating the Makefile for dtc proper with the Makefiles
imported from libfdt for libfdt and the shared testsuite. Notable
changes:
- No recursive make calls. Instead subsidiary Makefiles are
included into the top-level Makefile so we get a complete dependency
information.
- Common pattern rules, CFLAGS etc. shared between dtc, libfdt
and testsuite, rather than separate copies.
- Vaguely Kbuild-like non-verbose mode used by default, which
makes warnings more prominent.
- libfdt Makefile consists only of variable definitions and
helper rules, to make it more easily embeddable into other Makefile
systems.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The dtc tree currently includes two copies of the GPL - one which was
there originally, and one imported from the libfdt tree. This patch
gets rid of the extra copy in the libfdt tree.
In addition it renames the file containing the remaining copy from
COPYING to GPL. Since libfdt is dual-licensed, this seems clearer.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
There are quite a lot of testcases in the dtc testsuite (recently
imported from libfdt). It can be easy to miss a stray FAIL result in
the midst of all the rest. To improve this, this patch adds a summary
to the end of the testsuite results giving the total number of tests
along with the number of PASSes FAILs and other results.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Since Milton's patch, dtc will accept (and, correctly, ignore) NOP
tags when given dtb input v16 or later. However, although NOPs
weren't defined in earlier versions, they're not ambiguous, so should
be accepted there as well. This patch does so, printing a mere
warning when finding NOPs in a too-early dtb version.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
As a read-only functions, which take a const pointer to the fdt, treat
fdt_get_property() and fdt_getprop() as returning const pointers to
within the blob. fdt_get_property_w() and fdt_getprop_w() versions
are supplied which take a non-const fdt pointer and return a non-const
pointer for the benefit of callers wishing to alter the device tree
contents.
Likewise the lower-level fdt_offset_ptr() and _fdt_offset_ptr()
functions are changed to return const pointers, with *_w() versions
supplied.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Version 16 and later of the flat device tree format allow NOPs
to be placed in the tree. When processing dtb input, dtc must
recognise them.
Previously it would produce the error message
FATAL ERROR: Invalid opcode word 00000004 in device tree blob
Signed-off-by: Milton Miller <miltonm@bga.com>
At present, the lexer in dtc recognizes only space, tab and newline as
whitespace characters. This is broken; in particular this means that
dtc will get syntax errors on files with DOS-style (CR-LF) newlines.
This patch fixes the problem, using flex's built-int [:space:]
character class.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
With the last improvement to pad out the blob, I broke the blob
header totalsize adjustment. The adjustment was moved up in the
code before the memory image of the blob is created.
Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
This makes padding out the blob if the user requested extra size much
easer. The assembly and writing to the file is more straight forward too.
Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Implement the -R <number> option to add memory reserve slots.
Add a -S <size> option makes the blob at least this number of bytes.
Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
- Change include syntax to: /include/ "filename"
- Move private functions directly into dtc-lexer.l
- Define YYID for some older parser templates
Also fix a #include ordering problem around YYLTPE.
Signed-off-by; Jon Loeliger <jdl@freescale.com>
Acked-by: Haiying Wang <Haiying.Wang@freescale.com>
Keeps track of open files in a stack, and assigns
a filenum to source positions for each lexical token.
Modified error reporting to show source file as well.
No policy on file directory basis has been decided.
Still handles stdin.
Tested on all arch/powerpc/boot/dts DTS files
Signed-off-by: Jon Loeliger <jdl@freescale.com>
It is not an error for /chosen (or any of its children) to be missing.
It is not a requirement that the output of dtc be a complete, valid
device tree, as it may be intended that the dtb be passed through boot
code that will complete it. Thus, do not complain.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
At present fdt.h #includes stdint.h. This makes some sense, because fdt.h
uses the standard fixed-width integer types. However, this can make life
difficult when building in different environments which may not have a
stdint.h. Therefore, this patch removes the #include from fdt.h, instead
requiring that users of fdt.h define the fixed-width integer types before
including fdt.h, either by themselves including stdint.h, or by any other
means.
Add -h option for help
Add -q quiet option to reduce or suppress the whining
Create #define for the default version value.
Signed-off-by: vanbaren@cideas.com <vanbaren@cideas.com>
libdt.c was an attempt at creating a device tree handling library
within the dtc codebase. However, it was never even close to
completion, and is entirely obsoleted by it's spiritual descendent,
libfdt (currently a separate package). This patch, therefore, removes
libdt.c entirely, along with its only reference in the Makefile, an
unused variable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
libfdt defined a new version of the flattened device tree format,
version 17. It is backwards compatible with version 16, just adding
an extra header field giving the size of the blob's structure blob.
This patch adds support to dtc allowing it to read and write version
17 blobs. It also makes version 17 the default output version for
blobs.
At the same time we change the code to consistently using decimal
numbers for versions. Previously we sometimes used 16 and sometimes
0x10 to refer to version 16.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The structure in flat_dt.h defining the layout of a proprety within
the flat device tree is incorrect. It has the offset to the
property's name, then the length when in fact (according to
booting-without-of.txt and the output of dtc) then length should come
first, followed by the name offset.
In fact, this structure is never used so the mistake doesn't break
anything, but it should still be fixed to avoid misleading people.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Since its beginning, libfdt has used an incorrect definition of the
format for a property, putting the name offset before length, rather
than the other way around as described in booting-without-of.txt.
This corrects the error, making libfdt actually produce and use trees
which are compatible with the kernel and dtc.
Signed-of-by: David Gibson <david@gibson.dropbear.id.au>
This fixes several small bugs related to fdt_strerror().
- an entry is added to the error table for FDT_ERR_BADLAYOUT.
- Incorrect usage of fdt_strerror() in check_property() and
check_getprop() is corrected (they were passing a positive error code,
when fdt_strerror() expects a negative code).
- Add code to properly retreive an error code from
fdt_get_property() in check_property(). With that a check that the
length returned by fdt_get_property() matches that stored in the
retreived property.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Remove warning for missing interrupt-controller property
under /chosen. There is consensus that this
property does not belong here.
Also, add a warning if interrupt-controller _is_ found
under /chosen.
Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
Add the original simple test case and a case with
different based cell values. Correct output asm
files as well as stderr is captured.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
New syntax d#, b#, o# and h# allow for an explicit prefix
on cell values to specify their base. Eg: <d# 123>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
dtc allows nodes to have labels, which at present are just re-emitted
as symbols at the appropriate places when using asm-mode output. It
also allows "references" where the notation &/path/to/node in a cell
list will be replaced with the phandle of the referenced node.
This patch extends the reference syntax to allow references to labels
instead of just full device paths. This allows nodes deep within the
tree to be referenced with a shorter more convenient name. References
to labels are distinguished from reference to paths by the fact that
paths must start with a /, but labels can never start with a /.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
At present each property definition in a dts file must give as the
value either a string ("abc..."), a bytestring ([12abcd...]) or a cell
list (<1 2 3 ...>). This patch allows a property value to be given as
several of these, comma-separated. The final property value is just
the components appended together. So a property could have a list of
cells followed by a string, or a bytestring followed by some cells.
Cells are always aligned, so if cells are given following a string or
bytestring which is not a multiple of 4 bytes long, zero bytes are
inserted to align the following cells.
The primary motivation for this feature, however, is to allow defining
a property as a list of several strings. This is what's needed for
defining OF 'compatible' properties, and is less ugly and fiddly than
using embedded \0s in the strings.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Jon Loeliger <jdl@freescale.com>
At present, the tree checking code in dtc will die with an assertion
failure if given a tree which has the invalid value 0 or -1 in a
property which should contain a phandle. This patch fixes the check
to die more gracefully with an error message indicating the invalid
phandle value.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
The linux,platform property in /chosen was obsolete almost as soon as
it was invented. Remove the check for it from dtc, which just tends
to lead to irritating spurious failures.
Signed-off-by: David Gibson <dwg@au1.ibm.com>
This function moves the fdt_strerror() function, currently found in
the test code into the fdt library proper. This makes life easier for
any library users who want to provide meaningful error messages. The
function goes into a module of its own, so that users who don't need
the function won't get a copy of it linked in.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
First, this patch removes several underused error codes:
FDT_ERR_BADPOINTER and FDT_ERR_BADHEADER were not used at all and are
simply removed. FDT_ERR_SIZE_MISMATCH was very similar in spirit to
FDT_ERR_NOSPACE, and used only in circumstances where there can be no
confusion between the two, so is removed and folded into
FDT_ERR_NOSPACE. FDT_ERR_INTERAL was used on only one place, on a
"can't happen" check. It seems of little value so the check and error
code are removed also.
Second, the error codes have been re-numbered and grouped roughly by
severity. That is codes which can reasonably occur in normal
operation separated from those which indicate bad parameters (and
therefore a bug in the caller) or a bad or corrupted device tree blob.
Third the test function fdt_strerror() is cleaned up a little based on
these changes.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
At present, libfdt functions returning a structure offset return a
zero-or-positive offset on success, and return a negative error code
on failure. Functions which only return an error code return a
positive version of the error code, or 0 on success.
This patch improves consistency by always returning negative error
codes on failure, for both types of function. With this change, we do
away with the special fdt_offset_error() macro for checking whether a
returned offset value is an error and extracting the encoded error
value within. Instead an explicit (ret_value < 0) is now the
preferred way of checking return values for both offset-returning and
error-code-returning functions.
The fdt_strerror() function in the test code is updated
correspondingly to make more sense with the new conventions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch abolishes the non-standard and confusing encoding of errors
into pointer return values. The only functions still returning such a
potentially encoded pointer are fdt_get_property() and fdt_getprop().
Those functions also return a length via an (int *). With this patch
those functions instead now return NULL on any error, and return the
code indicating the type of error in the length paramater.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>