So far, the tests for generating runtime overlays with dtc weren't checking
the syntactic sugar. This adds such a test.
Furthermore the existing tests were only minimally testing dtc's output
for the overlay. This adds a test comparing the dtc output with the
more or less manually constructed overlays we already have for testing
libfdt's overlay application code. This does require some minor changes
to that manually constructed overlay which don't change the sematics but
re-order / rename things to match the way dtc does it.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
GNU stat(1) uses '-c "%s"' as the proper invocation to print filesize of the
file in question, while BSD stat(1) uses '-f "%Uz"'. Do some trivial
autodetection to check if we're using GNU stat(1) and assume we're using BSD
stat(1) if we don't detect otherwise.
This should allow the test suite to run properly out-of-the-box on *BSDs and
MacOS in addition to the current Linux support.
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
stat -c %s's equivalent on FreeBSD is stat -f %Uz; these differ enough, allow
STATSZ in the environment to specify local replacement for a stat that outputs
size in bytes of an argument.
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
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>
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>
This adds some simple tests for the checks of correctly formatted PCI
bridge nodes. Doesn't test all that much, but it's a start.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add a single test makeing sure the &foo { }; syntax works.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
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>
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>
At present 'make check' succeeds even if some tests fail. Adjust this so
that we can use things like 'git bisect run make check' to find a failure.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add a stacked overlay unit test, piggybacking on fdtoverlay.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, both legacy (linux,phandle) and ePAPR (phandle) properties
are inserted into dtbs by default. The newer ePAPR style has been
supported in dtc and Linux kernel for 7 years. That should be a long
enough transition period. We can save a little space by not putting both
into the dtb.
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add an fdtoverlay unit test. Applies applies overlay(s) and then
retrieves an inserted property to verify.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Since 548aea2 "fdtdump: Discourage use of fdtdump", fdtdump unconditionally
prints a message discouraging its own use except for debugging purposes.
This shows up messily in the "make check" output, so suppress it.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
If swig and the Python are available, build pylibfdt automatically.
Adjust the tests to run Python tests too in this case.
Signed-off-by: Simon Glass <sjg@chromium.org>
[dwg: Make error message clearer that missing swig or python-dev isn't
fatal to the whole build]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
If we have a construct like this:
label: &handle {
...
};
Running dtc on it will cause a segfault, because we use 'target'
when it could be NULL. Move the add_label() call into the if
statement to fix this potentially bad use of a NULL pointer.
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
At the moment we generate a __symbols__ node if -@ is specified OR if the
dts has the /plugin/ tag. That difference in behaviour from handling base
trees is unnecessary and slightly confusing. It also means it's impossible
to create a plugin without symbols. Since symbols in a plugin are only
useful in the case of stacked plugins - and libfdt doesn't even support
merging plugin symbols as part of overlay application yet - that's a thing
that might be useful.
So make __symbols__ generation depend only on -@. We also remove remove
the testcases that checked explicitly for this not very useful behaviour.
Instead we don't use -@ for our basic overlay testcase, and check that
symbols are not generated.
At some point in the future we should add support for symbol merging to
libfdt and add testcases for stacked overlay application.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Using -@ again here obscures what's going on, because at the end we can't
know which run actually generated the symbols node. We should just
generate the symbols on the first run and leave it at that.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
I think these were for an additional command line option which got dropped
during development. At this point all they're testing is that fixups don't
get generated for a non /plugin/ tree, which is already tested with one of
the simpler cases previously.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This changes the names of the testfiles for a number of the testcases of
the dtc overlay generation functionality to make them shorter and a bit
cleaerer what's going on. In addition we move some of the check_path
sanity checks closer to the dtc commands they verify.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
At the moment we have some rudimentary tests of the fdt_overlay_apply()
function which don't rely on overlay generation support in dtc. This is
done by avoiding any external references in the sample overlay, in
particularly using the 'target-path' syntax instead of 'target' to avoid
needing external references in the fragment targets. Thus this test case
doesn't exercise libfdt's processing of the __fixups__ node at all.
We do test that somewhat in combination with dtc's overlay support.
However, in the interests of being able to quickly determine which side a
bug is on, it would be nice to exercise this without requiring the dtc
support.
This adds testcases to do so, by making some examples with manually
constructed __symbols__ and __fixups__ nodes. In addition we rename some
of the test data files and add some extra check_path tests to make it a bit
clearer what's going on here.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The various tests for overlay/plugin support are currently lumped together
in the overlay_tests shell function, which is executed by libfdt_tests.
However, this includes both tests designed primarily to exercise libfdt's
overlay application, and tests designed to exercise dtc's overlay
generation. Split these up for improved clarity.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The current testcases for the -A "auto alias generation" option operate on
a "plugin" tree. Although not technically wrong, this is an odd approach,
since a plugin will almost certainly need the __symbols__ and/or __fixups__
syntax instead of aliases. On the other hand -A may be useful simply for
generating aliases on a tree which is not using the overlay / plugin
mechanism at all.
Therefore change the tests to operate on a base tree example instead of a
plugin.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
When overlay apply supprt was added to libfdt the testcases included some
which could only be executed with the (then) out of tree dtc with overlay
output support. So, the test script automatically skipped those tests if
it wasn't available.
Now that the overlay support is merged into dtc mainline there's no reason
to keep this logic. Instead run all the overlay tests unconditionally.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add a number of tests for dynamic objects/overlays.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add a test that checks for existence or not of a node.
It is useful for testing the various cases when generating
symbols and fixups for dynamic device tree objects.
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Rename the blobs to have a more explicit output that will give us a clearer
idea about whether a DT (and the test) has been compiled using a dtc with
our without overlays support.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The compiled blobs in the overlay tests do not have the test suffix which
is usually used to clean up and ignore the test artifacts.
Let's add that suffix.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The bad fixups tests were meant to be usable even for a non-overlay-enabled
dtc.
Move them out of that check.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Add some test infrastructure to test that the overlay can be merged, but
also that poorly formatted fixups would fail as expected.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[dwg: Don't execute bad overlay tests without overlay aware dtc]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
We just added the -a option to allow padding of the output dtb's size to
a specified alignment. Unfortunately the test cases for this had several
bugs:
* Didn't actually test anything since "alignbase" instead of $alignbase
was passed to the checker function
* Introduced an unnecessary run_local_test wrapper
* Didn't provide very helpful output on failure
* Only attempted to check one alignment value
This patch fixes up these problems.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
There is one condition that need cat the dtb files
into one dtb.img which can support several boards
use same SoC platform.
And the original dtb file size is not aligned to any base.
This may cause "Synchronous Abort" when load from a unligned
address on some SoC machine, such as ARM.
So this patch implement the -a <aligned number> option to
pad zero at the end of dtb files and make the dtb size aligned
to <aligned number>.
Then, the aligned dtbs can cat together and load without "Synchronous
Abort".
Signed-off-by: Tim Wang <timwang@asrmicro.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Implement a macro based on fdt_first_property_offset and
fdt_next_property_offset that provides a convenience to iterate over all
the properties of a given node.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Simon Glass <sjg@chromium.org>
[dwg: Removed a stray trailing blank line]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
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>
We have a couple of checks of the form:
if (offset+size > totalsize)
die();
We need to check that offset+size doesn't overflow, otherwise the check
will pass, and we may access past totalsize.
Found with AFL.
Signed-off-by: Anton Blanchard <anton@samba.org>
[Added a testcase]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
In order to work with preprocessed dts files more easily, dts will parse
line number information in the form emitted by cpp.
Anton Blanchard (using a fuzzer) reported that including a line number
directive with a nul character (a literal nul in the input file, not a \0
sequence) would cause dtc to SEGV. I spotted several more problems on
examining the code:
* It modified yytext in place which seems to work, but is ugly and I'm
not sure if it's safe on all lex/flex versions
* The regexp used in the lexer to recognize line number information
accepts strings with escape characters, but it won't process these
escapes.
- GNU cpp at least, will generate \ escapes in line number
information, at least with files containing " or \ in the name
This patch reworks the handling of line number information to address
these problems. \ escapes should now be handled directly. nuls in file
names (either with a literal nul in the input file, or with a \0 escape
sequence) are still not permitted, but will now result in a lexical error
rather than a SEGV.
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
If a dts file contains a string with \ followed by a nul byte - an actual
nul in the input file, not the \\0 escape - then the assert() in
get_escape_char() will trip, crashing dtc.
As far as I can tell, there isn't any valid need for this assert(), so just
remove it.
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The code handling integer literals in dtc-lexer.l assumes that the flex
regexp means that strtoull() can't fail to interpret the string as a valid
integer (either decimal, octal, or hexadecimal). This is not true for
octals. For example '09' is accepted as a literal by the regexp,
strtoull() attempts to handle it as octal, but it has a bad digit.
This changes the code to give a more useful error in this case.
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Currently, attempting to divide by zero in an integer expression in a dts
file will cause dtc to crash with a division by zero (SIGFPE).
This patch corrects this to properly detect this case and raise an error.
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Given a device tree node and a property name, the fdt_stringlist_count()
function counts the number of strings found in the property value.
This also adds a new error code, FDT_ERR_BADVALUE, that the function
returns when it encounters a non-NUL-terminated string list.
Signed-off-by: Thierry Reding <treding@nvidia.com>
[Changed testcase name --dwg]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The overall test runner script, for the fdtdump tests invokes the helper
script fdtdump-runtest.sh. It then includes directly some code very
similar to fdtdump-runtest.sh, which is never reached due to a "return".
Remove the never-reached test code.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The test script includes several specific tests for the handling of aliases
in fdt_path_offset(). These are primarily tests of the fdt_path_offset()
libfdt function itself, although dtc is used to generate a test file for
convenience.
Move these from the dtc tests section to the libfdt tests section
accordingly.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
The -n option is not standard in POSIX, so convert to printf which should
work the same in every shell.
Signed-off-by: Mike Frysinger <vapier@chromium.org>
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>
This patch changes the dtc grammar to allow following syntax
i2cexp: &i2c2 {
...
};
Current device tree compiler allows to define multiple labels when defining
the device node the first time. Typically device nodes are defined in
DTSI files. Now these nodes can be overwritten for updating some of the
properties. Typically, device nodes are overridden in DTS files.
When working with adapter boards, most of the time adapter board can fit to
multiple base boards. But depending on which base board it is connected to,
the devices on the adapter board would be children of different devices.
e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas
on dra72-evm.dts, i2c5 is exported for expansion connector.
This causes a problem when writing a generic device tree file for
the adapter board. Because, you cannot know whether all the devices on
adapter board are present on i2c or i2c5.
The problem can be solved by adding a common label (e.g. i2cexp) in both
of the DTS files when overriding the device nodes for i2c2 or i2c5.
This way, generic adapter board file would override the i2cexp. And
depending on which base board you use the adapter board, all the devices
are automatically added for correct device nodes.
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>