Commit graph

64 commits

Author SHA1 Message Date
Rob Herring
c81d389a10 checks: add chosen node checks
Add some checks for /chosen node. These check that chosen is located at
the root level and that bootargs and stdout-path properties are strings.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-15 13:26:57 +11:00
Rob Herring
e671852042 checks: add aliases node checks
Add checks for aliases node that all properties follow alias naming
convention and the values are a valid path.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13 21:28:11 +11:00
Rob Herring
d0c44ebe3f checks: check for #{size,address}-cells without child nodes
Add a check for unnecessary "#{size,address}-cells" when there's neither
a 'ranges' property nor child nodes with a 'reg' property.

An exception may be an overlay that adds nodes, but this case would need
"#{size,address}-cells" in the overlay to properly compile already.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13 21:03:29 +11:00
Rob Herring
18a3d84bb8 checks: add string list check for *-names properties
Add a string list check for common properties ending in "-names" such as
reg-names or interrupt-names.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13 20:27:36 +11:00
Rob Herring
8fe94fd6f1 checks: add string list check
Add a check for string list properties with compatible being the first
check.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13 20:22:56 +11:00
Rob Herring
6c57308196 checks: add a string check for 'label' property
Add a string property check for 'label' property. 'label' is a human
readable string typically used to identify connectors or ports on devices.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13 20:18:30 +11:00
Peter Rosin
a384191eba checks: fix sound-dai phandle with arg property check
The property is named "sound-dai", not "sound-dais".

Fixes: b3bbac02d5 ("checks: add phandle with arg property checks")
Signed-off-by: Peter Rosin <peda@axentia.se>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-05 11:31:51 +11:00
David Gibson
7975f64222 Fix widespread incorrect use of strneq(), replace with new strprefixeq()
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>
2017-11-11 19:36:42 +11:00
David Gibson
3b62fdaebf Remove leading underscores from identifiers
In a number of places, dtc and associated tools and test code use
leading _ characters on identifiers to flag them as "internal", an
idiom taken from the Linux kernel.  This is a bad idea in a userspace
program, because identifiers with a leading _ are reserved for the C
library / system.

In some cases, the extra _ served no real purpose, so simply drop it.  In
others move to the end of the identifier, which is a convention we're free
to use for our own purposes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-26 09:25:14 +02:00
Rob Herring
c1e55a5513 checks: fix handling of unresolved phandles for dts plugins
In dts plugins, it is valid to have unresolved phandle values. The
check_property_phandle_args and check_interrupts_property checks failed to
account for this resulting in spurious warnings or asserts, respectively.
Fix this by bailing from the checks if we're checking a dts plugin as
there is no way to further validate the properties.

Fixes: ee3d26f696 ("checks: add interrupts property check")
Fixes: b3bbac02d5 ("checks: add phandle with arg property checks")
Reported-by: Alan Tull <atull@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-19 12:32:09 +11:00
Thierry Reding
497432fd21 checks: Use proper format modifier for size_t
The size of size_t can vary between architectures, so using %ld isn't
going to work on 32-bit builds. Use the %zu modifier to make sure it is
always correct.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-28 10:58:40 +10:00
Rob Herring
ee3d26f696 checks: add interrupts property check
Add a check for nodes with interrupts property that they have a valid
parent, the parent has #interrupt-cells property, and the size is a
valid multiple of #interrupt-cells.

This may not handle every possible case and doesn't deal with
translation thru interrupt-map properties, but should be enough for
modern dts files.

Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-22 21:15:03 +10:00
Rob Herring
c1e7738988 checks: add gpio binding properties check
The GPIO binding is different compared to other phandle plus args
properties in that the property name has a variable, optional prefix.
The format of the property name is [<name>-]gpio{s} where <name> can
be any legal property string. Therefore, custom matching of property
names is needed, but the common check_property_phandle_args() function
can still be used.

It's possible that there are property names matching which are not GPIO
binding specifiers. There's only been one case found in testing which is
"[<vendor>,]nr-gpio{s}". This property has been blacklisted and the same
should be done to any others we find. This check will prevent getting
any more of these, too.

Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-22 21:14:43 +10:00
Rob Herring
b3bbac02d5 checks: add phandle with arg property checks
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>
2017-09-22 21:14:10 +10:00
David Gibson
13ce6e1c2f dtc: fix sprintf() format string error, again
2a42b14 "dtc: check.c fix compile error" changed a format string using
%lx which wasn't correct for all platforms.  Unfortunately it changed it to
%zx, which is wrong for a different set of platforms (and only right on
the others by accident).  The parameter we're formatting here is uint64_t,
not size_t, so we need to use the PRIx64 macro from <inttypes.h> to get
this right.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-08 14:35:16 +10:00
Shuah Khan
2a42b14d0d dtc: check.c fix compile error
Fix the following compile error found on odroid-xu4:

checks.c: In function ‘check_simple_bus_reg’:
checks.c:876:41: error: format ‘%lx’ expects argument of type
‘long unsigned int’, but argument 4 has type
‘uint64_t{aka long long unsigned int}’ [-Werror=format=]
  snprintf(unit_addr, sizeof(unit_addr), "%lx", reg);
                                         ^
checks.c:876:41: error: format ‘%lx’ expects argument of type
‘long unsigned int’, but argument 4 has type
‘uint64_t {aka long long unsigned int}’ [-Werror=format=]
cc1: all warnings being treated as errors
Makefile:304: recipe for target 'checks.o' failed
make: *** [checks.o] Error 1

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
[dwg: Correct new format to be correct in general]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-17 12:10:51 +10:00
Rob Herring
cdbb2b6c7a checks: Warn on node name unit-addresses with '0x' or leading 0s
Node name unit-addresses should generally never begin with 0x or leading
0s. Add warnings to check for these cases, but only for nodes without a
known bus type as there should be better bus specific checks of the
unit address in those cases. Any unit addresses that don't follow the
general rule will need to add a new bus type. There aren't any known
ones ATM.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 14:49:04 +11:00
Rob Herring
4c15d5da17 checks: Add bus checks for simple-bus buses
Add checks to identify simple-bus bus types and checks for child
devices. Simple-bus type is generally identified by "simple-bus"
compatible string. We also treat the root as a simple-bus, but only for
child nodes with reg property.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 14:49:04 +11:00
Rob Herring
33c3985226 checks: Add bus checks for PCI buses
Add PCI bridge and device node checks. We identify PCI bridges with
'device_type = "pci"' as only PCI bridges should set that property. For
bridges, check that node name is pci or pcie, ranges and bus-range are
present, and #address-cells and #size-cells are correct.

For devices, check the reg property fields are correct for the first
element (the config address). Check that the unit address is formatted
corectly based on the reg property. Device unit addresses are in the
form DD or DD,F where DD is the device 0-0x1f and F is the function 0-7.
Also, check that the bus number is within the expected range defined by
bridge's bus-ranges.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rob Herring <robh@kernel.org>
[dwg: Added a missing check dependency]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 14:45:37 +11:00
David Gibson
bad5b28049 Fix assorted sparse warnings
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>
2017-03-06 12:08:53 +11:00
David Gibson
672ac09ea0 Clean up gcc attributes
We have a number of explicit __GNUC__ conditionals to tell if we want to
use some gcc extensions for extra warnings.  This cleans this up to use
a single conditional, defining convenience macros for those attributes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 12:06:15 +11:00
Ian Campbell
acd1b534a5 Print output filename as part of warning messages
For example:
src/arm/at91-ariag25.dtb: Warning (unit_address_vs_reg): Node /memory has a reg or ranges property, but no unit name

If output is to stdout then the prefix is "<stdout>: ".

This helps to direct the developer to where to look when multiple files are
being compiled in parallel.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-23 20:11:20 +11:00
David Gibson
120775eb1c dtc: Use streq() in preference to strcmp()
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>
2017-02-13 15:57:54 +11:00
Rob Herring
852e9ecbe1 checks: Add Warning for stricter node name character checking
While '#', '?', '.', '+', '*', and '_' are considered valid characters,
their use is discouraged in recommended practices.

Testing this found a few cases of '.'. The majority of the warnings were
all from underscores.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-13 15:49:00 +11:00
Rob Herring
ef0e8f0615 checks: Add Warning for stricter property name character checking
While '?', '.', '+', '*', and '_' are considered valid characters their
use is discouraged in recommended practices. '#' is also only
recommended to be used at the beginning of property names.

Testing this found one typo error with '.' used instead of ','. The
rest of the warnings were all from underscores.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-13 15:49:00 +11:00
David Gibson
00fbb8696b Rename boot_info
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>
2016-12-09 16:30:43 +11:00
Pantelis Antoniou
20f29d8d41 dtc: Plugin and fixup support
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>
2016-12-09 13:26:39 +11:00
Pantelis Antoniou
8f70ac3980 checks: Pass boot_info instead of root node
As preparation for overlay support we need to pass the boot info
parameter instead of the root node to each check method.

The root node can be retrieved by accessing boot info's dt member.

No other functional changes are made.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-11-28 14:51:50 +11:00
David Gibson
1ee0ae24ea Simplify check field and macro names
Now that "node" checks are the only type of checks, simplify some names
accordingly.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-27 15:30:24 +10:00
David Gibson
9d97527a86 Remove property check functions
Property checking functions aren't particularly useful.  They're used only
in a handful of cases, and most of those really only check a small handful
of specific properties.  This patches converts the few cases to node check
functions and removes property check functions entirely.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-27 15:23:54 +10:00
David Gibson
2e709d158e Remove tree check functions
The tree check functions from the checking infrastructure aren't very
useful.  There were only two examples using them, and they're basically
equivalent to a node check which is applied only to the root node, so those
are easily replaced.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-27 15:23:54 +10:00
Stephen Warren
c9d9121683 Warn on node name unit-address presence/absence mismatch
ePAPR 1.1 section 2.2.1.1 "Node Name Requirements" specifies that any
node that has a reg property must include a unit address in its name
with value matching the first entry in its reg property. Conversely, if
a node does not have a reg property, the node name must not include a
unit address. Also allow ranges property as it is deemed valid, but ePAPR
is not clear about it.

Implement a check for this. The code doesn't validate the format of the
unit address; ePAPR implies this may vary from (containing bus) binding
to binding, so doing so would be much more complex.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
[robh: also allow non-empty ranges]
Signed-off-by: Rob Herring <robh@kernel.org>
[moved new test in check_table]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-02-19 16:00:05 +11:00
Jack Miller
64c46b098b Fix crash with poorly defined #size-cells
If you have a parent block with #size-cells improperly set to 0, and
then subsequently try to include a regs property in the child, dtc will
crash with SIGFPE while validating it. This patch fixes that crash,
instead printing the same invalid length warning that was causing it.

Test included.

Signed-off-by: Jack Miller <jack@codezen.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-04-30 10:55:41 +10:00
Colin Ian King
5ef2f7c2fa dtc: Use va_end to match corresponding va_start
Although on some systems va_end is a no-op, it is good practice
to use va_end, especially since the manual states:

"Each invocation of va_start() must be matched by a corresponding
invocation of va_end() in the same function."

Signed-off-by: Colin Ian King <colin.king@canonical.com>
2015-01-13 16:28:25 +11:00
Phil Elwell
242c264270 Improve portability
1) Remove the double parentheses around two comparisons in checks.c.
   The OSX LLVM-based C compiler warns about them.
2) Put an explicit "=" in the TN() macro, in accordance with c99.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
2014-10-24 11:45:41 +02:00
Florian Fainelli
24cb3d0681 dtc: fix some more -Wshadow warnings
Building on a RHEL6 system produced the following -Wshadow warnings in
fstree.c, util.c and checks.c:

cc1: warnings being treated as errors
checks.c: In function 'parse_checks_option':
checks.c:709: error: declaration of 'optarg' shadows a global
declaration
/usr/include/getopt.h:59: error: shadowed declaration is here
make[1]: *** [checks.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** Waiting for unfinished jobs....
cc1: warnings being treated as errors
fstree.c: In function 'read_fstree':
fstree.c:40: error: declaration of 'tmpnam' shadows a global
declaration
/usr/include/stdio.h:208: error: shadowed declaration is here
make[1]: *** [fstree.o] Error 1
cc1: warnings being treated as errors
util.c: In function 'xstrdup':
util.c:42: error: declaration of 'dup' shadows a global declaration
/usr/include/unistd.h:528: error: shadowed declaration is here

Fix all of these -Wshadow warnings by using slightly different variable
names which won't collide with anything else.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2014-02-01 16:48:19 +11:00
David Gibson
17625371ee Use stdbool more widely
We already use the C99 bool type from stdbool.h in a few places.  However
there are many other places we represent boolean values as plain ints.
This patch changes that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-28 21:06:53 +11:00
Stephen Warren
45013d8619 dtc: Add ability to delete nodes and properties
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>
2012-09-06 07:51:43 -05:00
David Gibson
d5399197e9 Allow toggling of semantic checks
This patch adds -W and -E options to dtc which allow toggling on and off
of the various built in semantic checks on the tree.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-08 13:45:21 -05:00
David Gibson
511dedd40f Re-work level setting on checks code
Currently each of the semantic checks in checks.c has a "level" between
IGNORE and ERROR.  This single level makes it awkward to implement the
semantics we want for toggling the checks on the command line.

This patch reworks the code to instead have separate boolean flags for
warning and error.  At present having both flags set will have the same
effect as having just the error flag set, but this can change in the
future.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-08 13:45:13 -05:00
David Gibson
05898c67c1 dtc: Allow multiple labels on nodes and properties
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>
2010-02-24 08:48:51 -06:00
David Gibson
329055dbbc Disallow re-use of the same label within a dts file
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>
2010-02-23 09:04:48 -06:00
David Gibson
d75b33af67 Support ePAPR compliant phandle properties
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>
2009-11-26 15:06:17 -06:00
David Gibson
9878f30f31 dtc: Handle linux,phandle properties which self-reference
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>
2008-11-17 14:05:48 -06:00
David Gibson
4d7bea7873 dtc: Run relevant checks on dtb input as well as dts
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>
2008-07-14 12:36:08 -05:00
David Gibson
c8c374b856 dtc: Use the same endian-conversion functions as libfdt
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>
2008-07-14 12:07:22 -05:00
David Gibson
d028e84140 dtc: Strip redundant "name" properties
If an input device tree has "name" properties which are correct, then
they are redundant (because they can be derived from the unit name).
Therefore, extend the checking code for correctness of "name"
properties to remove them if they are correct.  dtc will still insert
name properties in the output if that's of a sufficiently old version
to require them.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
2b3a96761a dtc: Fix indentation of fixup_phandle_references
Somehow the indentation of this function is messed up - 7 spaces
instead of 1 tab (probably a bad copy paste from a patch file).  This
patch fixes it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:33 -05:00
David Gibson
fa5b520ccb dtc: Implement checks for the format of node and property names
This patch adds checks to the checking framework to verify that node
and property names contain only legal characters, and in the case of
node names there is at most one '@'.

At present when coming from dts input, this is mostly already ensured
by the grammer, however putting the check later means its easier to
generate helpful error messages rather than just "syntax error".  For
dtb input, these checks replace the older similar check built into
flattree.c.

Testcases for the checks are also implemented.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2008-03-23 08:00:32 -05:00
David Gibson
376ab6f2ed dtc: Remove remaining old-style checks
The remaining old-style tree checking code: check_root(), check_cpus()
and check_memory() really aren't that useful.  They mostly check for
the presence of particular nodes and properties.  That's inherently
prone to false-positives, because we could be dealing with an
artificial tree (like many of the testcases) or it could be expected
that the missing properties are filled in by a bootloader or other
agent.

If any of these checks really turns out to be useful, we can
reimplement them later in a better conceived way on top of the new
checking infrastructure.  For now, just get rid of them, removing the
last vestiges of the old-style checking code (hoorah).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-12-18 07:54:30 -06:00