Reference via label allows extending nodes with compile-time checking of
whether the node being extended exists. This is useful to catch
renamed/removed nodes after an update of the device trees to be extended.
In absence of labels in the original device trees, new style path
references can be used:
/* upstream device tree */
/ {
leds: some-non-standard-led-controller-name {
led-0 {
default-state = "off";
};
};
};
/* downstream device tree */
&{/some-non-standard-led-controller-name/led-0} {
default-state = "on";
};
This is a common theme within the barebox bootloader[0], which extends the
upstream (Linux) device trees in that manner. The downside is that,
especially for deep nodes, these references can get quite long and tend to
break often due to upstream rework (e.g. rename to adhere to bindings).
Often there is a label a level or two higher that could be used. This
patch allows combining both a label and a new style path reference to
get a compile-time-checked reference, which allows rewriting the
previous downstream device tree snippet to:
&{leds/led-0} {
default-state = "on";
};
This won't be broken when /some-non-standard-led-controller-name is
renamed or moved while keeping the label. And if led-0 is renamed, we
will get the expected compile-time error.
Overlay support is skipped for now as they require special support: The
label and relative path parts need to be resolved at overlay apply-time,
not at compile-time.
[0]: https://www.barebox.org/doc/latest/devicetree/index.html
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
In several places we check for a returned phandle value to be valid,
for that it must not be 0 or "-1".
Wrap this check in a static inline function in dtc.h, and use ~0U instead
of -1 on the way, to keep everything in the unsigned realm.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20210618172030.9684-4-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
With -Wsign-compare, compilers warn about a mismatching signedness
in comparisons in the function get_node_by_path().
Taking the difference between two pointers results in a signed ptrdiff_t
type, which mismatches the unsigned type returned by strlen().
Since "p" has been returned by a call to strchr() with "path" as its
argument, we know for sure that it's bigger than "path", so the
difference must be positive. So a cast to an unsigned type is valid.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20210611171040.25524-7-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
With -Wsign-compare, compilers warn about a mismatching signedness in
comparisons in various parts of dtc.
Many variables are using signed types unnecessarily, as we never use
negative value in them.
Change their types to be unsigned, to prevent issues with comparisons.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Message-Id: <20201012161948.23994-7-andre.przywara@arm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The "strlen && strprefixeq" check in get_node_by_path is
excessive, since strlen is checked in strprefixeq macro
internally. Thus, "strlen(child->name) == p-path"
conjunct duplicates after macro expansion and could
be removed.
Signed-off-by: Denis Efremov <efremov@linux.com>
Message-Id: <20190827204148.20604-1-efremov@linux.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Replace instances of GPLv2 or later boilerplate with SPDX tags.
Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20190620211944.9378-2-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The YAML output fails for overlays and when symbol generation are enabled
due to missing markers in the generated properties.
Add type markers when generating properties under '__symbols__' and
'__fixups__' nodes as well as target-path properties. As a side effect of
append_to_property() changes, this also sets type markers in
'__local_fixups__' node properties.
Signed-off-by: Rob Herring <robh@kernel.org>
Message-Id: <20190517202804.9084-1-robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The typos have been discovered with the "codespell" utility.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20190520081209.20415-1-thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Extend the parser to record positions, in build_node,
build_node_delete, and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend
is defined in srcpos.c. New elements are added at the end. This
requires the srcpos type, define in srcpos.h, to be a list structure
with a next field. This next field is initialized to NULL in
srcpos.h, in the macro YYLLOC_DEFAULT invoked implicitly by the
generated parser code.
Another change to srcpos.c is to make srcpos_copy always do a full
copy, including a copy of the file substructure. This is required
because when dtc is used on the output of cpp, the successive detected
file names overwrite the file name in the file structure. The next
field does not need to be deep copied, because it is always NULL when
srcpos_copy is called; an assert checks for this. File names are only
updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This reverts commit baa1d2cf78.
Turns out this introduced memory badness. valgrind picks it up on
x86, but it straight out SEGVs on x86.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Extend the parser to record positions, in build_node, build_node_delete,
and build_property.
srcpos structures are added to the property and node types, and to the
parameter lists of the above functions that construct these types.
Nodes and properties that are created by the compiler rather than from
parsing source code have NULL as the srcpos value.
merge_nodes, defined in livetree.c, uses srcpos_extend to combine
multiple positions, resulting in a list of positions. srcpos_extend is
defined in srcpos.c. New elements are added at the end. The srcpos
type, define in srcpos.h, is now a list structure with a next field.
Another change to srcpos.c is to make srcpos_copy always do a full copy,
including a copy of the file substructure. This is required because
when dtc is used on the output of cpp, the successive detected file
names overwrite the file name in the file structure. The next field
does not need to be deep copied, because it is only updated in newly
copied positions and the positions to which it points have also been
copied. File names are only updated in uncopied position structures.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Generated phandle property values are a single cell, so set the type
marker to uint32. Otherwise, we default to uint8.
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
We've recently added "syntactic sugar" support to generate runtime dtb
overlays using similar syntax to the compile time overlays we've had for
a while. This worked with the &label { ... } syntax, adjusting an existing
labelled node, but would fail with the &{/path} { ... } syntax attempting
to adjust an existing node referenced by its path.
The previous code would always try to use the "target" property in the
output overlay, which needs to be fixed up, and __fixups__ can only encode
symbols, not paths, so the result could never work properly.
This adds support for the &{/path} syntax for overlays, translating it into
the "target-path" encoding in the output. It also changes existing
behaviour a little because we now unconditionally one fragment for each
overlay section in the source. Previously we would only create a fragment
if we couldn't locally resolve the node referenced. We need this for
path references, because the path is supposed to be referencing something
in the (not yet known) base tree, rather than the overlay tree we are
working with now. In particular one useful case for path based overlays
is using &{/} - but the constructed overlay tree will always have a root
node, meaning that without the change that would attempt to resolve the
fragment locally, which is not what we want.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Commit 737b2df3, "overlay: Add syntactic sugar version of overlays"
introduced an empty rule for "devicetree" that created ambiguities in
the grammar and causes the following warning:
BISON dtc-parser.tab.c
dtc-parser.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr]
Fix the grammar by explicitly testing for the condition the
new overlay grammar wants to use. This means duplicating a very small
amount of grammar processing code, but the alternative seems to be a
more invasive reorganization of the devicetree rule. Better to fix it
this way now and save the reorg for a separate patch.
Signed-off-by: Grant Likely <grant.likely@arm.com>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Every remaining usage of strneq() is, in fact, incorrect. They're trying
to check that the first n characters of one string exactly match another
string. But, they fall into the classic trap of strncmp() on which
strneq() is based. If n is less than the length of the second string, they
only check that the first string matches the start of the second, not the
whole of it.
To fix this, remove strneq() and replace it with a strprefixeq() function
which does what we want here.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Right now, check_interrupts_property fails with overlays, as the phandle
for the interrupt-parent can be orphan. Avoid this by allowing the orphan
node to pass the assert check.
The process_checks() call is also moved later during init sequence,
so that we can use the global variable generate_fixups to check if
we are compiling an overlay.
Signed-off-by: Tero Kristo <t-kristo@ti.com>
[dwg: Shortcut handling of invalid phandles]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
For simple overlays that use a single target there exists a
simpler syntax version.
&foo { }; generates an overlay with a single target at foo.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Many common bindings follow the same pattern of client properties
containing a phandle and N arg cells where N is defined in the provider
with a '#<specifier>-cells' property such as:
intc0: interrupt-controller@0 {
#interrupt-cells = <3>;
};
intc1: interrupt-controller@1 {
#interrupt-cells = <2>;
};
node {
interrupts-extended = <&intc0 1 2 3>, <&intc1 4 5>;
};
Add checks for properties following this pattern.
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When determining if to recurse into a node, get_node_by_path does not
check if the length of each node name is equal. If searching for
/foo/baz, this can result in recursing into /foobar because
strneq("foo", "foobar", 3) is true.
This can result in a reference to /foo/baz to be incorrectly set to
/foobar/baz. A test for this was added.
Signed-off-by: Tim Montague <tmontague@ghs.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This fixes a great many sparse warnings on the fdt and libfdt sources.
These are mostly due to incorrect mixing of endian annotated and native
integer types.
This includes fixing a couple of quasi-bugs where we had endian conversions
the wrong way around (this will have the right effect in practice, but is
certainly conceptually incorrect).
This doesn't make the whole tree sparse clean: there are many warnings in
bison and lex generated code, and there are a handful of other remaining
warnings that are (for now) more trouble than they're worth to fix (and
are not genuine bugs).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
struct fdt_reserve_entry is defined in fdt.h to exactly mirror the
in-memory layout of a reserve entry in the flattened tree. Since that is
always big-endian, it uses fdt64_t elements, which have sparse annotations
marking them as not native endian.
However, in dtc, we also use struct fdt_reserve_entry inside struct
reserve_info, and use it with native endian values. This will cause sparse
errors.
This stops this abuse, making struct reserve_info have its own native
endian fields for the same information.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
dtc defines a streq() (string equality) macro to avoid the easy confusion
of the sense of strcmp() comparison for equality. A few places where we
don't use it have slipped in, so remove them.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
struct boot_info is named that for historical reasons, and isn't
particularly meaningful. Essentially it contains all the information -
in "live" form from a single dts or dtb file. As we move towards support
for dynamic dt overlays, that name will become increasingly bad.
So, in preparation, rename it to dt_info. At the same time rename the
'the_boot_info' global to 'parser_output' since that's its actual purpose.
Unfortunately we do need the global unless we switch to bison's re-entrant
parser extensions, which would introduce its own complications.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch enable the generation of symbols & local fixup information
for trees compiled with the -@ (--symbols) option.
Using this patch labels in the tree and their users emit information
in __symbols__ and __local_fixups__ nodes.
The __fixups__ node make possible the dynamic resolution of phandle
references which are present in the plugin tree but lie in the
tree that are applying the overlay against.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Correct some typos discovered with the codespell utility.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
At present, the lexer token for references to a path doesn't permit a
reference to the root node &{/}. Fixing the lexer exposes another bug
handling this case.
This patch fixes both bugs and adds testcases.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Without this, new->deleted may be left set to some random value, which
may then cause future label references to fail to locate the label. The
code that allocates properties and nodes already contains the equivalent
memset().
Signed-off-by: Stephen Warren <swarren@nvidia.com>
dtc currently allows the contents of properties to be changed, and the
contents of nodes to be added to. There are situations where removing
properties or nodes may be useful. This change implements the following
syntax to do that:
/ {
/delete-property/ propname;
/delete-node/ nodename;
};
or:
/delete-node/ &noderef;
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
This patch adds a "dtdiff" script to do a useful form diff of two
device trees. This automatically converts the tree to dts form (if
it's not already) and uses a new "-s" option in dtc to "sort" the
tree. That is, it sorts the reserve entries, it sorts the properties
within each node by name, and it sorts nodes by name within their
parent.
This gives a pretty sensible diff between the trees, which will ignore
semantically null internal rearrangements (directly diffing the dts
files can give a lot of noise due to the order changes).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch allows the following construct:
/ {
property-a = "old";
property-b = "does not change";
};
/ {
property-a = "changed";
property-c = "new";
node-a {
};
};
Where the later device tree overrides the properties found in the
earlier tree. This is useful for laying down a template device tree
in an include file and modifying it for a specific board without having
to clone the entire tree.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
At present, both the grammar and our internal data structures mean
that there can be only one label on a node or property. This is a
fairly arbitrary constraint, given that any number of value labels can
appear at the same point, and that in C you can have any number of
labels on the same statement.
This is pretty much a non-issue now, but it may become important with
some of the extensions that Grant and I have in mind. It's not that
hard to change, so this patch does so, allowing an arbitrary number of
labels on any given node or property. As usual a testcase is added
too.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Currently, nothing will stop you from re-using the same label string
multiple times in a dts, e.g.:
/ {
samelabel: prop1 = "foo";
samelabel: prop2 = "bar";
};
or
/ {
samelabel: prop1 = "foo";
samelabel: subnode {
};
};
When using node references by label, this could lead to confusing
results (with no warning), and in -Oasm mode will result in output
which the assembler will complain about (since it too will have
duplicate labels).
This patch, therefore, adds code to checks.c to give errors if you
attempt to re-use the same label. It treats all labels (node,
property, and value) as residing in the same namespace, since the
assembler will treat them so for -Oasm mode.
Testcases for the new code are also added.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, when in -Idts -Odtb or -Ifs -Odtb modes, dtc always
defaults to using 0 as the value for the boot_cpuid_phys header field.
That's correct quite often, but there are some systems where there is
no CPU with hardware ID of 0, or where we don't want to use the CPU
with hardware ID 0 at all (e.g. for AMP-style partitioning). The only
way to override this default currently, is with the -b command line
option.
This patch improves dtc to instead base the default boot_cpuid_phys
value on the reg property of the first listed subnode of /cpus. This
means that dtc will get boot_cpuid_phys correct by default in a
greater proportion of cases (since the boot cpu is usually listed
first, and this way at least the boot_cpuid_phys default will match
some existing cpu node). If the node doesn't exist or has an invalid
'reg' property (missing or not 4 bytes in length), then
boot_cpuid_phys is set to 0.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, the Linux kernel, libfdt and dtc, when using flattened
device trees encode a node's phandle into a property named
"linux,phandle". The ePAPR specification, however - aiming as it is
to not be a Linux specific spec - requires that phandles be encoded in
a property named simply "phandle".
This patch adds support for this newer approach to dtc and libfdt.
Specifically:
- fdt_get_phandle() will now return the correct phandle if it
is supplied in either of these properties
- fdt_node_offset_by_phandle() will correctly find a node with
the given phandle encoded in either property.
- By default, when auto-generating phandles, dtc will encode
it into both properties for maximum compatibility. A new -H
option allows either only old-style or only new-style
properties to be generated.
- If phandle properties are explicitly supplied in the dts
file, dtc will not auto-generate ones in the alternate format.
- If both properties are supplied, dtc will check that they
have the same value.
- Some existing testcases are updated to use a mix of old and
new-style phandles, partially testing the changes.
- A new phandle_format test further tests the libfdt support,
and the -H option.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, dtc will generate phandles for nodes which are referenced
elsewhere in the tree. phandles can also be explicitly assigned by
defining the linux,phandle property. However, there is no way,
currently to tell dtc to generate a phandle for a node if it is not
referenced elsewhere. This is inconvenient when it's expected that
later processing on the flat tree might add nodes which _will_
the node in question.
One way one might attempt to do this is with the construct:
mynode: mynode {
linux,phandle = <&mynode>;
/* ... */
};
Though it's a trifle odd, there's really only one sensible meaning
which can be assigned to this construct: allocate a unique phandle to
"mynode" and put that in its linux,phandle property (as always).
Currently, however, dtc will choke on this self-reference. This patch
corrects this, making the construct above give the expected results.
It also ensures a more meaningful error message is given if you
attempt to process the nonsensical construct:
mynode: mynode {
linux,phandle = <&someothernode>;
/* ... */
};
The 'references' testcase is extended to cover this case, as well.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch adjusts the testsuite to run most of the tests for the tree
checking code on input in dtb form as well as dts form. Some checks
which only make sense for dts input (like reference handling) are
excluded, as are those which currently take dtb input because they
rely on things which cannot be lexically constructed in a dts file.
This shows up two small bugs in dtc, which are also corrected.
First, the name_properties test which was is supposed to remove
correctly formed 'name' properties (because they can be reconstructed
from tne node name) was instead removing 'name' properties even if
they weren't correct.
Secondly, when using dtb or fs input, the runtime tree in dtc did not
have the parent pointer initialized propertly because.built
internally. The appropriate initialization is added to the
add_child() function.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently both libfdt and dtc define a set of endian conversion macros
for accessing the device tree blob which is always big-endian. libfdt
uses names like cpu_to_fdt32() and dtc uses names like cpu_to_be32 (as
the Linux kernel). This patch switches dtc over to using the libfdt
macros (including libfdt_env.h to supply them). This has a couple of
small advantages:
- Removes some code duplication
- Will make conversion a bit easier if we ever need to produce
little-endian device tree blobs.
- dtc no longer needs to pull in netinet/in.h simply for the
ntohs() and ntohl() functions
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, dtc defines Linux-like names for various fixed-size integer
types. There's no good reason to do this; even Linux itself doesn't
use these names for externally visible things any more. This patch
replaces these with the C99 standardized type names from stdint.h.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, dtc will put the nonsense value 0xfeedbeef into the
boot_cpuid_phys field of an output blob, unless explicitly given
another value with the -b command line option. As well as being a
totally unuseful default value, this also means that dtc won't
properly preserve the boot_cpuid_phys field in -I dtb -O dtb mode.
This patch reworks things to improve the boot_cpuid handling. The new
semantics are that the output's boot_cpuid_phys value is:
the value given on the command line if -b is used
otherwise
the value from the input, if in -I dtb mode
otherwise
0
Implementation-wise we do the following:
- boot_cpuid_phys is added to struct boot_info, so that
structure now contains all of the blob's semantic information.
- dt_to_blob() and dt_to_asm() output the cpuid given in
boot_info
- dt_from_blob() fills in boot_info based on the input blob
- The other dt_from_*() functions just record 0, but we can
change this easily if e.g. we invent a way of specifying the boot cpu
in the source format.
- main() overrides the cpuid in the boot_info between input
and output if -b is given
We add some testcases to check this new behaviour.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, main() tests if it got a valid input tree from whichever
dt_from_*() function it invoked and if not, die()s. For one thing,
this test has, for no good reason, three different ways for those
functions to communicate a failure to provide input (bi NULL, bi->dt
NULL, or bi->error non-zero). For another, in every case save one, if
the dt_from_*() functions are unable to provide input they will
immediately die() (with a more specific error message) rather than
proceeding to the test in main().
Therefore, this patch removes this test, making the one case that
could have triggered it (in dt_from_source()) call die() directly
instead. With this change, the error field in struct boot_info is now
unused, so remove it.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Previously, only failure to parse caused the reading of the tree to fail;
semantic errors that called yyerror() but not YYERROR only emitted a message,
without signalling make to stop the build.
Signed-off-by: Scott Wood <scottwood@freescale.com>
This adds 'const' qualifiers to many variables and functions. In
particular it's now used for passing names to the tree accesor
functions.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
dtc: Flexible tree checking infrastructure
Here, at last, is a substantial start on revising dtc's infrastructure
for checking the tree; this is the rework I've been saying was
necessary practically since dtc was first release.
In the new model, we have a table of "check" structures, each with a
name, references to checking functions, and status variables. Each
check can (in principle) be individually switched off or on (as either
a warning or error). Checks have a list of prerequisites, so if
checks need to rely on results from earlier checks to make sense (or
even to avoid crashing) they just need to list the relevant other
checks there.
For now, only the "structural" checks and the fixups for phandle
references are converted to the new mechanism. The rather more
involved semantic checks (which is where this new mechanism will
really be useful) will have to be converted in future patches.
At present, there's no user interface for turning on/off the checks -
the -f option now forces output even if "error" level checks fail.
Again, future patches will be needed to add the fine-grained control,
but that should be quite straightforward with the infrastructure
implemented here.
Also adds a testcase for the handling of bad references, which catches
a bug encountered while developing this patch.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This patch moves the dtc code for checking the device tree its
processing into a new checks.c. The tree accessor functions from
livetree.c which the checks use are exported and added to dtc.h.
Another small step towards a flexible checking architecture.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Previously, there were a few shift/reduce and reduce/reduce
errors in the grammar that were being handled by the not-so-popular
GLR Parser technique.
Flip a right-recursive stack-abusing rule into a left-recursive
stack-friendly rule and clear up three messes in one shot: No more
conflicts, no need for the GLR parser, and friendlier stackness.
Compensate by reversing the property list on the node.
Signed-off-by: Jon Loeliger <jdl@freescale.com>
At present, dtc makes a lot of semantic checks on the device tree by
default, and will refuse to produce output if they fail. This means
people tend to need -f to force output despite failing semantic checks
rather a lot.
This patch splits the device tree checks into structural checks (no
bad or duplicate names or phandles) and semantic checks (everything
else). By default, only the structural checks are performed, and are
fatal. -f will force output even with structural errors (using this
in -Idts mode would essentially always be a bad idea, but it might be
useful in -Idtb mode for examining a malformed dtb).
Semantic checks are only performed if the new -c command line option
is supplied, and are always warnings only. Semantic checks will never
be performed on a tree with structural errors.
This patch is only a stopgap before implementing proper fine-grained
error/warning handling, but it should at least get rid of the
far-too-frequent need for -f for the time being.
This patch removes the -f from the dtc testcases now that it's no
longer necessary.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This large patch removes all trailing whitespace from dtc (including
libfdt, the testsuite and documentation). It also removes a handful
of redundant blank lines (at the end of functions, or when there are
two blank lines together for no particular reason).
As well as anything else, this means that quilt won't whinge when I go
to convert the whole of libfdt into a patch to apply to the kernel.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>