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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>