Commit graph

890 commits

Author SHA1 Message Date
David Gibson
e20d9658cd Add Coverity Scan support
I've recently signed up dtc for Coverity Scan coverage.  This adds magic
to the .travis.yml file to submit builds to Coverity for analysis.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:55:16 +10:00
Simon Glass
b04a2cf088 pylibfdt: Fix code style in setup.py
We should follow PEP8 even for our setup() call.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:43:34 +10:00
Simon Glass
1c5170d3a4 pylibfdt: Rename libfdt.swig to libfdt.i
The .i extension allows Python distutils to automatically handle the swig
file. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:43:34 +10:00
Simon Glass
580a9f6c28 Add a libfdt function to write a property placeholder
The existing function to add a new property to a tree being built requires
that the entire contents of the new property be passed in. For some
applications it is more convenient to be able to add the property contents
later, perhaps by reading from a file. This avoids double-buffering of the
contents.

Add a new function to support this and adjust the existing fdt_property() to
use it.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-02 13:38:46 +10:00
Simon Glass
ab15256d8d pylibfdt: Use the call function to simplify the Makefile
This is in a separate patch since I not sure if GNU make features
are permitted in the Makefile.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
9f2e3a3a1f pylibfdt: Use the correct libfdt version in the module
Use the same version number in the module as with the rest of libfdt. This
can be examined with:

   import pkg_resources
   print pkg_resources.require('libfdt')[0].version

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
e91c652af2 pylibfdt: Enable installation of Python module
Adjust the setup script to support installation, and call it from the
Makefile if enabled. It will be disabled if we were unable to build the
module (e.g. due to swig being missing), or the NO_PYTHON environment
variable is set.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
8a892fd85d pylibfdt: Allow building to be disabled
Some build systems want to build python libraries separately from the
rest of the build.

Add a NO_PYTHON option to enable this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
David Gibson
741cdff85d .travis.yml: Add builds with and without Python library prerequisites
To make sure the Makefile behaves in both cases, make Travis matrix builds
with and without swig installed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 16:30:27 +11:00
Simon Glass
14c4171f4f pylibfdt: Use package_dir to set the package directory
At present we manually move _libfdt.so into the correct place. Provide a
package directory so we can avoid needing to do this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
89a5062ab2 pylibfdt: Use environment to pass C flags and files
At present setup.py adjusts its command line when running, so that the
C flags and file list can be passed as arguments. Pass them in environment
variables instead, so we can avoid this messiness. It also allows us to
support the 'install' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
4e0e0d0497 pylibfdt: Allow pkg-config to be supplied in the environment
Some build systems have their own version of the pkg-config tool.
Use a variable for this instead of hard-coding it, to allow for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:27:21 +11:00
David Gibson
6afd7d9688 Correct typo: s/pylibgfdt/pylibfdt/
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-22 16:34:39 +11:00
Simon Glass
756ffc4f52 Build pylibfdt as part of the normal build process
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>
2017-03-21 16:31:13 +11:00
Simon Glass
8cb3896358 Adjust libfdt.h to work with swig
There are a few places where libfdt.h cannot be used as is with swig:

- macros like fdt_totalsize() have to be defined as C declarations
- fdt_offset_ptr() and fdt_getprop_namelen() need special treatment due to
    a TODO in the wrapper for fdt_getprop(). However they are not useful to
    Python so can be removed

Add #ifdefs to work around these problem.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
b40aa8359a Mention pylibfdt in the documentation
Add a note about pylibfdt in the README.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
12cfb740cc Add tests for pylibfdt
Add a set of tests to cover the functionality in pylibfdt.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
50f2507016 Add an initial Python library for libfdt
Add Python bindings for a bare-bones set of libfdt functions. These allow
navigating the tree and reading node names and properties.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11: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
558cd81bdd dtc: Bump version to v1.4.4
Preparing for yet another release, due to a build bug in v1.4.3.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-10 11:17:23 +11:00
Nicolas Iooss
c17a811c62 fdtput: Remove star from value_len documentation
When clang checks the documentation tags (with -Wdocumentation flag), it
reports the following warning:

    fdtput.c:70:11: error: parameter '*value_len' not found in the
    function declaration [-Werror,-Wdocumentation]
     * @param *value_len    Returns length of value encoded
              ^~~~~~~~~~
    fdtput.c:70:11: note: did you mean 'value_len'?
     * @param *value_len    Returns length of value encoded
              ^~~~~~~~~~
              value_len

As this sounds reasonable, remove the star from the documentation tag.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
Nicolas Iooss
194d5caaef fdtget: Use @return to document the return value
Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
Nicolas Iooss
d922ecdd01 tests: Make realloc_fdt() really allocate *fdt
This bug has been found by using clang Static Analyzer: it reported that
the value stored to fdt was never read.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
Nicolas Iooss
921cc17fec libfdt: overlay: Check the value of the right variable
overlay_update_local_node_references() saves the result of
fdt_subnode_offset() into variable tree_child but checks for variable
ret afterwards. As this does not make sense, check tree_child instead of
ret.

This bug has been found by compiling with clang. The compiler reported
the following warning:

    libfdt/fdt_overlay.c:275:7: error: variable 'ret' may be
    uninitialized when used here
          [-Werror,-Wconditional-uninitialized]
                    if (ret == -FDT_ERR_NOTFOUND)
                        ^~~
    libfdt/fdt_overlay.c:210:9: note: initialize the variable 'ret' to
    silence this
          warning
            int ret;
                   ^
                    = 0

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
Nicolas Iooss
9ffdf60bf4 dtc: Simplify asm_emit_string() implementation
Using %.*s format helps making asm_emit_string() not modify its "str"
parameter.

While at it, constify the "str" parameter of bin_emit_string() and
asm_emit_string(), as these function no longer modify it.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 14:19:26 +11:00
David Gibson
881012e443 libfdt: Change names of sparse helper macros
The default libfdt_env.h (for POSIXish userland builds) supports sparse
checking.  It has a couple of helper macros, __force and __bitwise which
expand the relevant sparse attributes to enable checking for incorrect
or missing endian conversions.

Those are bad names: for one, leading underscores are supposed to be
reserved for the system libraries, and worse, some systems (including
RHEL7) do define those names already.

So change them to FDT_FORCE and FDT_BITWISE which are far less likely to
have collisions.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06 12:16:56 +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
David Gibson
49300f2ade dtc: Don't abuse struct fdt_reserve_entry
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>
2017-03-06 12:04:45 +11:00
David Gibson
fa8bc7f928 dtc: Bump version to v1.4.3
Preparing for new release.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-28 16:10:08 +11:00
David Gibson
34a9886a17 Add printf format attributes
When compiling with gcc, we already include the attribute on check_msg()
to give compiler warnings about mismatches between printf() like format
strings and the corresponding arguments.  This patch adds similar
attributes for lexical_error() and die().

Suggested-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-28 10:09:45 +11:00
David Gibson
f72508e2b6 Correct some broken printf() like format mismatches
Fix two places where a printf()-style format string does not match the
arguments passed.

Reported-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-28 10:04:20 +11:00
David Gibson
397d5ef020 libfdt: Add fdt_setprop_empty()
Device trees can contain empty (zero length) properties, which are often
used as boolean flags.  These can already be created using fdt_setprop()
passing a length of zero and a pointer which is ignored.  It is safe to
pass NULL, but that may not be obvious from the interface.  To make it
clearer, add an fdt_setprop_empty() helper macro.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-24 11:12:50 +11:00
David Gibson
69a1bd6ad3 libfdt: Remove undefined behaviour setting empty properties
The standard way of setting an empty property using libfdt is:
    fdt_setprop(fdt, nodeoffset, propname, NULL, 0);
However, the implementation of this includes an unconditional:
     memcpy(prop->data, NULL, 0);
Which although it will be a no-op (which is what we want) on many platforms
is technically undefined behaviour.  Correct this, so that when passing
a 0 length, passing a NULL pointer as the value to fdt_setprop() is
definitely safe.  This should quiet static checkers which complain about
this.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-24 10:51:05 +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
00d7bb1f4b dtc: pos parameter to srcpos_string() can't be NULL
None of the callers ever pass a NULL to srcpos_string(), so the check
for it is not necessary.  Furthermore, checking it make Coverity complain
about the raw dereferences which follow later in the function.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-08 17:39:36 +11:00
Jean-Christophe Dubois
95d57726bc livetree.c: Fix memory leak
When running coverity on dtc source code the following error is reported.

==========================================================================
*** CID 1370967:  Resource leaks  (RESOURCE_LEAK)
/tools/dtc/livetree.c: 850 in add_fixup_entry()
844		if (strchr(node->fullpath, ':') || strchr(prop->name, ':'))
845			die("arguments should not contain ':'\n");
846
847		xasprintf(&entry, "%s:%s:%u",
848			  node->fullpath, prop->name, m->offset);
849		append_to_property(fn, m->ref, entry, strlen(entry) + 1);
>>>     CID 1370967:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "entry" going out of scope leaks the storage it points to.
850     }
==========================================================================

Fix the leak.

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-08 17:37:21 +11:00
Stephen Boyd
3b9c97093d dtc: Fix NULL pointer use in dtlabel + dtref case
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>
2017-01-31 09:50:22 +11:00
Stephen Boyd
43eb551426 manual: Fix typo it -> in
Two its in a row can't be right.

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-01-30 12:18:21 +11:00
Stephen Boyd
4baf15f7f1 Makefile: Add tags rule
It's useful to have some tags to jump around sources. We don't
include test sources in the toplevel Makefile because they
probably aren't useful to main program development.

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-01-30 12:09:31 +11:00
Heinrich Schuchardt
0931cea3ba dtc: fdtdump: check fdt if not in scanning mode
Running fdtdump without scan mode for an invalid file often
results in a segmentation fault because the fdt header is
not checked.

With the patch the header is checked both in scanning as
well as in non-scanning mode.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[dwg: Removed unnecessary inline, changed type from int to bool]
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-12-27 09:44:17 +11:00
Gabriel Smith
f88865469b dtc: Fix memory leak in character literal parsing
The data struct used for parsing character literals was never freed
resulting in a few bytes leaked for every character.

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-12 10:30:51 +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
David Gibson
1ef86ad2c2 dtc: Clean up /dts-v1/ and /plugin/ handling in grammar
First remove the non-terminal name 'versioninfo' - /plugin/ doesn't really
indicate a "version" per se, and version could be confused with the dtb
output version.

Second allow the /dts-v1/; /plugin/; sequence to be repeated, for easier
use of include files - but ensure that all copies match, so you can't
include a file declaring /plugin/ in one that doesn't, or vice versa.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09 16:23:23 +11:00
David Gibson
e3c769aa9c dtc: Don't always generate __symbols__ for plugins
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>
2016-12-09 16:13:39 +11:00